How to use the h11._util.make_sentinel function in h11

To help you get started, we’ve selected a few h11 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github python-hyper / h11 / h11 / _state.py View on Github external
"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},
github python-hyper / h11 / h11 / _state.py View on Github external
]

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: {},
    },
github python-hyper / h11 / h11 / _state.py View on Github external
"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},
github python-hyper / h11 / h11 / _state.py View on Github external
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: {
github python-hyper / h11 / h11 / _state.py View on Github external
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,
github python-hyper / h11 / h11 / _state.py View on Github external
"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},
github python-hyper / h11 / h11 / _state.py View on Github external
"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: {},
github python-hyper / h11 / h11 / _state.py View on Github external
"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},
github python-hyper / h11 / h11 / _state.py View on Github external
# 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")
github python-hyper / h11 / h11 / _connection.py View on Github external
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.