MCPcopy Index your code
hub / github.com/python/cpython / MySendfileProto

Class MySendfileProto

Lib/test/test_asyncio/test_sendfile.py:28–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26
27
28class MySendfileProto(asyncio.Protocol):
29
30 def __init__(self, loop=None, close_after=0):
31 self.transport = None
32 self.state = 'INITIAL'
33 self.nbytes = 0
34 if loop is not None:
35 self.connected = loop.create_future()
36 self.done = loop.create_future()
37 self.data = bytearray()
38 self.close_after = close_after
39
40 def _assert_state(self, *expected):
41 if self.state not in expected:
42 raise AssertionError(f'state: {self.state!r}, expected: {expected!r}')
43
44 def connection_made(self, transport):
45 self.transport = transport
46 self._assert_state('INITIAL')
47 self.state = 'CONNECTED'
48 if self.connected:
49 self.connected.set_result(None)
50
51 def eof_received(self):
52 self._assert_state('CONNECTED')
53 self.state = 'EOF'
54
55 def connection_lost(self, exc):
56 self._assert_state('CONNECTED', 'EOF')
57 self.state = 'CLOSED'
58 if self.done:
59 self.done.set_result(None)
60
61 def data_received(self, data):
62 self._assert_state('CONNECTED')
63 self.nbytes += len(data)
64 self.data.extend(data)
65 super().data_received(data)
66 if self.close_after and self.nbytes >= self.close_after:
67 self.transport.close()
68
69
70class MyProto(asyncio.Protocol):

Callers 1

prepare_sendfileMethod · 0.85

Calls

no outgoing calls

Tested by 1

prepare_sendfileMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…