Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wsproto.Connection reference #188

Merged
merged 4 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -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: .
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Connection
:special-members: __init__
:members:

.. autoclass:: wsproto.Connection
:special-members: __init__
:members:

.. autoclass:: wsproto.ConnectionType
:members:

Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions docs/source/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sphinx
sphinx-rtd-theme
1 change: 1 addition & 0 deletions src/wsproto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

A WebSocket implementation.
"""

from typing import Generator, Optional, Union

from .connection import Connection, ConnectionState, ConnectionType
Expand Down
15 changes: 10 additions & 5 deletions src/wsproto/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand All @@ -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 [])
Expand Down
2 changes: 1 addition & 1 deletion src/wsproto/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/wsproto/handshake.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

An implementation of WebSocket handshakes.
"""

from collections import deque
from typing import (
cast,
Expand Down
1 change: 1 addition & 0 deletions src/wsproto/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

Utility functions that do not belong in a separate module.
"""

import base64
import hashlib
import os
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ commands =

[testenv:docs]
deps =
sphinx
-r docs/source/requirements.txt
allowlist_externals = make
changedir = {toxinidir}/docs
commands =
Expand Down
Loading