From f4bc341e48e4cc01bc3d95fd8bcd01227b6a2b16 Mon Sep 17 00:00:00 2001 From: MtkN1 <51289448+MtkN1@users.noreply.github.com> Date: Wed, 7 Feb 2024 05:52:30 +0000 Subject: [PATCH 1/4] Add wsproto.Connection reference --- docs/source/api.rst | 4 ++++ src/wsproto/connection.py | 15 ++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/source/api.rst b/docs/source/api.rst index 9001109b..1c8583f1 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -19,6 +19,10 @@ Connection :special-members: __init__ :members: +.. autoclass:: wsproto.Connection + :special-members: __init__ + :members: + .. autoclass:: wsproto.ConnectionType :members: diff --git a/src/wsproto/connection.py b/src/wsproto/connection.py index 4439165e..5b07b396 100644 --- a/src/wsproto/connection.py +++ b/src/wsproto/connection.py @@ -63,11 +63,6 @@ class Connection: This wraps two other protocol objects, an HTTP/1.1 protocol object used to do the initial HTTP upgrade handshake and a WebSocket frame protocol object used to exchange messages and other control frames. - - :param conn_type: Whether this object is on the client- or server-side of - a connection. To initialise as a client pass ``CLIENT`` otherwise - pass ``SERVER``. - :type conn_type: ``ConnectionType`` """ def __init__( @@ -76,6 +71,16 @@ def __init__( extensions: Optional[List[Extension]] = None, trailing_data: bytes = b"", ) -> None: + """ + Constructor + + :param wsproto.connection.ConnectionType connection_type: Whether this + object is on the client- or server-side of a connection. + To initialise as a client pass ``CLIENT`` otherwise pass ``SERVER``. + :param list extensions: The proposed extensions. + :param bytes trailing_data: Data that has been received, but not yet + processed. + """ self.client = connection_type is ConnectionType.CLIENT self._events: Deque[Event] = deque() self._proto = FrameProtocol(self.client, extensions or []) From 8914e89986dc99ff0c0c4894be9d9ead767e83ef Mon Sep 17 00:00:00 2001 From: MtkN1 <51289448+MtkN1@users.noreply.github.com> Date: Wed, 7 Feb 2024 05:52:51 +0000 Subject: [PATCH 2/4] Fix Read the Docs build --- .readthedocs.yaml | 34 ++++++++++++++++++++++++++++++++++ docs/source/conf.py | 2 +- docs/source/requirements.txt | 2 ++ tox.ini | 2 +- 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 .readthedocs.yaml create mode 100644 docs/source/requirements.txt diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 00000000..b4abc6dc --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,34 @@ +# .readthedocs.yaml +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +# Required +version: 2 + +# Set the OS, Python version and other tools you might need +build: + os: ubuntu-22.04 + tools: + python: "3.11" + # You can also specify other tool versions: + # nodejs: "19" + # rust: "1.64" + # golang: "1.19" + +# Build documentation in the "docs/" directory with Sphinx +sphinx: + configuration: docs/source/conf.py + +# Optionally build your docs in additional formats such as PDF and ePub +# formats: +# - pdf +# - epub + +# Optional but recommended, declare the Python requirements required +# to build your documentation +# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html +python: + install: + - requirements: docs/source/requirements.txt + - method: pip + path: . diff --git a/docs/source/conf.py b/docs/source/conf.py index 26cc6053..ed76baf9 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -64,7 +64,7 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -html_theme = 'default' +html_theme = 'sphinx_rtd_theme' # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, diff --git a/docs/source/requirements.txt b/docs/source/requirements.txt new file mode 100644 index 00000000..cbf1e365 --- /dev/null +++ b/docs/source/requirements.txt @@ -0,0 +1,2 @@ +sphinx +sphinx-rtd-theme diff --git a/tox.ini b/tox.ini index 68fed1d5..26e88682 100644 --- a/tox.ini +++ b/tox.ini @@ -39,7 +39,7 @@ commands = [testenv:docs] deps = - sphinx + -r docs/source/requirements.txt allowlist_externals = make changedir = {toxinidir}/docs commands = From 51b20308b1ba829ba06fd9319aaf0e9c64bf5e8b Mon Sep 17 00:00:00 2001 From: MtkN1 <51289448+MtkN1@users.noreply.github.com> Date: Sat, 24 Feb 2024 03:23:19 +0000 Subject: [PATCH 3/4] Include the .readthedocs.yaml file --- MANIFEST.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index cf98024e..e2ea2429 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -4,5 +4,5 @@ graft docs graft test graft bench prune docs/build -include README.rst LICENSE CHANGELOG.rst tox.ini +include README.rst LICENSE CHANGELOG.rst tox.ini .readthedocs.yaml global-exclude *.pyc *.pyo *.swo *.swp *.map *.yml *.DS_Store .coverage From 21d4b3c8ff5cb6b0a7813572cf6012fcb96e412f Mon Sep 17 00:00:00 2001 From: MtkN1 <51289448+MtkN1@users.noreply.github.com> Date: Sat, 24 Feb 2024 03:27:29 +0000 Subject: [PATCH 4/4] Fix minor linting errors --- src/wsproto/__init__.py | 1 + src/wsproto/events.py | 2 +- src/wsproto/handshake.py | 1 + src/wsproto/utilities.py | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wsproto/__init__.py b/src/wsproto/__init__.py index f39ae4ba..60d04f2d 100644 --- a/src/wsproto/__init__.py +++ b/src/wsproto/__init__.py @@ -4,6 +4,7 @@ A WebSocket implementation. """ + from typing import Generator, Optional, Union from .connection import Connection, ConnectionState, ConnectionType diff --git a/src/wsproto/events.py b/src/wsproto/events.py index d758f8aa..7863c42d 100644 --- a/src/wsproto/events.py +++ b/src/wsproto/events.py @@ -4,6 +4,7 @@ Events that result from processing data on a WebSocket connection. """ + from abc import ABC from dataclasses import dataclass, field from typing import Generic, List, Optional, Sequence, TypeVar, Union @@ -156,7 +157,6 @@ class RejectData(Event): @dataclass(frozen=True) class CloseConnection(Event): - """The end of a Websocket connection, represents a closure frame. **wsproto does not automatically send a response to a close event.** To diff --git a/src/wsproto/handshake.py b/src/wsproto/handshake.py index 4ca8c60c..72af7229 100644 --- a/src/wsproto/handshake.py +++ b/src/wsproto/handshake.py @@ -4,6 +4,7 @@ An implementation of WebSocket handshakes. """ + from collections import deque from typing import ( cast, diff --git a/src/wsproto/utilities.py b/src/wsproto/utilities.py index 7cf53d17..967d94fb 100644 --- a/src/wsproto/utilities.py +++ b/src/wsproto/utilities.py @@ -4,6 +4,7 @@ Utility functions that do not belong in a separate module. """ + import base64 import hashlib import os