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

Method start_tls

Lib/asyncio/base_events.py:1321–1378  ·  view source on GitHub ↗

Upgrade transport to TLS. Return a new transport that *protocol* should start using immediately.

(self, transport, protocol, sslcontext, *,
                        server_side=False,
                        server_hostname=None,
                        ssl_handshake_timeout=None,
                        ssl_shutdown_timeout=None)

Source from the content-addressed store, hash-verified

1319 await proto.restore()
1320
1321 async def start_tls(self, transport, protocol, sslcontext, *,
1322 server_side=False,
1323 server_hostname=None,
1324 ssl_handshake_timeout=None,
1325 ssl_shutdown_timeout=None):
1326 """Upgrade transport to TLS.
1327
1328 Return a new transport that *protocol* should start using
1329 immediately.
1330 """
1331 if ssl is None:
1332 raise RuntimeError('Python ssl module is not available')
1333
1334 if not isinstance(sslcontext, ssl.SSLContext):
1335 raise TypeError(
1336 f'sslcontext is expected to be an instance of ssl.SSLContext, '
1337 f'got {sslcontext!r}')
1338
1339 if not getattr(transport, '_start_tls_compatible', False):
1340 raise TypeError(
1341 f'transport {transport!r} is not supported by start_tls()')
1342
1343 waiter = self.create_future()
1344 ssl_protocol = sslproto.SSLProtocol(
1345 self, protocol, sslcontext, waiter,
1346 server_side, server_hostname,
1347 ssl_handshake_timeout=ssl_handshake_timeout,
1348 ssl_shutdown_timeout=ssl_shutdown_timeout,
1349 call_connection_made=False)
1350
1351 # Pause early so that "ssl_protocol.data_received()" doesn't
1352 # have a chance to get called before "ssl_protocol.connection_made()".
1353 transport.pause_reading()
1354
1355 # gh-142352: move buffered StreamReader data to SSLProtocol
1356 if server_side:
1357 from .streams import StreamReaderProtocol
1358 if isinstance(protocol, StreamReaderProtocol):
1359 stream_reader = getattr(protocol, '_stream_reader', None)
1360 if stream_reader is not None:
1361 buffer = stream_reader._buffer
1362 if buffer:
1363 ssl_protocol._incoming.write(buffer)
1364 buffer.clear()
1365
1366 transport.set_protocol(ssl_protocol)
1367 conmade_cb = self.call_soon(ssl_protocol.connection_made, transport)
1368 resume_cb = self.call_soon(transport.resume_reading)
1369
1370 try:
1371 await waiter
1372 except BaseException:
1373 transport.close()
1374 conmade_cb.cancel()
1375 resume_cb.cancel()
1376 raise
1377
1378 return ssl_protocol._app_transport

Callers

nothing calls this directly

Calls 8

create_futureMethod · 0.95
call_soonMethod · 0.95
pause_readingMethod · 0.45
writeMethod · 0.45
clearMethod · 0.45
set_protocolMethod · 0.45
closeMethod · 0.45
cancelMethod · 0.45

Tested by

no test coverage detected