MCPcopy
hub / github.com/urllib3/urllib3 / connection_from_url

Function connection_from_url

src/urllib3/connectionpool.py:1121–1147  ·  view source on GitHub ↗

Given a url, return an :class:`.ConnectionPool` instance of its host. This is a shortcut for not having to parse out the scheme, host, and port of the url before creating an :class:`.ConnectionPool` instance. :param url: Absolute URL string that must include the scheme. Po

(url: str, **kw: typing.Any)

Source from the content-addressed store, hash-verified

1119
1120
1121def connection_from_url(url: str, **kw: typing.Any) -> HTTPConnectionPool:
1122 """
1123 Given a url, return an :class:`.ConnectionPool` instance of its host.
1124
1125 This is a shortcut for not having to parse out the scheme, host, and port
1126 of the url before creating an :class:`.ConnectionPool` instance.
1127
1128 :param url:
1129 Absolute URL string that must include the scheme. Port is optional.
1130
1131 :param \\**kw:
1132 Passes additional parameters to the constructor of the appropriate
1133 :class:`.ConnectionPool`. Useful for specifying things like
1134 timeout, maxsize, headers, etc.
1135
1136 Example::
1137
1138 >>> conn = connection_from_url('http://google.com/')
1139 >>> r = conn.request('GET', '/')
1140 """
1141 scheme, _, host, port, *_ = parse_url(url)
1142 scheme = scheme or "http"
1143 port = port or port_by_scheme.get(scheme, 80)
1144 if scheme == "https":
1145 return HTTPSConnectionPool(host, port=port, **kw) # type: ignore[arg-type]
1146 else:
1147 return HTTPConnectionPool(host, port=port, **kw) # type: ignore[arg-type]
1148
1149
1150@typing.overload

Callers 11

test_same_hostMethod · 0.90
test_not_same_hostMethod · 0.90
test_assert_same_hostMethod · 0.90
test_pool_closeMethod · 0.90
test_pool_close_twiceMethod · 0.90
test_contextmanagerMethod · 0.90
test_url_from_poolMethod · 0.90
test_same_urlMethod · 0.90
test_oldapiMethod · 0.90

Calls 4

parse_urlFunction · 0.85
HTTPSConnectionPoolClass · 0.85
HTTPConnectionPoolClass · 0.85
getMethod · 0.80

Tested by 11

test_same_hostMethod · 0.72
test_not_same_hostMethod · 0.72
test_assert_same_hostMethod · 0.72
test_pool_closeMethod · 0.72
test_pool_close_twiceMethod · 0.72
test_contextmanagerMethod · 0.72
test_url_from_poolMethod · 0.72
test_same_urlMethod · 0.72
test_oldapiMethod · 0.72