Skip to content

Commit d62e423

Browse files
committed
Deprecate the legacy asyncio implementation.
1 parent 8d055eb commit d62e423

File tree

15 files changed

+118
-55
lines changed

15 files changed

+118
-55
lines changed

docs/howto/upgrade.rst

+8-13
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,9 @@ respectively.
2727
.. admonition:: What will happen to the original implementation?
2828
:class: hint
2929

30-
The original implementation is now considered legacy.
31-
32-
The next steps are:
33-
34-
1. Deprecating it once the new implementation is considered sufficiently
35-
robust.
36-
2. Maintaining it for five years per the :ref:`backwards-compatibility
37-
policy <backwards-compatibility policy>`.
38-
3. Removing it. This is expected to happen around 2030.
30+
The original implementation is deprecated. It will be maintained for five
31+
years after deprecation according to the :ref:`backwards-compatibility
32+
policy <backwards-compatibility policy>`. Then, by 2030, it will be removed.
3933

4034
.. _deprecated APIs:
4135

@@ -69,13 +63,14 @@ Import paths
6963
For context, the ``websockets`` package is structured as follows:
7064

7165
* The new implementation is found in the ``websockets.asyncio`` package.
72-
* The original implementation was moved to the ``websockets.legacy`` package.
66+
* The original implementation was moved to the ``websockets.legacy`` package
67+
and deprecated.
7368
* The ``websockets`` package provides aliases for convenience. They were
7469
switched to the new implementation in version 14.0 or deprecated when there
75-
isn't an equivalent API.
70+
wasn't an equivalent API.
7671
* The ``websockets.client`` and ``websockets.server`` packages provide aliases
77-
for backwards-compatibility with earlier versions of websockets. They will
78-
be deprecated together with the original implementation.
72+
for backwards-compatibility with earlier versions of websockets. They were
73+
deprecated.
7974

8075
To upgrade to the new :mod:`asyncio` implementation, change import paths as
8176
shown in the tables below.

docs/index.rst

+22-21
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,38 @@ with a focus on correctness, simplicity, robustness, and performance.
2828

2929
It supports several network I/O and control flow paradigms.
3030

31-
1. The primary implementation builds upon :mod:`asyncio`, Python's standard
32-
asynchronous I/O framework. It provides an elegant coroutine-based API. It's
33-
ideal for servers that handle many clients concurrently.
34-
35-
.. admonition:: As of version :ref:`13.0`, there is a new :mod:`asyncio`
36-
implementation.
37-
:class: important
38-
39-
The historical implementation in ``websockets.legacy`` traces its roots to
40-
early versions of websockets. Although it's stable and robust, it is now
41-
considered legacy.
42-
43-
The new implementation in ``websockets.asyncio`` is a rewrite on top of
44-
the Sans-I/O implementation. It adds a few features that were impossible
45-
to implement within the original design.
46-
47-
The new implementation provides all features of the historical
48-
implementation, and a few more. If you're using the historical
49-
implementation, you should :doc:`ugrade to the new implementation
50-
<howto/upgrade>`. It's usually straightforward.
31+
1. The default implementation builds upon :mod:`asyncio`, Python's built-in
32+
asynchronous I/O library. It provides an elegant coroutine-based API. It's
33+
ideal for servers that handle many client connections.
5134

5235
2. The :mod:`threading` implementation is a good alternative for clients,
5336
especially if you aren't familiar with :mod:`asyncio`. It may also be used
54-
for servers that don't need to serve many clients.
37+
for servers that handle few client connections.
5538

5639
3. The `Sans-I/O`_ implementation is designed for integrating in third-party
5740
libraries, typically application servers, in addition being used internally
5841
by websockets.
5942

6043
.. _Sans-I/O: https://sans-io.readthedocs.io/
6144

