MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / SSLContext

Class SSLContext

tools/python-3.11.9-amd64/Lib/ssl.py:484–742  ·  view source on GitHub ↗

An SSLContext holds various SSL-related configuration options and data, such as certificates and possibly a private key.

Source from the content-addressed store, hash-verified

482
483
484class SSLContext(_SSLContext):
485 """An SSLContext holds various SSL-related configuration options and
486 data, such as certificates and possibly a private key."""
487 _windows_cert_stores = ("CA", "ROOT")
488
489 sslsocket_class = None # SSLSocket is assigned later.
490 sslobject_class = None # SSLObject is assigned later.
491
492 def __new__(cls, protocol=None, *args, **kwargs):
493 if protocol is None:
494 warnings.warn(
495 "ssl.SSLContext() without protocol argument is deprecated.",
496 category=DeprecationWarning,
497 stacklevel=2
498 )
499 protocol = PROTOCOL_TLS
500 self = _SSLContext.__new__(cls, protocol)
501 return self
502
503 def _encode_hostname(self, hostname):
504 if hostname is None:
505 return None
506 elif isinstance(hostname, str):
507 return hostname.encode('idna').decode('ascii')
508 else:
509 return hostname.decode('ascii')
510
511 def wrap_socket(self, sock, server_side=False,
512 do_handshake_on_connect=True,
513 suppress_ragged_eofs=True,
514 server_hostname=None, session=None):
515 # SSLSocket class handles server_hostname encoding before it calls
516 # ctx._wrap_socket()
517 return self.sslsocket_class._create(
518 sock=sock,
519 server_side=server_side,
520 do_handshake_on_connect=do_handshake_on_connect,
521 suppress_ragged_eofs=suppress_ragged_eofs,
522 server_hostname=server_hostname,
523 context=self,
524 session=session
525 )
526
527 def wrap_bio(self, incoming, outgoing, server_side=False,
528 server_hostname=None, session=None):
529 # Need to encode server_hostname here because _wrap_bio() can only
530 # handle ASCII str.
531 return self.sslobject_class._create(
532 incoming, outgoing, server_side=server_side,
533 server_hostname=self._encode_hostname(server_hostname),
534 session=session, context=self,
535 )
536
537 def set_npn_protocols(self, npn_protocols):
538 warnings.warn(
539 "ssl NPN is deprecated, use ALPN instead",
540 DeprecationWarning,
541 stacklevel=2

Callers 3

create_default_contextFunction · 0.70
wrap_socketFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected