Skip to content

Commit

Permalink
Avoid duplicating signature in API docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaugustin committed Jan 20, 2024
1 parent 35bc7dd commit cba4c24
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/reference/sansio/client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Client (`Sans-I/O`_)

.. currentmodule:: websockets.client

.. autoclass:: ClientProtocol(wsuri, origin=None, extensions=None, subprotocols=None, state=State.CONNECTING, max_size=2 ** 20, logger=None)
.. autoclass:: ClientProtocol

.. automethod:: receive_data

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/sansio/common.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Both sides (`Sans-I/O`_)

.. automodule:: websockets.protocol

.. autoclass:: Protocol(side, state=State.OPEN, max_size=2 ** 20, logger=None)
.. autoclass:: Protocol

.. automethod:: receive_data

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/sansio/server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Server (`Sans-I/O`_)

.. currentmodule:: websockets.server

.. autoclass:: ServerProtocol(origins=None, extensions=None, subprotocols=None, state=State.CONNECTING, max_size=2 ** 20, logger=None)
.. autoclass:: ServerProtocol

.. automethod:: receive_data

Expand Down
4 changes: 2 additions & 2 deletions docs/reference/sync/client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Client (:mod:`threading`)
Opening a connection
--------------------

.. autofunction:: connect(uri, *, sock=None, ssl_context=None, server_hostname=None, origin=None, extensions=None, subprotocols=None, additional_headers=None, user_agent_header="Python/x.y.z websockets/X.Y", compression="deflate", open_timeout=10, close_timeout=10, max_size=2 ** 20, logger=None, create_connection=None)
.. autofunction:: connect

.. autofunction:: unix_connect(path, uri=None, *, sock=None, ssl_context=None, server_hostname=None, origin=None, extensions=None, subprotocols=None, additional_headers=None, user_agent_header="Python/x.y.z websockets/X.Y", compression="deflate", open_timeout=10, close_timeout=10, max_size=2 ** 20, logger=None, create_connection=None)
.. autofunction:: unix_connect

Using a connection
------------------
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/sync/server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Server (:mod:`threading`)
Creating a server
-----------------

.. autofunction:: serve(handler, host=None, port=None, *, sock=None, ssl_context=None, origins=None, extensions=None, subprotocols=None, select_subprotocol=None, process_request=None, process_response=None, server_header="Python/x.y.z websockets/X.Y", compression="deflate", open_timeout=10, close_timeout=10, max_size=2 ** 20, logger=None, create_connection=None)
.. autofunction:: serve

.. autofunction:: unix_serve(handler, path=None, *, sock=None, ssl_context=None, origins=None, extensions=None, subprotocols=None, select_subprotocol=None, process_request=None, process_response=None, server_header="Python/x.y.z websockets/X.Y", compression="deflate", open_timeout=10, close_timeout=10, max_size=2 ** 20, logger=None, create_connection=None)
.. autofunction:: unix_serve

Running a server
----------------
Expand Down
18 changes: 10 additions & 8 deletions src/websockets/sync/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,10 @@ def recv_events(self) -> None:
def connect(
uri: str,
*,
# TCP/TLS — unix and path are only for unix_connect()
# TCP/TLS
sock: Optional[socket.socket] = None,
ssl_context: Optional[ssl.SSLContext] = None,
server_hostname: Optional[str] = None,
unix: bool = False,
path: Optional[str] = None,
# WebSocket
origin: Optional[Origin] = None,
extensions: Optional[Sequence[ClientExtensionFactory]] = None,
Expand All @@ -148,6 +146,7 @@ def connect(
logger: Optional[LoggerLike] = None,
# Escape hatch for advanced customization
create_connection: Optional[Type[ClientConnection]] = None,
**kwargs: Any,
) -> ClientConnection:
"""
Connect to the WebSocket server at ``uri``.
Expand Down Expand Up @@ -210,13 +209,15 @@ def connect(
if not wsuri.secure and ssl_context is not None:
raise TypeError("ssl_context argument is incompatible with a ws:// URI")

# Private APIs for unix_connect()
unix: bool = kwargs.pop("unix", False)
path: Optional[str] = kwargs.pop("path", None)

if unix:
if path is None and sock is None:
raise TypeError("missing path argument")
elif path is not None and sock is not None:
raise TypeError("path and sock arguments are incompatible")
else:
assert path is None # private argument, only set by unix_connect()

if subprotocols is not None:
validate_subprotocols(subprotocols)
Expand All @@ -241,7 +242,7 @@ def connect(
if unix:
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.settimeout(deadline.timeout())
assert path is not None # validated above -- this is for mpypy
assert path is not None # mypy cannot figure this out
sock.connect(path)
else:
sock = socket.create_connection(
Expand Down Expand Up @@ -308,8 +309,9 @@ def unix_connect(
"""
Connect to a WebSocket server listening on a Unix socket.
This function is identical to :func:`connect`, except for the additional
``path`` argument. It's only available on Unix.
This function accepts the same keyword arguments as :func:`connect`.
It's only available on Unix.
It's mainly useful for debugging servers listening on Unix sockets.
Expand Down
14 changes: 9 additions & 5 deletions src/websockets/sync/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,9 @@ def serve(
host: Optional[str] = None,
port: Optional[int] = None,
*,
# TCP/TLS — unix and path are only for unix_serve()
# TCP/TLS
sock: Optional[socket.socket] = None,
ssl_context: Optional[ssl.SSLContext] = None,
unix: bool = False,
path: Optional[str] = None,
# WebSocket
origins: Optional[Sequence[Optional[Origin]]] = None,
extensions: Optional[Sequence[ServerExtensionFactory]] = None,
Expand Down Expand Up @@ -304,6 +302,7 @@ def serve(
logger: Optional[LoggerLike] = None,
# Escape hatch for advanced customization
create_connection: Optional[Type[ServerConnection]] = None,
**kwargs: Any,
) -> WebSocketServer:
"""
Create a WebSocket server listening on ``host`` and ``port``.
Expand Down Expand Up @@ -397,6 +396,10 @@ def handler(websocket):

# Bind socket and listen

# Private APIs for unix_connect()
unix: bool = kwargs.pop("unix", False)
path: Optional[str] = kwargs.pop("path", None)

if sock is None:
if unix:
if path is None:
Expand Down Expand Up @@ -515,8 +518,9 @@ def unix_serve(
"""
Create a WebSocket server listening on a Unix socket.
This function is identical to :func:`serve`, except the ``host`` and
``port`` arguments are replaced by ``path``. It's only available on Unix.
This function accepts the same keyword arguments as :func:`serve`.
It's only available on Unix.
It's useful for deploying a server behind a reverse proxy such as nginx.
Expand Down

0 comments on commit cba4c24

Please sign in to comment.