|
35 | 35 |
|
36 | 36 | class Protocol(observer.Observable): |
37 | 37 | """ |
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. |
44 | 50 | """ |
45 | 51 |
|
46 | 52 | def __init__(self, owner=None): |
@@ -280,6 +286,16 @@ def _flush_send(self): |
280 | 286 |
|
281 | 287 |
|
282 | 288 | 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 | + """ |
283 | 299 |
|
284 | 300 | def __init__(self): |
285 | 301 | Protocol.__init__(self) |
@@ -349,6 +365,18 @@ def get_request(self, id): |
349 | 365 |
|
350 | 366 |
|
351 | 367 | 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 | + """ |
352 | 380 |
|
353 | 381 | @property |
354 | 382 | def connection(self): |
|
0 commit comments