Skip to content

Commit b826ea4

Browse files
committed
chore: new docstrings for Protocol classes
1 parent 4ba1149 commit b826ea4

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

src/netius/base/protocol.py

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,18 @@
3535

3636
class Protocol(observer.Observable):
3737
"""
38-
Abstract class from which concrete implementation of
39-
protocol logic should be inherited.
40-
41-
The logic of a protocol should implement both a reaction
42-
to the arrival of information (receive) and the sending
43-
of processed data (send).
38+
Abstract base for protocol implementations, providing
39+
an interface that is API-compatible with asyncio's
40+
`Protocol` class.
41+
42+
Manages the lifecycle of a connection through the
43+
standard `connection_made` and `connection_lost` callbacks
44+
and provides flow control via `pause_writing` and
45+
`resume_writing`.
46+
47+
Concrete subclasses should override data handling
48+
methods (eg `data_received`, `datagram_received`)
49+
to implement their specific protocol logic.
4450
"""
4551

4652
def __init__(self, owner=None):
@@ -280,6 +286,16 @@ def _flush_send(self):
280286

281287

282288
class DatagramProtocol(Protocol):
289+
"""
290+
Protocol for connectionless datagram-based communication
291+
(eg UDP), API-compatible with asyncio's
292+
`DatagramProtocol`.
293+
294+
Incoming data arrives through `datagram_received`
295+
and outgoing data is sent via `send`. Maintains a
296+
request queue for correlating responses to pending
297+
requests using their identifiers.
298+
"""
283299

284300
def __init__(self):
285301
Protocol.__init__(self)
@@ -349,6 +365,18 @@ def get_request(self, id):
349365

350366

351367
class StreamProtocol(Protocol):
368+
"""
369+
Protocol for stream-based (TCP) communication, providing
370+
an interface compatible with asyncio's `Protocol` class.
371+
372+
Incoming bytes arrive through `data_received` and
373+
outgoing data is written via `send`. Exposes backward
374+
compatibility delegation properties (`socket`, `renable`,
375+
`is_throttleable`, etc.) that reach through the transport
376+
to the underlying `Connection` object, allowing protocol
377+
instances to be used in code paths that still expect the
378+
older `Connection` interface (eg proxy servers).
379+
"""
352380

353381
@property
354382
def connection(self):

0 commit comments

Comments
 (0)