MCPcopy Index your code
hub / github.com/websocket-client/websocket-client / connect

Function connect

websocket/_http.py:126–160  ·  view source on GitHub ↗
(url: str, options, proxy, socket)

Source from the content-addressed store, hash-verified

124
125
126def connect(url: str, options, proxy, socket):
127 # Use _start_proxied_socket() only for socks4 or socks5 proxy
128 # Use _tunnel() for http proxy
129 # TODO: Use python-socks for http protocol also, to standardize flow
130 if proxy.proxy_host and not socket and proxy.proxy_protocol != "http":
131 return _start_proxied_socket(url, options, proxy)
132
133 hostname, port_from_url, resource, is_secure = parse_url(url)
134
135 if socket:
136 return socket, (hostname, port_from_url, resource)
137
138 addrinfo_list, need_tunnel, auth = _get_addrinfo_list(
139 hostname, port_from_url, is_secure, proxy
140 )
141 if not addrinfo_list:
142 raise WebSocketException(f"Host not found.: {hostname}:{port_from_url}")
143
144 sock = None
145 try:
146 sock = _open_socket(addrinfo_list, options.sockopt, options.timeout)
147 if need_tunnel:
148 sock = _tunnel(sock, hostname, port_from_url, auth)
149
150 if is_secure:
151 if HAVE_SSL:
152 sock = _ssl_socket(sock, options.sslopt, hostname)
153 else:
154 raise WebSocketException("SSL not available.")
155
156 return sock, (hostname, port_from_url, resource)
157 except:
158 if sock:
159 sock.close()
160 raise
161
162
163def _get_addrinfo_list(hostname, port: int, is_secure: bool, proxy) -> tuple:

Callers 3

test_connectMethod · 0.90
test_proxy_connectMethod · 0.90
connectMethod · 0.85

Calls 8

_start_proxied_socketFunction · 0.85
parse_urlFunction · 0.85
_get_addrinfo_listFunction · 0.85
WebSocketExceptionClass · 0.85
_open_socketFunction · 0.85
_tunnelFunction · 0.85
_ssl_socketFunction · 0.85
closeMethod · 0.45

Tested by 2

test_connectMethod · 0.72
test_proxy_connectMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…