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)
| 1119 | |
| 1120 | |
| 1121 | def 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 |