urlparse(url)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kenneth Reitz · committed by Kenneth Reitz · parent a197309 · Browse files · 2 files·+21 added−17 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+21 added−17 removed
- other:+21 added−17 removed
Provenance
- Commit
ca0d08e- Tree
0aa9363- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
a197309
2 files changed+21 added−17 removed
modified:requests/adapters.py+18 added-2 removed
10 unmodified lines11 import os12 import socket13 14 from .models import Response15+from .auth import HTTPProxyAuth16 from .packages.urllib3.poolmanager import PoolManager17 from .hooks import dispatch_hook18+from .compat import urlparse19 from .utils import DEFAULT_CA_BUNDLE_PATH, get_encoding_from_headers20 from .structures import CaseInsensitiveDict21 from .packages.urllib3.exceptions import MaxRetryError22 from .packages.urllib3.exceptions import TimeoutError97 unmodified lines120 # Run the Response hook.121 response = dispatch_hook('response', req.hooks, response)122 return response123 124+ def get_connection(self, url, proxies=None):125+ proxies = proxies or {}126+ proxy = proxies.get(urlparse(url).scheme)127 128+ if proxy:129+ conn = poolmanager.proxy_from_url(proxy)130+ else:131+ conn = self.poolmanager.connection_from_url(url)132+133+ return conn134+ # no_proxy = filter(lambda x: x.strip(), self.proxies.get('no', '').split(','))135+136+137+138 def close(self):139 """Dispose of any internal state.140 141 Currently, this just closes the PoolManager, which closes pooled142 connections.143 """144 self.poolmanager.clear()145 131- def send(self, request, prefetch=True, timeout=None, verify=True, cert=None):146+ def send(self, request, prefetch=True, timeout=None, verify=True, cert=None, proxies=None):147 """Sends PreparedRequest object. Returns Response object."""148 134- conn = self.poolmanager.connection_from_url(request.url)149+ conn = self.get_connection(request.url, proxies)150+151 self.cert_verify(conn, request.url, verify, cert)152 153 try:154 # Send the request.33 unmodified linesmodified:requests/models.py+3 added-15 removed
13 unmodified lines14 import logging15 16 # from datetime import datetime17 from io import BytesIO18-from types import GeneratorType18 from .hooks import dispatch_hook, default_hooks19 from .structures import CaseInsensitiveDict20 from .status_codes import codes21 22 from .auth import HTTPBasicAuth, HTTPProxyAuth23 from .cookies import cookiejar_from_dict, extract_cookies_to_jar, get_cookie_header25-# from .packages.urllib3.exceptions import MaxRetryError, LocationParseError26-# from .packages.urllib3.exceptions import TimeoutError27-# from .packages.urllib3.exceptions import SSLError as _SSLError28-# from .packages.urllib3.exceptions import HTTPError as _HTTPError29-# from .packages.urllib3 import connectionpool, poolmanager24 from .packages.urllib3.filepost import encode_multipart_formdata31-25 from .exceptions import (26 ConnectionError, HTTPError, RequestException, Timeout, TooManyRedirects,27 URLRequired, SSLError, MissingSchema, InvalidSchema, InvalidURL)28 from .utils import (6 unmodified lines35 StringIO, is_py2, chardet, json, builtin_str, urldefrag, basestring)36 37 REDIRECT_STATI = (codes.moved, codes.found, codes.other, codes.temporary_moved)38 CONTENT_CHUNK_SIZE = 10 * 102439+ITER_CHUNK_SIZE = 10 * 102440 41 log = logging.getLogger(__name__)42 43 6 unmodified lines50 url = []51 52 p = urlsplit(self.url)53 60- # Proxies use full URLs.61- # if p.scheme in self.proxies:62- # url_base, frag = urldefrag(self.url)63- # return url_base64-65-54 path = p.path55 if not path:56 path = '/'57 237 unmodified lines295 def prepare_body(self, data, files):296 """Prepares the given HTTP body data."""297 298 # If a generator is provided, error out.311- if isinstance(data, types.GeneratorType)299+ if isinstance(data, type(_ for _ in [])):300 raise NotImplementedError('Generator bodies are not supported yet.')301 302 # Nottin' on you.303 body = None140 unmodified lines444 gen = stream_decode_response_unicode(gen, self)445 446 return gen447 460- def iter_lines(self, chunk_size=10 * 1024, decode_unicode=None):448+ def iter_lines(self, chunk_size=ITER_CHUNK_SIZE, decode_unicode=None):449 """Iterates over the response data, one line at a time. This450 avoids reading the content at once into memory for large451 responses.452 """136 unmodified lines