diff --git a/src/websockets/client.py b/src/websockets/client.py index 028e7ce4..633b1960 100644 --- a/src/websockets/client.py +++ b/src/websockets/client.py @@ -144,7 +144,7 @@ def process_response(self, response: Response) -> None: request: WebSocket handshake response received from the server. Raises: - InvalidHandshake: if the handshake response is invalid. + InvalidHandshake: If the handshake response is invalid. """ @@ -216,7 +216,7 @@ def process_extensions(self, headers: Headers) -> List[Extension]: List of accepted extensions. Raises: - InvalidHandshake: to abort the handshake. + InvalidHandshake: To abort the handshake. """ accepted_extensions: List[Extension] = [] diff --git a/src/websockets/extensions/base.py b/src/websockets/extensions/base.py index cca3fe51..7446c990 100644 --- a/src/websockets/extensions/base.py +++ b/src/websockets/extensions/base.py @@ -35,7 +35,7 @@ def decode( Decoded frame. Raises: - PayloadTooBig: if decoding the payload exceeds ``max_size``. + PayloadTooBig: If decoding the payload exceeds ``max_size``. """ raise NotImplementedError @@ -89,7 +89,7 @@ def process_response_params( An extension instance. Raises: - NegotiationError: if parameters aren't acceptable. + NegotiationError: If parameters aren't acceptable. """ raise NotImplementedError @@ -121,7 +121,7 @@ def process_request_params( extension and an extension instance. Raises: - NegotiationError: to reject the offer, if parameters received from + NegotiationError: To reject the offer, if parameters received from the client aren't acceptable. """ diff --git a/src/websockets/frames.py b/src/websockets/frames.py index e5e2af8b..201bc506 100644 --- a/src/websockets/frames.py +++ b/src/websockets/frames.py @@ -216,10 +216,10 @@ def parse( extensions: List of extensions, applied in reverse order. Raises: - EOFError: if the connection is closed without a full WebSocket frame. - UnicodeDecodeError: if the frame contains invalid UTF-8. - PayloadTooBig: if the frame's payload size exceeds ``max_size``. - ProtocolError: if the frame contains incorrect values. + EOFError: If the connection is closed without a full WebSocket frame. + UnicodeDecodeError: If the frame contains invalid UTF-8. + PayloadTooBig: If the frame's payload size exceeds ``max_size``. + ProtocolError: If the frame contains incorrect values. """ # Read the header. @@ -285,7 +285,7 @@ def serialize( extensions: List of extensions, applied in order. Raises: - ProtocolError: if the frame contains incorrect values. + ProtocolError: If the frame contains incorrect values. """ self.check() @@ -334,7 +334,7 @@ def check(self) -> None: Check that reserved bits and opcode have acceptable values. Raises: - ProtocolError: if a reserved bit or the opcode is invalid. + ProtocolError: If a reserved bit or the opcode is invalid. """ if self.rsv1 or self.rsv2 or self.rsv3: @@ -360,7 +360,7 @@ def prepare_data(data: Data) -> Tuple[int, bytes]: object. Raises: - TypeError: if ``data`` doesn't have a supported type. + TypeError: If ``data`` doesn't have a supported type. """ if isinstance(data, str): @@ -383,7 +383,7 @@ def prepare_ctrl(data: Data) -> bytes: If ``data`` is a bytes-like object, return a :class:`bytes` object. Raises: - TypeError: if ``data`` doesn't have a supported type. + TypeError: If ``data`` doesn't have a supported type. """ if isinstance(data, str): @@ -435,8 +435,8 @@ def parse(cls, data: bytes) -> Close: data: Payload of the close frame. Raises: - ProtocolError: if data is ill-formed. - UnicodeDecodeError: if the reason isn't valid UTF-8. + ProtocolError: If data is ill-formed. + UnicodeDecodeError: If the reason isn't valid UTF-8. """ if len(data) >= 2: @@ -463,7 +463,7 @@ def check(self) -> None: Check that the close code has a valid value for a close frame. Raises: - ProtocolError: if the close code is invalid. + ProtocolError: If the close code is invalid. """ if not (self.code in EXTERNAL_CLOSE_CODES or 3000 <= self.code < 5000): diff --git a/src/websockets/headers.py b/src/websockets/headers.py index 8391ad26..463df306 100644 --- a/src/websockets/headers.py +++ b/src/websockets/headers.py @@ -103,7 +103,7 @@ def parse_token(header: str, pos: int, header_name: str) -> Tuple[str, int]: Return the token value and the new position. Raises: - InvalidHeaderFormat: on invalid inputs. + InvalidHeaderFormat: On invalid inputs. """ match = _token_re.match(header, pos) @@ -127,7 +127,7 @@ def parse_quoted_string(header: str, pos: int, header_name: str) -> Tuple[str, i Return the unquoted value and the new position. Raises: - InvalidHeaderFormat: on invalid inputs. + InvalidHeaderFormat: On invalid inputs. """ match = _quoted_string_re.match(header, pos) @@ -180,7 +180,7 @@ def parse_list( Return a list of items. Raises: - InvalidHeaderFormat: on invalid inputs. + InvalidHeaderFormat: On invalid inputs. """ # Per https://www.rfc-editor.org/rfc/rfc7230.html#section-7, "a recipient @@ -234,7 +234,7 @@ def parse_connection_option( Return the protocol value and the new position. Raises: - InvalidHeaderFormat: on invalid inputs. + InvalidHeaderFormat: On invalid inputs. """ item, pos = parse_token(header, pos, header_name) @@ -251,7 +251,7 @@ def parse_connection(header: str) -> List[ConnectionOption]: header: value of the ``Connection`` header. Raises: - InvalidHeaderFormat: on invalid inputs. + InvalidHeaderFormat: On invalid inputs. """ return parse_list(parse_connection_option, header, 0, "Connection") @@ -271,7 +271,7 @@ def parse_upgrade_protocol( Return the protocol value and the new position. Raises: - InvalidHeaderFormat: on invalid inputs. + InvalidHeaderFormat: On invalid inputs. """ match = _protocol_re.match(header, pos) @@ -292,7 +292,7 @@ def parse_upgrade(header: str) -> List[UpgradeProtocol]: header: Value of the ``Upgrade`` header. Raises: - InvalidHeaderFormat: on invalid inputs. + InvalidHeaderFormat: On invalid inputs. """ return parse_list(parse_upgrade_protocol, header, 0, "Upgrade") @@ -307,7 +307,7 @@ def parse_extension_item_param( Return a ``(name, value)`` pair and the new position. Raises: - InvalidHeaderFormat: on invalid inputs. + InvalidHeaderFormat: On invalid inputs. """ # Extract parameter name. @@ -344,7 +344,7 @@ def parse_extension_item( list of ``(name, value)`` pairs, and the new position. Raises: - InvalidHeaderFormat: on invalid inputs. + InvalidHeaderFormat: On invalid inputs. """ # Extract extension name. @@ -379,7 +379,7 @@ def parse_extension(header: str) -> List[ExtensionHeader]: Parameter values are :obj:`None` when no value is provided. Raises: - InvalidHeaderFormat: on invalid inputs. + InvalidHeaderFormat: On invalid inputs. """ return parse_list(parse_extension_item, header, 0, "Sec-WebSocket-Extensions") @@ -431,7 +431,7 @@ def parse_subprotocol_item( Return the subprotocol value and the new position. Raises: - InvalidHeaderFormat: on invalid inputs. + InvalidHeaderFormat: On invalid inputs. """ item, pos = parse_token(header, pos, header_name) @@ -445,7 +445,7 @@ def parse_subprotocol(header: str) -> List[Subprotocol]: Return a list of WebSocket subprotocols. Raises: - InvalidHeaderFormat: on invalid inputs. + InvalidHeaderFormat: On invalid inputs. """ return parse_list(parse_subprotocol_item, header, 0, "Sec-WebSocket-Protocol") @@ -505,7 +505,7 @@ def parse_token68(header: str, pos: int, header_name: str) -> Tuple[str, int]: Return the token value and the new position. Raises: - InvalidHeaderFormat: on invalid inputs. + InvalidHeaderFormat: On invalid inputs. """ match = _token68_re.match(header, pos) @@ -535,8 +535,8 @@ def parse_authorization_basic(header: str) -> Tuple[str, str]: header: Value of the ``Authorization`` header. Raises: - InvalidHeaderFormat: on invalid inputs. - InvalidHeaderValue: on unsupported inputs. + InvalidHeaderFormat: On invalid inputs. + InvalidHeaderValue: On unsupported inputs. """ # https://www.rfc-editor.org/rfc/rfc7235.html#section-2.1 diff --git a/src/websockets/http11.py b/src/websockets/http11.py index c0a96f87..6fe775ee 100644 --- a/src/websockets/http11.py +++ b/src/websockets/http11.py @@ -97,9 +97,9 @@ def parse( line or raises an exception if there isn't enough data Raises: - EOFError: if the connection is closed without a full HTTP request. - SecurityError: if the request exceeds a security limit. - ValueError: if the request isn't well formatted. + EOFError: If the connection is closed without a full HTTP request. + SecurityError: If the request exceeds a security limit. + ValueError: If the request isn't well formatted. """ # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.1 @@ -201,10 +201,10 @@ def parse( of the stream. Raises: - EOFError: if the connection is closed without a full HTTP response. - SecurityError: if the response exceeds a security limit. - LookupError: if the response isn't well formatted. - ValueError: if the response isn't well formatted. + EOFError: If the connection is closed without a full HTTP response. + SecurityError: If the response exceeds a security limit. + LookupError: If the response isn't well formatted. + ValueError: If the response isn't well formatted. """ # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.2 @@ -299,9 +299,9 @@ def parse_headers( or raises an exception if there isn't enough data. Raises: - EOFError: if the connection is closed without complete headers. - SecurityError: if the request exceeds a security limit. - ValueError: if the request isn't well formatted. + EOFError: If the connection is closed without complete headers. + SecurityError: If the request exceeds a security limit. + ValueError: If the request isn't well formatted. """ # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.2 @@ -350,8 +350,8 @@ def parse_line( or raises an exception if there isn't enough data. Raises: - EOFError: if the connection is closed without a CRLF. - SecurityError: if the response exceeds a security limit. + EOFError: If the connection is closed without a CRLF. + SecurityError: If the response exceeds a security limit. """ try: diff --git a/src/websockets/legacy/server.py b/src/websockets/legacy/server.py index 4af7ed10..e8cf8220 100644 --- a/src/websockets/legacy/server.py +++ b/src/websockets/legacy/server.py @@ -271,7 +271,7 @@ async def read_http_request(self) -> Tuple[str, Headers]: after this coroutine returns. Raises: - InvalidMessage: if the HTTP message is malformed or isn't an + InvalidMessage: If the HTTP message is malformed or isn't an HTTP/1.1 GET request. """ @@ -381,7 +381,7 @@ def process_origin( origins: Optional list of acceptable origins. Raises: - InvalidOrigin: if the origin isn't acceptable. + InvalidOrigin: If the origin isn't acceptable. """ # "The user agent MUST NOT include more than one Origin header field" @@ -432,7 +432,7 @@ def process_extensions( extensions: Optional list of supported extensions. Raises: - InvalidHandshake: to abort the handshake with an HTTP 400 error. + InvalidHandshake: To abort the handshake with an HTTP 400 error. """ response_header_value: Optional[str] = None @@ -492,7 +492,7 @@ def process_subprotocol( available_subprotocols: Optional list of supported subprotocols. Raises: - InvalidHandshake: to abort the handshake with an HTTP 400 error. + InvalidHandshake: To abort the handshake with an HTTP 400 error. """ subprotocol: Optional[Subprotocol] = None @@ -574,7 +574,7 @@ async def handshake( path of the URI of the request. Raises: - InvalidHandshake: if the handshake fails. + InvalidHandshake: If the handshake fails. """ path, request_headers = await self.read_http_request() diff --git a/src/websockets/protocol.py b/src/websockets/protocol.py index 99c9ee1a..6851f3b1 100644 --- a/src/websockets/protocol.py +++ b/src/websockets/protocol.py @@ -217,7 +217,7 @@ def close_exc(self) -> ConnectionClosed: known only once the connection is closed. Raises: - AssertionError: if the connection isn't closed yet. + AssertionError: If the connection isn't closed yet. """ assert self.state is CLOSED, "connection isn't closed yet" @@ -252,7 +252,7 @@ def receive_data(self, data: bytes) -> None: - You should call :meth:`events_received` and process resulting events. Raises: - EOFError: if :meth:`receive_eof` was called earlier. + EOFError: If :meth:`receive_eof` was called earlier. """ self.reader.feed_data(data) @@ -270,7 +270,7 @@ def receive_eof(self) -> None: any new events. Raises: - EOFError: if :meth:`receive_eof` was called earlier. + EOFError: If :meth:`receive_eof` was called earlier. """ self.reader.feed_eof() @@ -292,7 +292,7 @@ def send_continuation(self, data: bytes, fin: bool) -> None: of a fragmented message and to :obj:`False` otherwise. Raises: - ProtocolError: if a fragmented message isn't in progress. + ProtocolError: If a fragmented message isn't in progress. """ if not self.expect_continuation_frame: @@ -313,7 +313,7 @@ def send_text(self, data: bytes, fin: bool = True) -> None: a fragmented message. Raises: - ProtocolError: if a fragmented message is in progress. + ProtocolError: If a fragmented message is in progress. """ if self.expect_continuation_frame: @@ -334,7 +334,7 @@ def send_binary(self, data: bytes, fin: bool = True) -> None: a fragmented message. Raises: - ProtocolError: if a fragmented message is in progress. + ProtocolError: If a fragmented message is in progress. """ if self.expect_continuation_frame: @@ -354,7 +354,7 @@ def send_close(self, code: Optional[int] = None, reason: str = "") -> None: reason: close reason. Raises: - ProtocolError: if a fragmented message is being sent, if the code + ProtocolError: If a fragmented message is being sent, if the code isn't valid, or if a reason is provided without a code """ @@ -412,7 +412,7 @@ def fail(self, code: int, reason: str = "") -> None: reason: close reason Raises: - ProtocolError: if the code isn't valid. + ProtocolError: If the code isn't valid. """ # 7.1.7. Fail the WebSocket Connection diff --git a/src/websockets/server.py b/src/websockets/server.py index 6711a0bb..330e54f3 100644 --- a/src/websockets/server.py +++ b/src/websockets/server.py @@ -217,7 +217,7 @@ def process_request( ``Sec-WebSocket-Protocol`` headers for the handshake response. Raises: - InvalidHandshake: if the handshake request is invalid; + InvalidHandshake: If the handshake request is invalid; then the server must return 400 Bad Request error. """ @@ -296,8 +296,8 @@ def process_origin(self, headers: Headers) -> Optional[Origin]: origin, if it is acceptable. Raises: - InvalidHandshake: if the Origin header is invalid. - InvalidOrigin: if the origin isn't acceptable. + InvalidHandshake: If the Origin header is invalid. + InvalidOrigin: If the origin isn't acceptable. """ # "The user agent MUST NOT include more than one Origin header field" @@ -347,7 +347,7 @@ def process_extensions( accepted extensions. Raises: - InvalidHandshake: if the Sec-WebSocket-Extensions header is invalid. + InvalidHandshake: If the Sec-WebSocket-Extensions header is invalid. """ response_header_value: Optional[str] = None @@ -404,7 +404,7 @@ def process_subprotocol(self, headers: Headers) -> Optional[Subprotocol]: ``Sec-WebSocket-Protocol`` response header. Raises: - InvalidHandshake: if the Sec-WebSocket-Subprotocol header is invalid. + InvalidHandshake: If the Sec-WebSocket-Subprotocol header is invalid. """ subprotocols: Sequence[Subprotocol] = sum( @@ -453,7 +453,7 @@ def select_subprotocol(protocol, subprotocols): :obj:`None` to continue without a subprotocol. Raises: - NegotiationError: custom implementations may raise this exception + NegotiationError: Custom implementations may raise this exception to abort the handshake with an HTTP 400 error. """ diff --git a/src/websockets/streams.py b/src/websockets/streams.py index d288cf0c..956f139d 100644 --- a/src/websockets/streams.py +++ b/src/websockets/streams.py @@ -29,8 +29,8 @@ def read_line(self, m: int) -> Generator[None, None, bytes]: m: Maximum number bytes to read; this is a security limit. Raises: - EOFError: if the stream ends without a LF. - RuntimeError: if the stream ends in more than ``m`` bytes. + EOFError: If the stream ends without a LF. + RuntimeError: If the stream ends in more than ``m`` bytes. """ n = 0 # number of bytes to read @@ -61,7 +61,7 @@ def read_exact(self, n: int) -> Generator[None, None, bytes]: n: How many bytes to read. Raises: - EOFError: if the stream ends in less than ``n`` bytes. + EOFError: If the stream ends in less than ``n`` bytes. """ assert n >= 0 @@ -84,7 +84,7 @@ def read_to_eof(self, m: int) -> Generator[None, None, bytes]: m: Maximum number bytes to read; this is a security limit. Raises: - RuntimeError: if the stream ends in more than ``m`` bytes. + RuntimeError: If the stream ends in more than ``m`` bytes. """ while not self.eof: @@ -122,7 +122,7 @@ def feed_data(self, data: bytes) -> None: data: Data to write. Raises: - EOFError: if the stream has ended. + EOFError: If the stream has ended. """ if self.eof: @@ -136,7 +136,7 @@ def feed_eof(self) -> None: :meth:`feed_eof` cannot be called more than once. Raises: - EOFError: if the stream has ended. + EOFError: If the stream has ended. """ if self.eof: diff --git a/src/websockets/uri.py b/src/websockets/uri.py index 970020e2..8cf58174 100644 --- a/src/websockets/uri.py +++ b/src/websockets/uri.py @@ -69,7 +69,7 @@ def parse_uri(uri: str) -> WebSocketURI: Parsed WebSocket URI. Raises: - InvalidURI: if ``uri`` isn't a valid WebSocket URI. + InvalidURI: If ``uri`` isn't a valid WebSocket URI. """ parsed = urllib.parse.urlparse(uri)