mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
urlparse(url)
This commit is contained in:
+18
-2
@@ -12,8 +12,10 @@ import os
|
||||
import socket
|
||||
|
||||
from .models import Response
|
||||
from .auth import HTTPProxyAuth
|
||||
from .packages.urllib3.poolmanager import PoolManager
|
||||
from .hooks import dispatch_hook
|
||||
from .compat import urlparse
|
||||
from .utils import DEFAULT_CA_BUNDLE_PATH, get_encoding_from_headers
|
||||
from .structures import CaseInsensitiveDict
|
||||
from .packages.urllib3.exceptions import MaxRetryError
|
||||
@@ -119,6 +121,19 @@ class HTTPAdapter(BaseAdapter):
|
||||
response = dispatch_hook('response', req.hooks, response)
|
||||
return response
|
||||
|
||||
def get_connection(self, url, proxies=None):
|
||||
proxies = proxies or {}
|
||||
proxy = proxies.get(urlparse(url).scheme)
|
||||
|
||||
if proxy:
|
||||
conn = poolmanager.proxy_from_url(proxy)
|
||||
else:
|
||||
conn = self.poolmanager.connection_from_url(url)
|
||||
|
||||
return conn
|
||||
# no_proxy = filter(lambda x: x.strip(), self.proxies.get('no', '').split(','))
|
||||
|
||||
|
||||
|
||||
def close(self):
|
||||
"""Dispose of any internal state.
|
||||
@@ -128,10 +143,11 @@ class HTTPAdapter(BaseAdapter):
|
||||
"""
|
||||
self.poolmanager.clear()
|
||||
|
||||
def send(self, request, prefetch=True, timeout=None, verify=True, cert=None):
|
||||
def send(self, request, prefetch=True, timeout=None, verify=True, cert=None, proxies=None):
|
||||
"""Sends PreparedRequest object. Returns Response object."""
|
||||
|
||||
conn = self.poolmanager.connection_from_url(request.url)
|
||||
conn = self.get_connection(request.url, proxies)
|
||||
|
||||
self.cert_verify(conn, request.url, verify, cert)
|
||||
|
||||
try:
|
||||
|
||||
+3
-15
@@ -15,20 +15,13 @@ import logging
|
||||
|
||||
# from datetime import datetime
|
||||
from io import BytesIO
|
||||
from types import GeneratorType
|
||||
from .hooks import dispatch_hook, default_hooks
|
||||
from .structures import CaseInsensitiveDict
|
||||
from .status_codes import codes
|
||||
|
||||
from .auth import HTTPBasicAuth, HTTPProxyAuth
|
||||
from .cookies import cookiejar_from_dict, extract_cookies_to_jar, get_cookie_header
|
||||
# from .packages.urllib3.exceptions import MaxRetryError, LocationParseError
|
||||
# from .packages.urllib3.exceptions import TimeoutError
|
||||
# from .packages.urllib3.exceptions import SSLError as _SSLError
|
||||
# from .packages.urllib3.exceptions import HTTPError as _HTTPError
|
||||
# from .packages.urllib3 import connectionpool, poolmanager
|
||||
from .packages.urllib3.filepost import encode_multipart_formdata
|
||||
|
||||
from .exceptions import (
|
||||
ConnectionError, HTTPError, RequestException, Timeout, TooManyRedirects,
|
||||
URLRequired, SSLError, MissingSchema, InvalidSchema, InvalidURL)
|
||||
@@ -43,6 +36,7 @@ from .compat import (
|
||||
|
||||
REDIRECT_STATI = (codes.moved, codes.found, codes.other, codes.temporary_moved)
|
||||
CONTENT_CHUNK_SIZE = 10 * 1024
|
||||
ITER_CHUNK_SIZE = 10 * 1024
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -57,12 +51,6 @@ class RequestEncodingMixin(object):
|
||||
|
||||
p = urlsplit(self.url)
|
||||
|
||||
# Proxies use full URLs.
|
||||
# if p.scheme in self.proxies:
|
||||
# url_base, frag = urldefrag(self.url)
|
||||
# return url_base
|
||||
|
||||
|
||||
path = p.path
|
||||
if not path:
|
||||
path = '/'
|
||||
@@ -308,7 +296,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
|
||||
"""Prepares the given HTTP body data."""
|
||||
|
||||
# If a generator is provided, error out.
|
||||
if isinstance(data, types.GeneratorType)
|
||||
if isinstance(data, type(_ for _ in [])):
|
||||
raise NotImplementedError('Generator bodies are not supported yet.')
|
||||
|
||||
# Nottin' on you.
|
||||
@@ -457,7 +445,7 @@ class Response(object):
|
||||
|
||||
return gen
|
||||
|
||||
def iter_lines(self, chunk_size=10 * 1024, decode_unicode=None):
|
||||
def iter_lines(self, chunk_size=ITER_CHUNK_SIZE, decode_unicode=None):
|
||||
"""Iterates over the response data, one line at a time. This
|
||||
avoids reading the content at once into memory for large
|
||||
responses.
|
||||
|
||||
Reference in New Issue
Block a user