You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Enso-Bot/venv/Lib/site-packages/websockets/exceptions.py

96 lines
2.3 KiB
Python

5 years ago
__all__ = [
'AbortHandshake', 'InvalidHandshake', 'InvalidMessage', 'InvalidOrigin',
'InvalidState', 'InvalidStatusCode', 'InvalidURI', 'ConnectionClosed',
'PayloadTooBig', 'WebSocketProtocolError',
5 years ago
]
class InvalidHandshake(Exception):
5 years ago
"""
Exception raised when a handshake request or response is invalid.
5 years ago
"""
class AbortHandshake(InvalidHandshake):
5 years ago
"""
Exception raised to abort a handshake and return a HTTP response.
5 years ago
"""
def __init__(self, status, headers, body=None):
self.status = status
self.headers = headers
self.body = body
5 years ago
class InvalidMessage(InvalidHandshake):
"""
Exception raised when the HTTP message in a handshake request is malformed.
5 years ago
"""
class InvalidOrigin(InvalidHandshake):
5 years ago
"""
Exception raised when the origin in a handshake request is forbidden.
5 years ago
"""
class InvalidStatusCode(InvalidHandshake):
"""
Exception raised when a handshake response status code is invalid.
5 years ago
Provides the integer status code in its ``status_code`` attribute.
5 years ago
"""
def __init__(self, status_code):
5 years ago
self.status_code = status_code
message = 'Status code not 101: {}'.format(status_code)
5 years ago
super().__init__(message)
class InvalidState(Exception):
5 years ago
"""
Exception raised when an operation is forbidden in the current state.
5 years ago
"""
class ConnectionClosed(InvalidState):
5 years ago
"""
Exception raised when trying to read or write on a closed connection.
5 years ago
Provides the connection close code and reason in its ``code`` and
``reason`` attributes respectively.
5 years ago
"""
def __init__(self, code, reason):
self.code = code
self.reason = reason
message = 'WebSocket connection is closed: '
message += 'code = {}, '.format(code) if code else 'no code, '
message += 'reason = {}.'.format(reason) if reason else 'no reason.'
5 years ago
super().__init__(message)
class InvalidURI(Exception):
5 years ago
"""
Exception raised when an URI isn't a valid websocket URI.
5 years ago
"""
class PayloadTooBig(Exception):
5 years ago
"""
Exception raised when a frame's payload exceeds the maximum size.
5 years ago
"""
class WebSocketProtocolError(Exception):
5 years ago
"""
Internal exception raised when the remote side breaks the protocol.
5 years ago
"""