MCPcopy Create free account
hub / github.com/EasyIME/PIME / ssl_wrap_socket

Function ssl_wrap_socket

python/python3/tornado/netutil.py:644–677  ·  view source on GitHub ↗

Returns an ``ssl.SSLSocket`` wrapping the given socket. ``ssl_options`` may be either an `ssl.SSLContext` object or a dictionary (as accepted by `ssl_options_to_context`). Additional keyword arguments are passed to ``wrap_socket`` (either the `~ssl.SSLContext` method or the `ssl` m

(
    socket: socket.socket,
    ssl_options: Union[Dict[str, Any], ssl.SSLContext],
    server_hostname: Optional[str] = None,
    server_side: Optional[bool] = None,
    **kwargs: Any
)

Source from the content-addressed store, hash-verified

642
643
644def ssl_wrap_socket(
645 socket: socket.socket,
646 ssl_options: Union[Dict[str, Any], ssl.SSLContext],
647 server_hostname: Optional[str] = None,
648 server_side: Optional[bool] = None,
649 **kwargs: Any
650) -> ssl.SSLSocket:
651 """Returns an ``ssl.SSLSocket`` wrapping the given socket.
652
653 ``ssl_options`` may be either an `ssl.SSLContext` object or a
654 dictionary (as accepted by `ssl_options_to_context`). Additional
655 keyword arguments are passed to ``wrap_socket`` (either the
656 `~ssl.SSLContext` method or the `ssl` module function as
657 appropriate).
658
659 .. versionchanged:: 6.2
660
661 Added server_side argument. Omitting this argument will
662 result in a DeprecationWarning on Python 3.10.
663 """
664 context = ssl_options_to_context(ssl_options, server_side=server_side)
665 if server_side is None:
666 server_side = False
667 if ssl.HAS_SNI:
668 # In python 3.4, wrap_socket only accepts the server_hostname
669 # argument if HAS_SNI is true.
670 # TODO: add a unittest (python added server-side SNI support in 3.4)
671 # In the meantime it can be manually tested with
672 # python3 -m tornado.httpclient https://sni.velox.ch
673 return context.wrap_socket(
674 socket, server_hostname=server_hostname, server_side=server_side, **kwargs
675 )
676 else:
677 return context.wrap_socket(socket, server_side=server_side, **kwargs)

Callers 4

start_tlsMethod · 0.90
_handle_connectMethod · 0.90
_handle_connectionMethod · 0.90
_make_server_iostreamMethod · 0.90

Calls 1

ssl_options_to_contextFunction · 0.85

Tested by 1

_make_server_iostreamMethod · 0.72