45+
Refer to the :doc:`feature support matrices <reference/features>` for the full
46+
list of features provided by each implementation.
47+
48+
.. admonition:: The :mod:`asyncio` implementation was rewritten.
49+
:class: tip
50+
51+
The new implementation in ``websockets.asyncio`` builds upon the Sans-I/O
52+
implementation. It adds features that were impossible to provide in the
53+
original design. It was introduced in version 13.0.
54+
55+
The historical implementation in ``websockets.legacy`` traces its roots to
56+
early versions of websockets. While it's stable and robust, it was deprecated
57+
in version 14.0 and it will be removed by 2030.
58+
59+
The new implementation provides the same features as the historical
60+
implementation, and then some. If you're using the historical implementation,
61+
you should :doc:`ugrade to the new implementation <howto/upgrade>`.
62+
6263
Here's an echo server using the :mod:`asyncio` API:
6364

6465
.. literalinclude:: ../example/echo.py

docs/project/changelog.rst

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ Backwards-incompatible changes
5555
.. admonition:: The legacy :mod:`asyncio` implementation is now deprecated.
5656
:class: caution
5757

58+
The :doc:`upgrade guide <../howto/upgrade>` provides complete instructions
59+
to migrate your application.
60+
5861
Aliases for deprecated API were removed from ``__all__``. As a consequence,
5962
they cannot be imported e.g. with ``from websockets import *`` anymore.
6063

docs/reference/index.rst

+16-14
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,19 @@ Check which implementations support which features and known limitations.
1313

1414
features
1515

16-
:mod:`asyncio` (new)
17-
--------------------
16+
:mod:`asyncio`
17+
--------------
1818

1919
It's ideal for servers that handle many clients concurrently.
2020

21-
It's a rewrite of the legacy :mod:`asyncio` implementation.
21+
This is the default implementation.
2222

2323
.. toctree::
2424
:titlesonly:
2525

2626
asyncio/server
2727
asyncio/client
2828

29-
:mod:`asyncio` (legacy)
30-
-----------------------
31-
32-
This is the historical implementation.
33-
34-
.. toctree::
35-
:titlesonly:
36-
37-
legacy/server
38-
legacy/client
39-
4029
:mod:`threading`
4130
----------------
4231

@@ -62,6 +51,19 @@ application servers.
6251
sansio/server
6352
sansio/client
6453

54+
:mod:`asyncio` (legacy)
55+
-----------------------
56+
57+
This is the historical implementation.
58+
59+
It is deprecated and will be removed.
60+
61+
.. toctree::
62+
:titlesonly:
63+
64+
legacy/server
65+
legacy/client
66+
6567
Extensions
6668
----------
6769

docs/reference/legacy/client.rst

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Client (legacy :mod:`asyncio`)
22
==============================
33

4+
.. admonition:: The legacy :mod:`asyncio` implementation is deprecated.
5+
:class: caution
6+
7+
The :doc:`upgrade guide <../../howto/upgrade>` provides complete instructions
8+
to migrate your application.
9+
410
.. automodule:: websockets.legacy.client
511

612
Opening a connection

docs/reference/legacy/common.rst

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
Both sides (legacy :mod:`asyncio`)
44
==================================
55

6+
.. admonition:: The legacy :mod:`asyncio` implementation is deprecated.
7+
:class: caution
8+
9+
The :doc:`upgrade guide <../../howto/upgrade>` provides complete instructions
10+
to migrate your application.
11+
612
.. automodule:: websockets.legacy.protocol
713

814
.. autoclass:: WebSocketCommonProtocol(*, logger=None, ping_interval=20, ping_timeout=20, close_timeout=10, max_size=2 ** 20, max_queue=2 ** 5, read_limit=2 ** 16, write_limit=2 ** 16)

docs/reference/legacy/server.rst

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Server (legacy :mod:`asyncio`)
22
==============================
33

4+
.. admonition:: The legacy :mod:`asyncio` implementation is deprecated.
5+
:class: caution
6+
7+
The :doc:`upgrade guide <../../howto/upgrade>` provides complete instructions
8+
to migrate your application.
9+
410
.. automodule:: websockets.legacy.server
511

612
Starting a server

docs/topics/design.rst

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
:orphan:
2+
13
Design (legacy :mod:`asyncio`)
24
==============================
35

docs/topics/index.rst

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Get a deeper understanding of how websockets is built and why.
1212
broadcast
1313
compression
1414
keepalive
15-
design
1615
memory
1716
security
1817
performance

src/websockets/auth.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22

33
import warnings
44

5-
from .legacy.auth import *
6-
from .legacy.auth import __all__ # noqa: F401
5+
6+
with warnings.catch_warnings():
7+
# Suppress redundant DeprecationWarning raised by websockets.legacy.
8+
warnings.filterwarnings("ignore", category=DeprecationWarning)
9+
from .legacy.auth import *
10+
from .legacy.auth import __all__ # noqa: F401
711

812

913
warnings.warn( # deprecated in 14.0
10-
"websockets.auth is deprecated",
14+
"websockets.auth, an alias for websockets.legacy.auth, is deprecated; "
15+
"see https://websockets.readthedocs.io/en/stable/howto/upgrade.html "
16+
"for upgrade instructions",
1117
DeprecationWarning,
1218
)

src/websockets/http.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
import warnings
44

55
from .datastructures import Headers, MultipleValuesError # noqa: F401
6-
from .legacy.http import read_request, read_response # noqa: F401
6+
7+
8+
with warnings.catch_warnings():
9+
# Suppress redundant DeprecationWarning raised by websockets.legacy.
10+
warnings.filterwarnings("ignore", category=DeprecationWarning)
11+
from .legacy.http import read_request, read_response # noqa: F401
712

813

914
warnings.warn( # deprecated in 9.0 - 2021-09-01

src/websockets/legacy/__init__.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from __future__ import annotations
2+
3+
import warnings
4+
5+
6+
warnings.warn( # deprecated in 14.0
7+
"websockets.legacy is deprecated; "
8+
"see https://websockets.readthedocs.io/en/stable/howto/upgrade.html "
9+
"for upgrade instructions",
10+
DeprecationWarning,
11+
)

tests/legacy/__init__.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from __future__ import annotations
2+
3+
import warnings
4+
5+
6+
with warnings.catch_warnings():
7+
# Suppress DeprecationWarning raised by websockets.legacy.
8+
warnings.filterwarnings("ignore", category=DeprecationWarning)
9+
import websockets.legacy # noqa: F401

tests/maxi_cov.py

-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010

1111
UNMAPPED_SRC_FILES = [
12-
"websockets/auth.py",
1312
"websockets/typing.py",
1413
"websockets/version.py",
1514
]
@@ -105,7 +104,6 @@ def get_ignored_files(src_dir="src"):
105104
# or websockets (import locations).
106105
"*/websockets/asyncio/async_timeout.py",
107106
"*/websockets/asyncio/compatibility.py",
108-
"*/websockets/auth.py",
109107
# This approach isn't applicable to the test suite of the legacy
110108
# implementation, due to the huge test_client_server test module.
111109
"*/websockets/legacy/*",

tests/test_auth.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from .utils import DeprecationTestCase
2+
3+
4+
class BackwardsCompatibilityTests(DeprecationTestCase):
5+
def test_headers_class(self):
6+
with self.assertDeprecationWarning(
7+
"websockets.auth, an alias for websockets.legacy.auth, is deprecated; "
8+
"see https://websockets.readthedocs.io/en/stable/howto/upgrade.html "
9+
"for upgrade instructions",
10+
):
11+
from websockets.auth import (
12+
BasicAuthWebSocketServerProtocol, # noqa: F401
13+
basic_auth_protocol_factory, # noqa: F401
14+
)

0 commit comments

Comments
 (0)