MCPcopy Index your code
hub / github.com/python-websockets/websockets / __init__

Method __init__

src/websockets/protocol.py:89–158  ·  view source on GitHub ↗
(
        self,
        side: Side,
        *,
        state: State = OPEN,
        max_size: tuple[int | None, int | None] | int | None = 2**20,
        logger: LoggerLike | None = None,
    )

Source from the content-addressed store, hash-verified

87 """
88
89 def __init__(
90 self,
91 side: Side,
92 *,
93 state: State = OPEN,
94 max_size: tuple[int | None, int | None] | int | None = 2**20,
95 logger: LoggerLike | None = None,
96 ) -> None:
97 # Unique identifier. For logs.
98 self.id: uuid.UUID = uuid.uuid4()
99 """Unique identifier of the connection. Useful in logs."""
100
101 # Logger or LoggerAdapter for this connection.
102 if logger is None:
103 logger = logging.getLogger(f"websockets.{side.name.lower()}")
104 self.logger: LoggerLike = logger
105 """Logger for this connection."""
106
107 # Track if DEBUG is enabled. Shortcut logging calls if it isn't.
108 self.debug = logger.isEnabledFor(logging.DEBUG)
109
110 # Connection side. CLIENT or SERVER.
111 self.side = side
112
113 # Connection state. Initially OPEN because subclasses handle CONNECTING.
114 self.state = state
115
116 # Maximum size of incoming messages in bytes.
117 if isinstance(max_size, int) or max_size is None:
118 self.max_message_size, self.max_fragment_size = max_size, None
119 else:
120 self.max_message_size, self.max_fragment_size = max_size
121
122 # Current size of incoming message in bytes. Only set while reading a
123 # fragmented message i.e. a data frames with the FIN bit not set.
124 self.current_size: int | None = None
125
126 # True while sending a fragmented message i.e. a data frames with the
127 # FIN bit not set.
128 self.expect_continuation_frame = False
129
130 # WebSocket protocol parameters.
131 self.origin: Origin | None = None
132 self.extensions: list[Extension] = []
133 self.subprotocol: Subprotocol | None = None
134
135 # Close code and reason, set when a close frame is sent or received.
136 self.close_rcvd: Close | None = None
137 self.close_sent: Close | None = None
138 self.close_rcvd_then_sent: bool | None = None
139
140 # Track if an exception happened during the handshake.
141 self.handshake_exc: Exception | None = None
142 """
143 Exception to raise if the opening handshake failed.
144
145 :obj:`None` if the opening handshake succeeded.
146

Callers

nothing calls this directly

Calls 2

parseMethod · 0.95
StreamReaderClass · 0.85

Tested by

no test coverage detected