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

Method create_connection

Lib/asyncio/base_events.py:1065–1213  ·  view source on GitHub ↗

Connect to a TCP server. Create a streaming transport connection to a given internet host and port: socket family AF_INET or socket.AF_INET6 depending on host (or family if specified), socket type SOCK_STREAM. protocol_factory must be a callable returning a protocol

(
            self, protocol_factory, host=None, port=None,
            *, ssl=None, family=0,
            proto=0, flags=0, sock=None,
            local_addr=None, server_hostname=None,
            ssl_handshake_timeout=None,
            ssl_shutdown_timeout=None,
            happy_eyeballs_delay=None, interleave=None,
            all_errors=False)

Source from the content-addressed store, hash-verified

1063 exceptions = my_exceptions = None
1064
1065 async def create_connection(
1066 self, protocol_factory, host=None, port=None,
1067 *, ssl=None, family=0,
1068 proto=0, flags=0, sock=None,
1069 local_addr=None, server_hostname=None,
1070 ssl_handshake_timeout=None,
1071 ssl_shutdown_timeout=None,
1072 happy_eyeballs_delay=None, interleave=None,
1073 all_errors=False):
1074 """Connect to a TCP server.
1075
1076 Create a streaming transport connection to a given internet host and
1077 port: socket family AF_INET or socket.AF_INET6 depending on host (or
1078 family if specified), socket type SOCK_STREAM. protocol_factory must be
1079 a callable returning a protocol instance.
1080
1081 This method is a coroutine which will try to establish the connection
1082 in the background. When successful, the coroutine returns a
1083 (transport, protocol) pair.
1084 """
1085 if server_hostname is not None and not ssl:
1086 raise ValueError('server_hostname is only meaningful with ssl')
1087
1088 if server_hostname is None and ssl:
1089 # Use host as default for server_hostname. It is an error
1090 # if host is empty or not set, e.g. when an
1091 # already-connected socket was passed or when only a port
1092 # is given. To avoid this error, you can pass
1093 # server_hostname='' -- this will bypass the hostname
1094 # check. (This also means that if host is a numeric
1095 # IP/IPv6 address, we will attempt to verify that exact
1096 # address; this will probably fail, but it is possible to
1097 # create a certificate for a specific IP address, so we
1098 # don't judge it here.)
1099 if not host:
1100 raise ValueError('You must set server_hostname '
1101 'when using ssl without a host')
1102 server_hostname = host
1103
1104 if ssl_handshake_timeout is not None and not ssl:
1105 raise ValueError(
1106 'ssl_handshake_timeout is only meaningful with ssl')
1107
1108 if ssl_shutdown_timeout is not None and not ssl:
1109 raise ValueError(
1110 'ssl_shutdown_timeout is only meaningful with ssl')
1111
1112 if sock is not None:
1113 _check_ssl_socket(sock)
1114
1115 if happy_eyeballs_delay is not None and interleave is None:
1116 # If using happy eyeballs, default to interleave addresses by family
1117 interleave = 1
1118
1119 if host is not None or port is not None:
1120 if sock is not None:
1121 raise ValueError(
1122 'host/port and sock can not be specified at the same time')

Callers

nothing calls this directly

Calls 11

_ensure_resolvedMethod · 0.95
_connect_sockMethod · 0.95
_check_ssl_socketFunction · 0.85
_interleave_addrinfosFunction · 0.85
strFunction · 0.85
TimeoutErrorClass · 0.85
formatMethod · 0.45
joinMethod · 0.45
get_extra_infoMethod · 0.45
debugMethod · 0.45

Tested by

no test coverage detected