Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python3..../asyncio
File: sslproto.py
import collections
[0] Fix | Delete
import warnings
[1] Fix | Delete
try:
[2] Fix | Delete
import ssl
[3] Fix | Delete
except ImportError: # pragma: no cover
[4] Fix | Delete
ssl = None
[5] Fix | Delete
[6] Fix | Delete
from . import base_events
[7] Fix | Delete
from . import compat
[8] Fix | Delete
from . import protocols
[9] Fix | Delete
from . import transports
[10] Fix | Delete
from .log import logger
[11] Fix | Delete
[12] Fix | Delete
[13] Fix | Delete
def _create_transport_context(server_side, server_hostname):
[14] Fix | Delete
if server_side:
[15] Fix | Delete
raise ValueError('Server side SSL needs a valid SSLContext')
[16] Fix | Delete
[17] Fix | Delete
# Client side may pass ssl=True to use a default
[18] Fix | Delete
# context; in that case the sslcontext passed is None.
[19] Fix | Delete
# The default is secure for client connections.
[20] Fix | Delete
if hasattr(ssl, 'create_default_context'):
[21] Fix | Delete
# Python 3.4+: use up-to-date strong settings.
[22] Fix | Delete
sslcontext = ssl.create_default_context()
[23] Fix | Delete
if not server_hostname:
[24] Fix | Delete
sslcontext.check_hostname = False
[25] Fix | Delete
else:
[26] Fix | Delete
# Fallback for Python 3.3.
[27] Fix | Delete
sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
[28] Fix | Delete
sslcontext.options |= ssl.OP_NO_SSLv2
[29] Fix | Delete
sslcontext.options |= ssl.OP_NO_SSLv3
[30] Fix | Delete
sslcontext.set_default_verify_paths()
[31] Fix | Delete
sslcontext.verify_mode = ssl.CERT_REQUIRED
[32] Fix | Delete
return sslcontext
[33] Fix | Delete
[34] Fix | Delete
[35] Fix | Delete
def _is_sslproto_available():
[36] Fix | Delete
return hasattr(ssl, "MemoryBIO")
[37] Fix | Delete
[38] Fix | Delete
[39] Fix | Delete
# States of an _SSLPipe.
[40] Fix | Delete
_UNWRAPPED = "UNWRAPPED"
[41] Fix | Delete
_DO_HANDSHAKE = "DO_HANDSHAKE"
[42] Fix | Delete
_WRAPPED = "WRAPPED"
[43] Fix | Delete
_SHUTDOWN = "SHUTDOWN"
[44] Fix | Delete
[45] Fix | Delete
[46] Fix | Delete
class _SSLPipe(object):
[47] Fix | Delete
"""An SSL "Pipe".
[48] Fix | Delete
[49] Fix | Delete
An SSL pipe allows you to communicate with an SSL/TLS protocol instance
[50] Fix | Delete
through memory buffers. It can be used to implement a security layer for an
[51] Fix | Delete
existing connection where you don't have access to the connection's file
[52] Fix | Delete
descriptor, or for some reason you don't want to use it.
[53] Fix | Delete
[54] Fix | Delete
An SSL pipe can be in "wrapped" and "unwrapped" mode. In unwrapped mode,
[55] Fix | Delete
data is passed through untransformed. In wrapped mode, application level
[56] Fix | Delete
data is encrypted to SSL record level data and vice versa. The SSL record
[57] Fix | Delete
level is the lowest level in the SSL protocol suite and is what travels
[58] Fix | Delete
as-is over the wire.
[59] Fix | Delete
[60] Fix | Delete
An SslPipe initially is in "unwrapped" mode. To start SSL, call
[61] Fix | Delete
do_handshake(). To shutdown SSL again, call unwrap().
[62] Fix | Delete
"""
[63] Fix | Delete
[64] Fix | Delete
max_size = 256 * 1024 # Buffer size passed to read()
[65] Fix | Delete
[66] Fix | Delete
def __init__(self, context, server_side, server_hostname=None):
[67] Fix | Delete
"""
[68] Fix | Delete
The *context* argument specifies the ssl.SSLContext to use.
[69] Fix | Delete
[70] Fix | Delete
The *server_side* argument indicates whether this is a server side or
[71] Fix | Delete
client side transport.
[72] Fix | Delete
[73] Fix | Delete
The optional *server_hostname* argument can be used to specify the
[74] Fix | Delete
hostname you are connecting to. You may only specify this parameter if
[75] Fix | Delete
the _ssl module supports Server Name Indication (SNI).
[76] Fix | Delete
"""
[77] Fix | Delete
self._context = context
[78] Fix | Delete
self._server_side = server_side
[79] Fix | Delete
self._server_hostname = server_hostname
[80] Fix | Delete
self._state = _UNWRAPPED
[81] Fix | Delete
self._incoming = ssl.MemoryBIO()
[82] Fix | Delete
self._outgoing = ssl.MemoryBIO()
[83] Fix | Delete
self._sslobj = None
[84] Fix | Delete
self._need_ssldata = False
[85] Fix | Delete
self._handshake_cb = None
[86] Fix | Delete
self._shutdown_cb = None
[87] Fix | Delete
[88] Fix | Delete
@property
[89] Fix | Delete
def context(self):
[90] Fix | Delete
"""The SSL context passed to the constructor."""
[91] Fix | Delete
return self._context
[92] Fix | Delete
[93] Fix | Delete
@property
[94] Fix | Delete
def ssl_object(self):
[95] Fix | Delete
"""The internal ssl.SSLObject instance.
[96] Fix | Delete
[97] Fix | Delete
Return None if the pipe is not wrapped.
[98] Fix | Delete
"""
[99] Fix | Delete
return self._sslobj
[100] Fix | Delete
[101] Fix | Delete
@property
[102] Fix | Delete
def need_ssldata(self):
[103] Fix | Delete
"""Whether more record level data is needed to complete a handshake
[104] Fix | Delete
that is currently in progress."""
[105] Fix | Delete
return self._need_ssldata
[106] Fix | Delete
[107] Fix | Delete
@property
[108] Fix | Delete
def wrapped(self):
[109] Fix | Delete
"""
[110] Fix | Delete
Whether a security layer is currently in effect.
[111] Fix | Delete
[112] Fix | Delete
Return False during handshake.
[113] Fix | Delete
"""
[114] Fix | Delete
return self._state == _WRAPPED
[115] Fix | Delete
[116] Fix | Delete
def do_handshake(self, callback=None):
[117] Fix | Delete
"""Start the SSL handshake.
[118] Fix | Delete
[119] Fix | Delete
Return a list of ssldata. A ssldata element is a list of buffers
[120] Fix | Delete
[121] Fix | Delete
The optional *callback* argument can be used to install a callback that
[122] Fix | Delete
will be called when the handshake is complete. The callback will be
[123] Fix | Delete
called with None if successful, else an exception instance.
[124] Fix | Delete
"""
[125] Fix | Delete
if self._state != _UNWRAPPED:
[126] Fix | Delete
raise RuntimeError('handshake in progress or completed')
[127] Fix | Delete
self._sslobj = self._context.wrap_bio(
[128] Fix | Delete
self._incoming, self._outgoing,
[129] Fix | Delete
server_side=self._server_side,
[130] Fix | Delete
server_hostname=self._server_hostname)
[131] Fix | Delete
self._state = _DO_HANDSHAKE
[132] Fix | Delete
self._handshake_cb = callback
[133] Fix | Delete
ssldata, appdata = self.feed_ssldata(b'', only_handshake=True)
[134] Fix | Delete
assert len(appdata) == 0
[135] Fix | Delete
return ssldata
[136] Fix | Delete
[137] Fix | Delete
def shutdown(self, callback=None):
[138] Fix | Delete
"""Start the SSL shutdown sequence.
[139] Fix | Delete
[140] Fix | Delete
Return a list of ssldata. A ssldata element is a list of buffers
[141] Fix | Delete
[142] Fix | Delete
The optional *callback* argument can be used to install a callback that
[143] Fix | Delete
will be called when the shutdown is complete. The callback will be
[144] Fix | Delete
called without arguments.
[145] Fix | Delete
"""
[146] Fix | Delete
if self._state == _UNWRAPPED:
[147] Fix | Delete
raise RuntimeError('no security layer present')
[148] Fix | Delete
if self._state == _SHUTDOWN:
[149] Fix | Delete
raise RuntimeError('shutdown in progress')
[150] Fix | Delete
assert self._state in (_WRAPPED, _DO_HANDSHAKE)
[151] Fix | Delete
self._state = _SHUTDOWN
[152] Fix | Delete
self._shutdown_cb = callback
[153] Fix | Delete
ssldata, appdata = self.feed_ssldata(b'')
[154] Fix | Delete
assert appdata == [] or appdata == [b'']
[155] Fix | Delete
return ssldata
[156] Fix | Delete
[157] Fix | Delete
def feed_eof(self):
[158] Fix | Delete
"""Send a potentially "ragged" EOF.
[159] Fix | Delete
[160] Fix | Delete
This method will raise an SSL_ERROR_EOF exception if the EOF is
[161] Fix | Delete
unexpected.
[162] Fix | Delete
"""
[163] Fix | Delete
self._incoming.write_eof()
[164] Fix | Delete
ssldata, appdata = self.feed_ssldata(b'')
[165] Fix | Delete
assert appdata == [] or appdata == [b'']
[166] Fix | Delete
[167] Fix | Delete
def feed_ssldata(self, data, only_handshake=False):
[168] Fix | Delete
"""Feed SSL record level data into the pipe.
[169] Fix | Delete
[170] Fix | Delete
The data must be a bytes instance. It is OK to send an empty bytes
[171] Fix | Delete
instance. This can be used to get ssldata for a handshake initiated by
[172] Fix | Delete
this endpoint.
[173] Fix | Delete
[174] Fix | Delete
Return a (ssldata, appdata) tuple. The ssldata element is a list of
[175] Fix | Delete
buffers containing SSL data that needs to be sent to the remote SSL.
[176] Fix | Delete
[177] Fix | Delete
The appdata element is a list of buffers containing plaintext data that
[178] Fix | Delete
needs to be forwarded to the application. The appdata list may contain
[179] Fix | Delete
an empty buffer indicating an SSL "close_notify" alert. This alert must
[180] Fix | Delete
be acknowledged by calling shutdown().
[181] Fix | Delete
"""
[182] Fix | Delete
if self._state == _UNWRAPPED:
[183] Fix | Delete
# If unwrapped, pass plaintext data straight through.
[184] Fix | Delete
if data:
[185] Fix | Delete
appdata = [data]
[186] Fix | Delete
else:
[187] Fix | Delete
appdata = []
[188] Fix | Delete
return ([], appdata)
[189] Fix | Delete
[190] Fix | Delete
self._need_ssldata = False
[191] Fix | Delete
if data:
[192] Fix | Delete
self._incoming.write(data)
[193] Fix | Delete
[194] Fix | Delete
ssldata = []
[195] Fix | Delete
appdata = []
[196] Fix | Delete
try:
[197] Fix | Delete
if self._state == _DO_HANDSHAKE:
[198] Fix | Delete
# Call do_handshake() until it doesn't raise anymore.
[199] Fix | Delete
self._sslobj.do_handshake()
[200] Fix | Delete
self._state = _WRAPPED
[201] Fix | Delete
if self._handshake_cb:
[202] Fix | Delete
self._handshake_cb(None)
[203] Fix | Delete
if only_handshake:
[204] Fix | Delete
return (ssldata, appdata)
[205] Fix | Delete
# Handshake done: execute the wrapped block
[206] Fix | Delete
[207] Fix | Delete
if self._state == _WRAPPED:
[208] Fix | Delete
# Main state: read data from SSL until close_notify
[209] Fix | Delete
while True:
[210] Fix | Delete
chunk = self._sslobj.read(self.max_size)
[211] Fix | Delete
appdata.append(chunk)
[212] Fix | Delete
if not chunk: # close_notify
[213] Fix | Delete
break
[214] Fix | Delete
[215] Fix | Delete
elif self._state == _SHUTDOWN:
[216] Fix | Delete
# Call shutdown() until it doesn't raise anymore.
[217] Fix | Delete
self._sslobj.unwrap()
[218] Fix | Delete
self._sslobj = None
[219] Fix | Delete
self._state = _UNWRAPPED
[220] Fix | Delete
if self._shutdown_cb:
[221] Fix | Delete
self._shutdown_cb()
[222] Fix | Delete
[223] Fix | Delete
elif self._state == _UNWRAPPED:
[224] Fix | Delete
# Drain possible plaintext data after close_notify.
[225] Fix | Delete
appdata.append(self._incoming.read())
[226] Fix | Delete
except (ssl.SSLError, ssl.CertificateError) as exc:
[227] Fix | Delete
if getattr(exc, 'errno', None) not in (
[228] Fix | Delete
ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE,
[229] Fix | Delete
ssl.SSL_ERROR_SYSCALL):
[230] Fix | Delete
if self._state == _DO_HANDSHAKE and self._handshake_cb:
[231] Fix | Delete
self._handshake_cb(exc)
[232] Fix | Delete
raise
[233] Fix | Delete
self._need_ssldata = (exc.errno == ssl.SSL_ERROR_WANT_READ)
[234] Fix | Delete
[235] Fix | Delete
# Check for record level data that needs to be sent back.
[236] Fix | Delete
# Happens for the initial handshake and renegotiations.
[237] Fix | Delete
if self._outgoing.pending:
[238] Fix | Delete
ssldata.append(self._outgoing.read())
[239] Fix | Delete
return (ssldata, appdata)
[240] Fix | Delete
[241] Fix | Delete
def feed_appdata(self, data, offset=0):
[242] Fix | Delete
"""Feed plaintext data into the pipe.
[243] Fix | Delete
[244] Fix | Delete
Return an (ssldata, offset) tuple. The ssldata element is a list of
[245] Fix | Delete
buffers containing record level data that needs to be sent to the
[246] Fix | Delete
remote SSL instance. The offset is the number of plaintext bytes that
[247] Fix | Delete
were processed, which may be less than the length of data.
[248] Fix | Delete
[249] Fix | Delete
NOTE: In case of short writes, this call MUST be retried with the SAME
[250] Fix | Delete
buffer passed into the *data* argument (i.e. the id() must be the
[251] Fix | Delete
same). This is an OpenSSL requirement. A further particularity is that
[252] Fix | Delete
a short write will always have offset == 0, because the _ssl module
[253] Fix | Delete
does not enable partial writes. And even though the offset is zero,
[254] Fix | Delete
there will still be encrypted data in ssldata.
[255] Fix | Delete
"""
[256] Fix | Delete
assert 0 <= offset <= len(data)
[257] Fix | Delete
if self._state == _UNWRAPPED:
[258] Fix | Delete
# pass through data in unwrapped mode
[259] Fix | Delete
if offset < len(data):
[260] Fix | Delete
ssldata = [data[offset:]]
[261] Fix | Delete
else:
[262] Fix | Delete
ssldata = []
[263] Fix | Delete
return (ssldata, len(data))
[264] Fix | Delete
[265] Fix | Delete
ssldata = []
[266] Fix | Delete
view = memoryview(data)
[267] Fix | Delete
while True:
[268] Fix | Delete
self._need_ssldata = False
[269] Fix | Delete
try:
[270] Fix | Delete
if offset < len(view):
[271] Fix | Delete
offset += self._sslobj.write(view[offset:])
[272] Fix | Delete
except ssl.SSLError as exc:
[273] Fix | Delete
# It is not allowed to call write() after unwrap() until the
[274] Fix | Delete
# close_notify is acknowledged. We return the condition to the
[275] Fix | Delete
# caller as a short write.
[276] Fix | Delete
if exc.reason == 'PROTOCOL_IS_SHUTDOWN':
[277] Fix | Delete
exc.errno = ssl.SSL_ERROR_WANT_READ
[278] Fix | Delete
if exc.errno not in (ssl.SSL_ERROR_WANT_READ,
[279] Fix | Delete
ssl.SSL_ERROR_WANT_WRITE,
[280] Fix | Delete
ssl.SSL_ERROR_SYSCALL):
[281] Fix | Delete
raise
[282] Fix | Delete
self._need_ssldata = (exc.errno == ssl.SSL_ERROR_WANT_READ)
[283] Fix | Delete
[284] Fix | Delete
# See if there's any record level data back for us.
[285] Fix | Delete
if self._outgoing.pending:
[286] Fix | Delete
ssldata.append(self._outgoing.read())
[287] Fix | Delete
if offset == len(view) or self._need_ssldata:
[288] Fix | Delete
break
[289] Fix | Delete
return (ssldata, offset)
[290] Fix | Delete
[291] Fix | Delete
[292] Fix | Delete
class _SSLProtocolTransport(transports._FlowControlMixin,
[293] Fix | Delete
transports.Transport):
[294] Fix | Delete
[295] Fix | Delete
def __init__(self, loop, ssl_protocol):
[296] Fix | Delete
self._loop = loop
[297] Fix | Delete
# SSLProtocol instance
[298] Fix | Delete
self._ssl_protocol = ssl_protocol
[299] Fix | Delete
self._closed = False
[300] Fix | Delete
[301] Fix | Delete
def get_extra_info(self, name, default=None):
[302] Fix | Delete
"""Get optional transport information."""
[303] Fix | Delete
return self._ssl_protocol._get_extra_info(name, default)
[304] Fix | Delete
[305] Fix | Delete
def set_protocol(self, protocol):
[306] Fix | Delete
self._ssl_protocol._app_protocol = protocol
[307] Fix | Delete
[308] Fix | Delete
def get_protocol(self):
[309] Fix | Delete
return self._ssl_protocol._app_protocol
[310] Fix | Delete
[311] Fix | Delete
def is_closing(self):
[312] Fix | Delete
return self._closed
[313] Fix | Delete
[314] Fix | Delete
def close(self):
[315] Fix | Delete
"""Close the transport.
[316] Fix | Delete
[317] Fix | Delete
Buffered data will be flushed asynchronously. No more data
[318] Fix | Delete
will be received. After all buffered data is flushed, the
[319] Fix | Delete
protocol's connection_lost() method will (eventually) called
[320] Fix | Delete
with None as its argument.
[321] Fix | Delete
"""
[322] Fix | Delete
self._closed = True
[323] Fix | Delete
self._ssl_protocol._start_shutdown()
[324] Fix | Delete
[325] Fix | Delete
# On Python 3.3 and older, objects with a destructor part of a reference
[326] Fix | Delete
# cycle are never destroyed. It's not more the case on Python 3.4 thanks
[327] Fix | Delete
# to the PEP 442.
[328] Fix | Delete
if compat.PY34:
[329] Fix | Delete
def __del__(self):
[330] Fix | Delete
if not self._closed:
[331] Fix | Delete
warnings.warn("unclosed transport %r" % self, ResourceWarning,
[332] Fix | Delete
source=self)
[333] Fix | Delete
self.close()
[334] Fix | Delete
[335] Fix | Delete
def pause_reading(self):
[336] Fix | Delete
"""Pause the receiving end.
[337] Fix | Delete
[338] Fix | Delete
No data will be passed to the protocol's data_received()
[339] Fix | Delete
method until resume_reading() is called.
[340] Fix | Delete
"""
[341] Fix | Delete
self._ssl_protocol._transport.pause_reading()
[342] Fix | Delete
[343] Fix | Delete
def resume_reading(self):
[344] Fix | Delete
"""Resume the receiving end.
[345] Fix | Delete
[346] Fix | Delete
Data received will once again be passed to the protocol's
[347] Fix | Delete
data_received() method.
[348] Fix | Delete
"""
[349] Fix | Delete
self._ssl_protocol._transport.resume_reading()
[350] Fix | Delete
[351] Fix | Delete
def set_write_buffer_limits(self, high=None, low=None):
[352] Fix | Delete
"""Set the high- and low-water limits for write flow control.
[353] Fix | Delete
[354] Fix | Delete
These two values control when to call the protocol's
[355] Fix | Delete
pause_writing() and resume_writing() methods. If specified,
[356] Fix | Delete
the low-water limit must be less than or equal to the
[357] Fix | Delete
high-water limit. Neither value can be negative.
[358] Fix | Delete
[359] Fix | Delete
The defaults are implementation-specific. If only the
[360] Fix | Delete
high-water limit is given, the low-water limit defaults to an
[361] Fix | Delete
implementation-specific value less than or equal to the
[362] Fix | Delete
high-water limit. Setting high to zero forces low to zero as
[363] Fix | Delete
well, and causes pause_writing() to be called whenever the
[364] Fix | Delete
buffer becomes non-empty. Setting low to zero causes
[365] Fix | Delete
resume_writing() to be called only once the buffer is empty.
[366] Fix | Delete
Use of zero for either limit is generally sub-optimal as it
[367] Fix | Delete
reduces opportunities for doing I/O and computation
[368] Fix | Delete
concurrently.
[369] Fix | Delete
"""
[370] Fix | Delete
self._ssl_protocol._transport.set_write_buffer_limits(high, low)
[371] Fix | Delete
[372] Fix | Delete
def get_write_buffer_size(self):
[373] Fix | Delete
"""Return the current size of the write buffer."""
[374] Fix | Delete
return self._ssl_protocol._transport.get_write_buffer_size()
[375] Fix | Delete
[376] Fix | Delete
def write(self, data):
[377] Fix | Delete
"""Write some data bytes to the transport.
[378] Fix | Delete
[379] Fix | Delete
This does not block; it buffers the data and arranges for it
[380] Fix | Delete
to be sent out asynchronously.
[381] Fix | Delete
"""
[382] Fix | Delete
if not isinstance(data, (bytes, bytearray, memoryview)):
[383] Fix | Delete
raise TypeError("data: expecting a bytes-like instance, got {!r}"
[384] Fix | Delete
.format(type(data).__name__))
[385] Fix | Delete
if not data:
[386] Fix | Delete
return
[387] Fix | Delete
self._ssl_protocol._write_appdata(data)
[388] Fix | Delete
[389] Fix | Delete
def can_write_eof(self):
[390] Fix | Delete
"""Return True if this transport supports write_eof(), False if not."""
[391] Fix | Delete
return False
[392] Fix | Delete
[393] Fix | Delete
def abort(self):
[394] Fix | Delete
"""Close the transport immediately.
[395] Fix | Delete
[396] Fix | Delete
Buffered data will be lost. No more data will be received.
[397] Fix | Delete
The protocol's connection_lost() method will (eventually) be
[398] Fix | Delete
called with None as its argument.
[399] Fix | Delete
"""
[400] Fix | Delete
self._ssl_protocol._abort()
[401] Fix | Delete
[402] Fix | Delete
[403] Fix | Delete
class SSLProtocol(protocols.Protocol):
[404] Fix | Delete
"""SSL protocol.
[405] Fix | Delete
[406] Fix | Delete
Implementation of SSL on top of a socket using incoming and outgoing
[407] Fix | Delete
buffers which are ssl.MemoryBIO objects.
[408] Fix | Delete
"""
[409] Fix | Delete
[410] Fix | Delete
def __init__(self, loop, app_protocol, sslcontext, waiter,
[411] Fix | Delete
server_side=False, server_hostname=None,
[412] Fix | Delete
call_connection_made=True):
[413] Fix | Delete
if ssl is None:
[414] Fix | Delete
raise RuntimeError('stdlib ssl module not available')
[415] Fix | Delete
[416] Fix | Delete
if not sslcontext:
[417] Fix | Delete
sslcontext = _create_transport_context(server_side, server_hostname)
[418] Fix | Delete
[419] Fix | Delete
self._server_side = server_side
[420] Fix | Delete
if server_hostname and not server_side:
[421] Fix | Delete
self._server_hostname = server_hostname
[422] Fix | Delete
else:
[423] Fix | Delete
self._server_hostname = None
[424] Fix | Delete
self._sslcontext = sslcontext
[425] Fix | Delete
# SSL-specific extra info. More info are set when the handshake
[426] Fix | Delete
# completes.
[427] Fix | Delete
self._extra = dict(sslcontext=sslcontext)
[428] Fix | Delete
[429] Fix | Delete
# App data write buffering
[430] Fix | Delete
self._write_backlog = collections.deque()
[431] Fix | Delete
self._write_buffer_size = 0
[432] Fix | Delete
[433] Fix | Delete
self._waiter = waiter
[434] Fix | Delete
self._loop = loop
[435] Fix | Delete
self._app_protocol = app_protocol
[436] Fix | Delete
self._app_transport = _SSLProtocolTransport(self._loop, self)
[437] Fix | Delete
# _SSLPipe instance (None until the connection is made)
[438] Fix | Delete
self._sslpipe = None
[439] Fix | Delete
self._session_established = False
[440] Fix | Delete
self._in_handshake = False
[441] Fix | Delete
self._in_shutdown = False
[442] Fix | Delete
# transport, ex: SelectorSocketTransport
[443] Fix | Delete
self._transport = None
[444] Fix | Delete
self._call_connection_made = call_connection_made
[445] Fix | Delete
[446] Fix | Delete
def _wakeup_waiter(self, exc=None):
[447] Fix | Delete
if self._waiter is None:
[448] Fix | Delete
return
[449] Fix | Delete
if not self._waiter.cancelled():
[450] Fix | Delete
if exc is not None:
[451] Fix | Delete
self._waiter.set_exception(exc)
[452] Fix | Delete
else:
[453] Fix | Delete
self._waiter.set_result(None)
[454] Fix | Delete
self._waiter = None
[455] Fix | Delete
[456] Fix | Delete
def connection_made(self, transport):
[457] Fix | Delete
"""Called when the low-level connection is made.
[458] Fix | Delete
[459] Fix | Delete
Start the SSL handshake.
[460] Fix | Delete
"""
[461] Fix | Delete
self._transport = transport
[462] Fix | Delete
self._sslpipe = _SSLPipe(self._sslcontext,
[463] Fix | Delete
self._server_side,
[464] Fix | Delete
self._server_hostname)
[465] Fix | Delete
self._start_handshake()
[466] Fix | Delete
[467] Fix | Delete
def connection_lost(self, exc):
[468] Fix | Delete
"""Called when the low-level connection is lost or closed.
[469] Fix | Delete
[470] Fix | Delete
The argument is an exception object or None (the latter
[471] Fix | Delete
meaning a regular EOF is received or the connection was
[472] Fix | Delete
aborted or closed).
[473] Fix | Delete
"""
[474] Fix | Delete
if self._session_established:
[475] Fix | Delete
self._session_established = False
[476] Fix | Delete
self._loop.call_soon(self._app_protocol.connection_lost, exc)
[477] Fix | Delete
self._transport = None
[478] Fix | Delete
self._app_transport = None
[479] Fix | Delete
self._wakeup_waiter(exc)
[480] Fix | Delete
[481] Fix | Delete
def pause_writing(self):
[482] Fix | Delete
"""Called when the low-level transport's buffer goes over
[483] Fix | Delete
the high-water mark.
[484] Fix | Delete
"""
[485] Fix | Delete
self._app_protocol.pause_writing()
[486] Fix | Delete
[487] Fix | Delete
def resume_writing(self):
[488] Fix | Delete
"""Called when the low-level transport's buffer drains below
[489] Fix | Delete
the low-water mark.
[490] Fix | Delete
"""
[491] Fix | Delete
self._app_protocol.resume_writing()
[492] Fix | Delete
[493] Fix | Delete
def data_received(self, data):
[494] Fix | Delete
"""Called when some SSL data is received.
[495] Fix | Delete
[496] Fix | Delete
The argument is a bytes object.
[497] Fix | Delete
"""
[498] Fix | Delete
if self._sslpipe is None:
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function