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

Method _create

tools/python-3.11.9-amd64/Lib/ssl.py:1019–1111  ·  view source on GitHub ↗
(cls, sock, server_side=False, do_handshake_on_connect=True,
                suppress_ragged_eofs=True, server_hostname=None,
                context=None, session=None)

Source from the content-addressed store, hash-verified

1017
1018 @classmethod
1019 def _create(cls, sock, server_side=False, do_handshake_on_connect=True,
1020 suppress_ragged_eofs=True, server_hostname=None,
1021 context=None, session=None):
1022 if sock.getsockopt(SOL_SOCKET, SO_TYPE) != SOCK_STREAM:
1023 raise NotImplementedError("only stream sockets are supported")
1024 if server_side:
1025 if server_hostname:
1026 raise ValueError("server_hostname can only be specified "
1027 "in client mode")
1028 if session is not None:
1029 raise ValueError("session can only be specified in "
1030 "client mode")
1031 if context.check_hostname and not server_hostname:
1032 raise ValueError("check_hostname requires server_hostname")
1033
1034 sock_timeout = sock.gettimeout()
1035 kwargs = dict(
1036 family=sock.family, type=sock.type, proto=sock.proto,
1037 fileno=sock.fileno()
1038 )
1039 self = cls.__new__(cls, **kwargs)
1040 super(SSLSocket, self).__init__(**kwargs)
1041 sock.detach()
1042 # Now SSLSocket is responsible for closing the file descriptor.
1043 try:
1044 self._context = context
1045 self._session = session
1046 self._closed = False
1047 self._sslobj = None
1048 self.server_side = server_side
1049 self.server_hostname = context._encode_hostname(server_hostname)
1050 self.do_handshake_on_connect = do_handshake_on_connect
1051 self.suppress_ragged_eofs = suppress_ragged_eofs
1052
1053 # See if we are connected
1054 try:
1055 self.getpeername()
1056 except OSError as e:
1057 if e.errno != errno.ENOTCONN:
1058 raise
1059 connected = False
1060 blocking = self.getblocking()
1061 self.setblocking(False)
1062 try:
1063 # We are not connected so this is not supposed to block, but
1064 # testing revealed otherwise on macOS and Windows so we do
1065 # the non-blocking dance regardless. Our raise when any data
1066 # is found means consuming the data is harmless.
1067 notconn_pre_handshake_data = self.recv(1)
1068 except OSError as e:
1069 # EINVAL occurs for recv(1) on non-connected on unix sockets.
1070 if e.errno not in (errno.ENOTCONN, errno.EINVAL):
1071 raise
1072 notconn_pre_handshake_data = b''
1073 self.setblocking(blocking)
1074 if notconn_pre_handshake_data:
1075 # This prevents pending data sent to the socket before it was
1076 # closed from escaping to the caller who could otherwise

Callers

nothing calls this directly

Calls 14

recvMethod · 0.95
do_handshakeMethod · 0.95
_encode_hostnameMethod · 0.80
getpeernameMethod · 0.80
setblockingMethod · 0.80
SSLErrorClass · 0.50
getsockoptMethod · 0.45
gettimeoutMethod · 0.45
filenoMethod · 0.45
__new__Method · 0.45
__init__Method · 0.45
detachMethod · 0.45

Tested by

no test coverage detected