Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"SEND_BODY",
"DONE",
"MUST_CLOSE",
"CLOSED",
"MIGHT_SWITCH_PROTOCOL",
"SWITCHED_PROTOCOL",
"ERROR",
]
CLIENT = make_sentinel("CLIENT")
SERVER = make_sentinel("SERVER")
# States
IDLE = make_sentinel("IDLE")
SEND_RESPONSE = make_sentinel("SEND_RESPONSE")
SEND_BODY = make_sentinel("SEND_BODY")
DONE = make_sentinel("DONE")
MUST_CLOSE = make_sentinel("MUST_CLOSE")
CLOSED = make_sentinel("CLOSED")
ERROR = make_sentinel("ERROR")
# Switch types
MIGHT_SWITCH_PROTOCOL = make_sentinel("MIGHT_SWITCH_PROTOCOL")
SWITCHED_PROTOCOL = make_sentinel("SWITCHED_PROTOCOL")
_SWITCH_UPGRADE = make_sentinel("_SWITCH_UPGRADE")
_SWITCH_CONNECT = make_sentinel("_SWITCH_CONNECT")
EVENT_TRIGGERED_TRANSITIONS = {
CLIENT: {
IDLE: {Request: SEND_BODY, ConnectionClosed: CLOSED},
SEND_BODY: {Data: SEND_BODY, EndOfMessage: DONE},
]
CLIENT = make_sentinel("CLIENT")
SERVER = make_sentinel("SERVER")
# States
IDLE = make_sentinel("IDLE")
SEND_RESPONSE = make_sentinel("SEND_RESPONSE")
SEND_BODY = make_sentinel("SEND_BODY")
DONE = make_sentinel("DONE")
MUST_CLOSE = make_sentinel("MUST_CLOSE")
CLOSED = make_sentinel("CLOSED")
ERROR = make_sentinel("ERROR")
# Switch types
MIGHT_SWITCH_PROTOCOL = make_sentinel("MIGHT_SWITCH_PROTOCOL")
SWITCHED_PROTOCOL = make_sentinel("SWITCHED_PROTOCOL")
_SWITCH_UPGRADE = make_sentinel("_SWITCH_UPGRADE")
_SWITCH_CONNECT = make_sentinel("_SWITCH_CONNECT")
EVENT_TRIGGERED_TRANSITIONS = {
CLIENT: {
IDLE: {Request: SEND_BODY, ConnectionClosed: CLOSED},
SEND_BODY: {Data: SEND_BODY, EndOfMessage: DONE},
DONE: {ConnectionClosed: CLOSED},
MUST_CLOSE: {ConnectionClosed: CLOSED},
CLOSED: {ConnectionClosed: CLOSED},
MIGHT_SWITCH_PROTOCOL: {},
SWITCHED_PROTOCOL: {},
ERROR: {},
},
"SEND_RESPONSE",
"SEND_BODY",
"DONE",
"MUST_CLOSE",
"CLOSED",
"MIGHT_SWITCH_PROTOCOL",
"SWITCHED_PROTOCOL",
"ERROR",
]
CLIENT = make_sentinel("CLIENT")
SERVER = make_sentinel("SERVER")
# States
IDLE = make_sentinel("IDLE")
SEND_RESPONSE = make_sentinel("SEND_RESPONSE")
SEND_BODY = make_sentinel("SEND_BODY")
DONE = make_sentinel("DONE")
MUST_CLOSE = make_sentinel("MUST_CLOSE")
CLOSED = make_sentinel("CLOSED")
ERROR = make_sentinel("ERROR")
# Switch types
MIGHT_SWITCH_PROTOCOL = make_sentinel("MIGHT_SWITCH_PROTOCOL")
SWITCHED_PROTOCOL = make_sentinel("SWITCHED_PROTOCOL")
_SWITCH_UPGRADE = make_sentinel("_SWITCH_UPGRADE")
_SWITCH_CONNECT = make_sentinel("_SWITCH_CONNECT")
EVENT_TRIGGERED_TRANSITIONS = {
CLIENT: {
IDLE: {Request: SEND_BODY, ConnectionClosed: CLOSED},
CLIENT = make_sentinel("CLIENT")
SERVER = make_sentinel("SERVER")
# States
IDLE = make_sentinel("IDLE")
SEND_RESPONSE = make_sentinel("SEND_RESPONSE")
SEND_BODY = make_sentinel("SEND_BODY")
DONE = make_sentinel("DONE")
MUST_CLOSE = make_sentinel("MUST_CLOSE")
CLOSED = make_sentinel("CLOSED")
ERROR = make_sentinel("ERROR")
# Switch types
MIGHT_SWITCH_PROTOCOL = make_sentinel("MIGHT_SWITCH_PROTOCOL")
SWITCHED_PROTOCOL = make_sentinel("SWITCHED_PROTOCOL")
_SWITCH_UPGRADE = make_sentinel("_SWITCH_UPGRADE")
_SWITCH_CONNECT = make_sentinel("_SWITCH_CONNECT")
EVENT_TRIGGERED_TRANSITIONS = {
CLIENT: {
IDLE: {Request: SEND_BODY, ConnectionClosed: CLOSED},
SEND_BODY: {Data: SEND_BODY, EndOfMessage: DONE},
DONE: {ConnectionClosed: CLOSED},
MUST_CLOSE: {ConnectionClosed: CLOSED},
CLOSED: {ConnectionClosed: CLOSED},
MIGHT_SWITCH_PROTOCOL: {},
SWITCHED_PROTOCOL: {},
ERROR: {},
},
SERVER: {
SERVER = make_sentinel("SERVER")
# States
IDLE = make_sentinel("IDLE")
SEND_RESPONSE = make_sentinel("SEND_RESPONSE")
SEND_BODY = make_sentinel("SEND_BODY")
DONE = make_sentinel("DONE")
MUST_CLOSE = make_sentinel("MUST_CLOSE")
CLOSED = make_sentinel("CLOSED")
ERROR = make_sentinel("ERROR")
# Switch types
MIGHT_SWITCH_PROTOCOL = make_sentinel("MIGHT_SWITCH_PROTOCOL")
SWITCHED_PROTOCOL = make_sentinel("SWITCHED_PROTOCOL")
_SWITCH_UPGRADE = make_sentinel("_SWITCH_UPGRADE")
_SWITCH_CONNECT = make_sentinel("_SWITCH_CONNECT")
EVENT_TRIGGERED_TRANSITIONS = {
CLIENT: {
IDLE: {Request: SEND_BODY, ConnectionClosed: CLOSED},
SEND_BODY: {Data: SEND_BODY, EndOfMessage: DONE},
DONE: {ConnectionClosed: CLOSED},
MUST_CLOSE: {ConnectionClosed: CLOSED},
CLOSED: {ConnectionClosed: CLOSED},
MIGHT_SWITCH_PROTOCOL: {},
SWITCHED_PROTOCOL: {},
ERROR: {},
},
SERVER: {
IDLE: {
ConnectionClosed: CLOSED,
"CLOSED",
"MIGHT_SWITCH_PROTOCOL",
"SWITCHED_PROTOCOL",
"ERROR",
]
CLIENT = make_sentinel("CLIENT")
SERVER = make_sentinel("SERVER")
# States
IDLE = make_sentinel("IDLE")
SEND_RESPONSE = make_sentinel("SEND_RESPONSE")
SEND_BODY = make_sentinel("SEND_BODY")
DONE = make_sentinel("DONE")
MUST_CLOSE = make_sentinel("MUST_CLOSE")
CLOSED = make_sentinel("CLOSED")
ERROR = make_sentinel("ERROR")
# Switch types
MIGHT_SWITCH_PROTOCOL = make_sentinel("MIGHT_SWITCH_PROTOCOL")
SWITCHED_PROTOCOL = make_sentinel("SWITCHED_PROTOCOL")
_SWITCH_UPGRADE = make_sentinel("_SWITCH_UPGRADE")
_SWITCH_CONNECT = make_sentinel("_SWITCH_CONNECT")
EVENT_TRIGGERED_TRANSITIONS = {
CLIENT: {
IDLE: {Request: SEND_BODY, ConnectionClosed: CLOSED},
SEND_BODY: {Data: SEND_BODY, EndOfMessage: DONE},
DONE: {ConnectionClosed: CLOSED},
MUST_CLOSE: {ConnectionClosed: CLOSED},
CLOSED: {ConnectionClosed: CLOSED},
"MIGHT_SWITCH_PROTOCOL",
"SWITCHED_PROTOCOL",
"ERROR",
]
CLIENT = make_sentinel("CLIENT")
SERVER = make_sentinel("SERVER")
# States
IDLE = make_sentinel("IDLE")
SEND_RESPONSE = make_sentinel("SEND_RESPONSE")
SEND_BODY = make_sentinel("SEND_BODY")
DONE = make_sentinel("DONE")
MUST_CLOSE = make_sentinel("MUST_CLOSE")
CLOSED = make_sentinel("CLOSED")
ERROR = make_sentinel("ERROR")
# Switch types
MIGHT_SWITCH_PROTOCOL = make_sentinel("MIGHT_SWITCH_PROTOCOL")
SWITCHED_PROTOCOL = make_sentinel("SWITCHED_PROTOCOL")
_SWITCH_UPGRADE = make_sentinel("_SWITCH_UPGRADE")
_SWITCH_CONNECT = make_sentinel("_SWITCH_CONNECT")
EVENT_TRIGGERED_TRANSITIONS = {
CLIENT: {
IDLE: {Request: SEND_BODY, ConnectionClosed: CLOSED},
SEND_BODY: {Data: SEND_BODY, EndOfMessage: DONE},
DONE: {ConnectionClosed: CLOSED},
MUST_CLOSE: {ConnectionClosed: CLOSED},
CLOSED: {ConnectionClosed: CLOSED},
MIGHT_SWITCH_PROTOCOL: {},
"MUST_CLOSE",
"CLOSED",
"MIGHT_SWITCH_PROTOCOL",
"SWITCHED_PROTOCOL",
"ERROR",
]
CLIENT = make_sentinel("CLIENT")
SERVER = make_sentinel("SERVER")
# States
IDLE = make_sentinel("IDLE")
SEND_RESPONSE = make_sentinel("SEND_RESPONSE")
SEND_BODY = make_sentinel("SEND_BODY")
DONE = make_sentinel("DONE")
MUST_CLOSE = make_sentinel("MUST_CLOSE")
CLOSED = make_sentinel("CLOSED")
ERROR = make_sentinel("ERROR")
# Switch types
MIGHT_SWITCH_PROTOCOL = make_sentinel("MIGHT_SWITCH_PROTOCOL")
SWITCHED_PROTOCOL = make_sentinel("SWITCHED_PROTOCOL")
_SWITCH_UPGRADE = make_sentinel("_SWITCH_UPGRADE")
_SWITCH_CONNECT = make_sentinel("_SWITCH_CONNECT")
EVENT_TRIGGERED_TRANSITIONS = {
CLIENT: {
IDLE: {Request: SEND_BODY, ConnectionClosed: CLOSED},
SEND_BODY: {Data: SEND_BODY, EndOfMessage: DONE},
DONE: {ConnectionClosed: CLOSED},
MUST_CLOSE: {ConnectionClosed: CLOSED},
# Everything in __all__ gets re-exported as part of the h11 public API.
__all__ = [
"CLIENT",
"SERVER",
"IDLE",
"SEND_RESPONSE",
"SEND_BODY",
"DONE",
"MUST_CLOSE",
"CLOSED",
"MIGHT_SWITCH_PROTOCOL",
"SWITCHED_PROTOCOL",
"ERROR",
]
CLIENT = make_sentinel("CLIENT")
SERVER = make_sentinel("SERVER")
# States
IDLE = make_sentinel("IDLE")
SEND_RESPONSE = make_sentinel("SEND_RESPONSE")
SEND_BODY = make_sentinel("SEND_BODY")
DONE = make_sentinel("DONE")
MUST_CLOSE = make_sentinel("MUST_CLOSE")
CLOSED = make_sentinel("CLOSED")
ERROR = make_sentinel("ERROR")
# Switch types
MIGHT_SWITCH_PROTOCOL = make_sentinel("MIGHT_SWITCH_PROTOCOL")
SWITCHED_PROTOCOL = make_sentinel("SWITCHED_PROTOCOL")
_SWITCH_UPGRADE = make_sentinel("_SWITCH_UPGRADE")
from ._readers import READERS
from ._receivebuffer import ReceiveBuffer
from ._state import * # Import all state sentinels
from ._state import _SWITCH_CONNECT, _SWITCH_UPGRADE, ConnectionState
from ._util import ( # Import the internal things we need
LocalProtocolError,
make_sentinel,
RemoteProtocolError,
)
from ._writers import WRITERS
# Everything in __all__ gets re-exported as part of the h11 public API.
__all__ = ["Connection", "NEED_DATA", "PAUSED"]
NEED_DATA = make_sentinel("NEED_DATA")
PAUSED = make_sentinel("PAUSED")
# If we ever have this much buffered without it making a complete parseable
# event, we error out. The only time we really buffer is when reading the
# request/reponse line + headers together, so this is effectively the limit on
# the size of that.
#
# Some precedents for defaults:
# - node.js: 80 * 1024
# - tomcat: 8 * 1024
# - IIS: 16 * 1024
# - Apache: <8 KiB per line>
DEFAULT_MAX_INCOMPLETE_EVENT_SIZE = 16 * 1024
# RFC 7230's rules for connection lifecycles:
# - If either side says they want to close the connection, then the connection
# must close.