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

Method _create

Lib/ssl.py:1007–1099  ·  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

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

Callers

nothing calls this directly

Calls 14

recvMethod · 0.95
do_handshakeMethod · 0.95
superClass · 0.85
_encode_hostnameMethod · 0.80
getsockoptMethod · 0.45
gettimeoutMethod · 0.45
filenoMethod · 0.45
__new__Method · 0.45
__init__Method · 0.45
detachMethod · 0.45
getpeernameMethod · 0.45
setblockingMethod · 0.45

Tested by

no test coverage detected