Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python3..../asyncio
File: protocols.py
"""Abstract Protocol class."""
[0] Fix | Delete
[1] Fix | Delete
__all__ = ['BaseProtocol', 'Protocol', 'DatagramProtocol',
[2] Fix | Delete
'SubprocessProtocol']
[3] Fix | Delete
[4] Fix | Delete
[5] Fix | Delete
class BaseProtocol:
[6] Fix | Delete
"""Common base class for protocol interfaces.
[7] Fix | Delete
[8] Fix | Delete
Usually user implements protocols that derived from BaseProtocol
[9] Fix | Delete
like Protocol or ProcessProtocol.
[10] Fix | Delete
[11] Fix | Delete
The only case when BaseProtocol should be implemented directly is
[12] Fix | Delete
write-only transport like write pipe
[13] Fix | Delete
"""
[14] Fix | Delete
[15] Fix | Delete
def connection_made(self, transport):
[16] Fix | Delete
"""Called when a connection is made.
[17] Fix | Delete
[18] Fix | Delete
The argument is the transport representing the pipe connection.
[19] Fix | Delete
To receive data, wait for data_received() calls.
[20] Fix | Delete
When the connection is closed, connection_lost() is called.
[21] Fix | Delete
"""
[22] Fix | Delete
[23] Fix | Delete
def connection_lost(self, exc):
[24] Fix | Delete
"""Called when the connection is lost or closed.
[25] Fix | Delete
[26] Fix | Delete
The argument is an exception object or None (the latter
[27] Fix | Delete
meaning a regular EOF is received or the connection was
[28] Fix | Delete
aborted or closed).
[29] Fix | Delete
"""
[30] Fix | Delete
[31] Fix | Delete
def pause_writing(self):
[32] Fix | Delete
"""Called when the transport's buffer goes over the high-water mark.
[33] Fix | Delete
[34] Fix | Delete
Pause and resume calls are paired -- pause_writing() is called
[35] Fix | Delete
once when the buffer goes strictly over the high-water mark
[36] Fix | Delete
(even if subsequent writes increases the buffer size even
[37] Fix | Delete
more), and eventually resume_writing() is called once when the
[38] Fix | Delete
buffer size reaches the low-water mark.
[39] Fix | Delete
[40] Fix | Delete
Note that if the buffer size equals the high-water mark,
[41] Fix | Delete
pause_writing() is not called -- it must go strictly over.
[42] Fix | Delete
Conversely, resume_writing() is called when the buffer size is
[43] Fix | Delete
equal or lower than the low-water mark. These end conditions
[44] Fix | Delete
are important to ensure that things go as expected when either
[45] Fix | Delete
mark is zero.
[46] Fix | Delete
[47] Fix | Delete
NOTE: This is the only Protocol callback that is not called
[48] Fix | Delete
through EventLoop.call_soon() -- if it were, it would have no
[49] Fix | Delete
effect when it's most needed (when the app keeps writing
[50] Fix | Delete
without yielding until pause_writing() is called).
[51] Fix | Delete
"""
[52] Fix | Delete
[53] Fix | Delete
def resume_writing(self):
[54] Fix | Delete
"""Called when the transport's buffer drains below the low-water mark.
[55] Fix | Delete
[56] Fix | Delete
See pause_writing() for details.
[57] Fix | Delete
"""
[58] Fix | Delete
[59] Fix | Delete
[60] Fix | Delete
class Protocol(BaseProtocol):
[61] Fix | Delete
"""Interface for stream protocol.
[62] Fix | Delete
[63] Fix | Delete
The user should implement this interface. They can inherit from
[64] Fix | Delete
this class but don't need to. The implementations here do
[65] Fix | Delete
nothing (they don't raise exceptions).
[66] Fix | Delete
[67] Fix | Delete
When the user wants to requests a transport, they pass a protocol
[68] Fix | Delete
factory to a utility function (e.g., EventLoop.create_connection()).
[69] Fix | Delete
[70] Fix | Delete
When the connection is made successfully, connection_made() is
[71] Fix | Delete
called with a suitable transport object. Then data_received()
[72] Fix | Delete
will be called 0 or more times with data (bytes) received from the
[73] Fix | Delete
transport; finally, connection_lost() will be called exactly once
[74] Fix | Delete
with either an exception object or None as an argument.
[75] Fix | Delete
[76] Fix | Delete
State machine of calls:
[77] Fix | Delete
[78] Fix | Delete
start -> CM [-> DR*] [-> ER?] -> CL -> end
[79] Fix | Delete
[80] Fix | Delete
* CM: connection_made()
[81] Fix | Delete
* DR: data_received()
[82] Fix | Delete
* ER: eof_received()
[83] Fix | Delete
* CL: connection_lost()
[84] Fix | Delete
"""
[85] Fix | Delete
[86] Fix | Delete
def data_received(self, data):
[87] Fix | Delete
"""Called when some data is received.
[88] Fix | Delete
[89] Fix | Delete
The argument is a bytes object.
[90] Fix | Delete
"""
[91] Fix | Delete
[92] Fix | Delete
def eof_received(self):
[93] Fix | Delete
"""Called when the other end calls write_eof() or equivalent.
[94] Fix | Delete
[95] Fix | Delete
If this returns a false value (including None), the transport
[96] Fix | Delete
will close itself. If it returns a true value, closing the
[97] Fix | Delete
transport is up to the protocol.
[98] Fix | Delete
"""
[99] Fix | Delete
[100] Fix | Delete
[101] Fix | Delete
class DatagramProtocol(BaseProtocol):
[102] Fix | Delete
"""Interface for datagram protocol."""
[103] Fix | Delete
[104] Fix | Delete
def datagram_received(self, data, addr):
[105] Fix | Delete
"""Called when some datagram is received."""
[106] Fix | Delete
[107] Fix | Delete
def error_received(self, exc):
[108] Fix | Delete
"""Called when a send or receive operation raises an OSError.
[109] Fix | Delete
[110] Fix | Delete
(Other than BlockingIOError or InterruptedError.)
[111] Fix | Delete
"""
[112] Fix | Delete
[113] Fix | Delete
[114] Fix | Delete
class SubprocessProtocol(BaseProtocol):
[115] Fix | Delete
"""Interface for protocol for subprocess calls."""
[116] Fix | Delete
[117] Fix | Delete
def pipe_data_received(self, fd, data):
[118] Fix | Delete
"""Called when the subprocess writes data into stdout/stderr pipe.
[119] Fix | Delete
[120] Fix | Delete
fd is int file descriptor.
[121] Fix | Delete
data is bytes object.
[122] Fix | Delete
"""
[123] Fix | Delete
[124] Fix | Delete
def pipe_connection_lost(self, fd, exc):
[125] Fix | Delete
"""Called when a file descriptor associated with the child process is
[126] Fix | Delete
closed.
[127] Fix | Delete
[128] Fix | Delete
fd is the int file descriptor that was closed.
[129] Fix | Delete
"""
[130] Fix | Delete
[131] Fix | Delete
def process_exited(self):
[132] Fix | Delete
"""Called when subprocess has exited."""
[133] Fix | Delete
[134] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function