__init__.py000064400000006767147205317600006702 0ustar00# -*- coding: utf-8 -*- # __ # /__) _ _ _ _ _/ _ # / ( (- (/ (/ (- _) / _) # / """ Requests HTTP Library ~~~~~~~~~~~~~~~~~~~~~ Requests is an HTTP library, written in Python, for human beings. Basic GET usage: >>> import requests >>> r = requests.get('https://www.python.org') >>> r.status_code 200 >>> 'Python is a programming language' in r.content True ... or POST: >>> payload = dict(key1='value1', key2='value2') >>> r = requests.post('http://httpbin.org/post', data=payload) >>> print(r.text) { ... "form": { "key2": "value2", "key1": "value1" }, ... } The other HTTP methods are supported - see `requests.api`. Full documentation is at . :copyright: (c) 2017 by Kenneth Reitz. :license: Apache 2.0, see LICENSE for more details. """ from pip._vendor import urllib3 from pip._vendor import chardet import warnings from .exceptions import RequestsDependencyWarning def check_compatibility(urllib3_version, chardet_version): urllib3_version = urllib3_version.split('.') assert urllib3_version != ['dev'] # Verify urllib3 isn't installed from git. # Sometimes, urllib3 only reports its version as 16.1. if len(urllib3_version) == 2: urllib3_version.append('0') # Check urllib3 for compatibility. major, minor, patch = urllib3_version # noqa: F811 major, minor, patch = int(major), int(minor), int(patch) # urllib3 >= 1.21.1, <= 1.22 assert major == 1 assert minor >= 21 assert minor <= 22 # Check chardet for compatibility. major, minor, patch = chardet_version.split('.')[:3] major, minor, patch = int(major), int(minor), int(patch) # chardet >= 3.0.2, < 3.1.0 assert major == 3 assert minor < 1 assert patch >= 2 # Check imported dependencies for compatibility. try: check_compatibility(urllib3.__version__, chardet.__version__) except (AssertionError, ValueError): warnings.warn("urllib3 ({0}) or chardet ({1}) doesn't match a supported " "version!".format(urllib3.__version__, chardet.__version__), RequestsDependencyWarning) # Attempt to enable urllib3's SNI support, if possible # try: # from pip._vendor.urllib3.contrib import pyopenssl # pyopenssl.inject_into_urllib3() # except ImportError: # pass # urllib3's DependencyWarnings should be silenced. from pip._vendor.urllib3.exceptions import DependencyWarning warnings.simplefilter('ignore', DependencyWarning) from .__version__ import __title__, __description__, __url__, __version__ from .__version__ import __build__, __author__, __author_email__, __license__ from .__version__ import __copyright__, __cake__ from . import utils from . import packages from .models import Request, Response, PreparedRequest from .api import request, get, head, post, patch, put, delete, options from .sessions import session, Session from .status_codes import codes from .exceptions import ( RequestException, Timeout, URLRequired, TooManyRedirects, HTTPError, ConnectionError, FileModeWarning, ConnectTimeout, ReadTimeout ) # Set default logging handler to avoid "No handler found" warnings. import logging try: # Python 2.7+ from logging import NullHandler except ImportError: class NullHandler(logging.Handler): def emit(self, record): pass logging.getLogger(__name__).addHandler(NullHandler()) # FileModeWarnings go off per the default. warnings.simplefilter('default', FileModeWarning, append=True) adapters.py000064400000051030147205317600006725 0ustar00# -*- coding: utf-8 -*- """ requests.adapters ~~~~~~~~~~~~~~~~~ This module contains the transport adapters that Requests uses to define and maintain connections. """ import os.path import socket from pip._vendor.urllib3.poolmanager import PoolManager, proxy_from_url from pip._vendor.urllib3.response import HTTPResponse from pip._vendor.urllib3.util import Timeout as TimeoutSauce from pip._vendor.urllib3.util.retry import Retry from pip._vendor.urllib3.exceptions import ClosedPoolError from pip._vendor.urllib3.exceptions import ConnectTimeoutError from pip._vendor.urllib3.exceptions import HTTPError as _HTTPError from pip._vendor.urllib3.exceptions import MaxRetryError from pip._vendor.urllib3.exceptions import NewConnectionError from pip._vendor.urllib3.exceptions import ProxyError as _ProxyError from pip._vendor.urllib3.exceptions import ProtocolError from pip._vendor.urllib3.exceptions import ReadTimeoutError from pip._vendor.urllib3.exceptions import SSLError as _SSLError from pip._vendor.urllib3.exceptions import ResponseError from .models import Response from .compat import urlparse, basestring from .utils import (DEFAULT_CA_BUNDLE_PATH, get_encoding_from_headers, prepend_scheme_if_needed, get_auth_from_url, urldefragauth, select_proxy) from .structures import CaseInsensitiveDict from .cookies import extract_cookies_to_jar from .exceptions import (ConnectionError, ConnectTimeout, ReadTimeout, SSLError, ProxyError, RetryError, InvalidSchema) from .auth import _basic_auth_str try: from pip._vendor.urllib3.contrib.socks import SOCKSProxyManager except ImportError: def SOCKSProxyManager(*args, **kwargs): raise InvalidSchema("Missing dependencies for SOCKS support.") DEFAULT_POOLBLOCK = False DEFAULT_POOLSIZE = 10 DEFAULT_RETRIES = 0 DEFAULT_POOL_TIMEOUT = None class BaseAdapter(object): """The Base Transport Adapter""" def __init__(self): super(BaseAdapter, self).__init__() def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None): """Sends PreparedRequest object. Returns Response object. :param request: The :class:`PreparedRequest ` being sent. :param stream: (optional) Whether to stream the request content. :param timeout: (optional) How long to wait for the server to send data before giving up, as a float, or a :ref:`(connect timeout, read timeout) ` tuple. :type timeout: float or tuple :param verify: (optional) Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use :param cert: (optional) Any user-provided SSL certificate to be trusted. :param proxies: (optional) The proxies dictionary to apply to the request. """ raise NotImplementedError def close(self): """Cleans up adapter specific items.""" raise NotImplementedError class HTTPAdapter(BaseAdapter): """The built-in HTTP Adapter for urllib3. Provides a general-case interface for Requests sessions to contact HTTP and HTTPS urls by implementing the Transport Adapter interface. This class will usually be created by the :class:`Session ` class under the covers. :param pool_connections: The number of urllib3 connection pools to cache. :param pool_maxsize: The maximum number of connections to save in the pool. :param max_retries: The maximum number of retries each connection should attempt. Note, this applies only to failed DNS lookups, socket connections and connection timeouts, never to requests where data has made it to the server. By default, Requests does not retry failed connections. If you need granular control over the conditions under which we retry a request, import urllib3's ``Retry`` class and pass that instead. :param pool_block: Whether the connection pool should block for connections. Usage:: >>> import requests >>> s = requests.Session() >>> a = requests.adapters.HTTPAdapter(max_retries=3) >>> s.mount('http://', a) """ __attrs__ = ['max_retries', 'config', '_pool_connections', '_pool_maxsize', '_pool_block'] def __init__(self, pool_connections=DEFAULT_POOLSIZE, pool_maxsize=DEFAULT_POOLSIZE, max_retries=DEFAULT_RETRIES, pool_block=DEFAULT_POOLBLOCK): if max_retries == DEFAULT_RETRIES: self.max_retries = Retry(0, read=False) else: self.max_retries = Retry.from_int(max_retries) self.config = {} self.proxy_manager = {} super(HTTPAdapter, self).__init__() self._pool_connections = pool_connections self._pool_maxsize = pool_maxsize self._pool_block = pool_block self.init_poolmanager(pool_connections, pool_maxsize, block=pool_block) def __getstate__(self): return dict((attr, getattr(self, attr, None)) for attr in self.__attrs__) def __setstate__(self, state): # Can't handle by adding 'proxy_manager' to self.__attrs__ because # self.poolmanager uses a lambda function, which isn't pickleable. self.proxy_manager = {} self.config = {} for attr, value in state.items(): setattr(self, attr, value) self.init_poolmanager(self._pool_connections, self._pool_maxsize, block=self._pool_block) def init_poolmanager(self, connections, maxsize, block=DEFAULT_POOLBLOCK, **pool_kwargs): """Initializes a urllib3 PoolManager. This method should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter `. :param connections: The number of urllib3 connection pools to cache. :param maxsize: The maximum number of connections to save in the pool. :param block: Block when no free connections are available. :param pool_kwargs: Extra keyword arguments used to initialize the Pool Manager. """ # save these values for pickling self._pool_connections = connections self._pool_maxsize = maxsize self._pool_block = block self.poolmanager = PoolManager(num_pools=connections, maxsize=maxsize, block=block, strict=True, **pool_kwargs) def proxy_manager_for(self, proxy, **proxy_kwargs): """Return urllib3 ProxyManager for the given proxy. This method should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter `. :param proxy: The proxy to return a urllib3 ProxyManager for. :param proxy_kwargs: Extra keyword arguments used to configure the Proxy Manager. :returns: ProxyManager :rtype: urllib3.ProxyManager """ if proxy in self.proxy_manager: manager = self.proxy_manager[proxy] elif proxy.lower().startswith('socks'): username, password = get_auth_from_url(proxy) manager = self.proxy_manager[proxy] = SOCKSProxyManager( proxy, username=username, password=password, num_pools=self._pool_connections, maxsize=self._pool_maxsize, block=self._pool_block, **proxy_kwargs ) else: proxy_headers = self.proxy_headers(proxy) manager = self.proxy_manager[proxy] = proxy_from_url( proxy, proxy_headers=proxy_headers, num_pools=self._pool_connections, maxsize=self._pool_maxsize, block=self._pool_block, **proxy_kwargs) return manager def cert_verify(self, conn, url, verify, cert): """Verify a SSL certificate. This method should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter `. :param conn: The urllib3 connection object associated with the cert. :param url: The requested URL. :param verify: Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use :param cert: The SSL certificate to verify. """ if url.lower().startswith('https') and verify: cert_loc = None # Allow self-specified cert location. if verify is not True: cert_loc = verify if not cert_loc: cert_loc = DEFAULT_CA_BUNDLE_PATH if not cert_loc or not os.path.exists(cert_loc): raise IOError("Could not find a suitable TLS CA certificate bundle, " "invalid path: {0}".format(cert_loc)) conn.cert_reqs = 'CERT_REQUIRED' if not os.path.isdir(cert_loc): conn.ca_certs = cert_loc else: conn.ca_cert_dir = cert_loc else: conn.cert_reqs = 'CERT_NONE' conn.ca_certs = None conn.ca_cert_dir = None if cert: if not isinstance(cert, basestring): conn.cert_file = cert[0] conn.key_file = cert[1] else: conn.cert_file = cert conn.key_file = None if conn.cert_file and not os.path.exists(conn.cert_file): raise IOError("Could not find the TLS certificate file, " "invalid path: {0}".format(conn.cert_file)) if conn.key_file and not os.path.exists(conn.key_file): raise IOError("Could not find the TLS key file, " "invalid path: {0}".format(conn.key_file)) def build_response(self, req, resp): """Builds a :class:`Response ` object from a urllib3 response. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter ` :param req: The :class:`PreparedRequest ` used to generate the response. :param resp: The urllib3 response object. :rtype: requests.Response """ response = Response() # Fallback to None if there's no status_code, for whatever reason. response.status_code = getattr(resp, 'status', None) # Make headers case-insensitive. response.headers = CaseInsensitiveDict(getattr(resp, 'headers', {})) # Set encoding. response.encoding = get_encoding_from_headers(response.headers) response.raw = resp response.reason = response.raw.reason if isinstance(req.url, bytes): response.url = req.url.decode('utf-8') else: response.url = req.url # Add new cookies from the server. extract_cookies_to_jar(response.cookies, req, resp) # Give the Response some context. response.request = req response.connection = self return response def get_connection(self, url, proxies=None): """Returns a urllib3 connection for the given URL. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter `. :param url: The URL to connect to. :param proxies: (optional) A Requests-style dictionary of proxies used on this request. :rtype: urllib3.ConnectionPool """ proxy = select_proxy(url, proxies) if proxy: proxy = prepend_scheme_if_needed(proxy, 'http') proxy_manager = self.proxy_manager_for(proxy) conn = proxy_manager.connection_from_url(url) else: # Only scheme should be lower case parsed = urlparse(url) url = parsed.geturl() conn = self.poolmanager.connection_from_url(url) return conn def close(self): """Disposes of any internal state. Currently, this closes the PoolManager and any active ProxyManager, which closes any pooled connections. """ self.poolmanager.clear() for proxy in self.proxy_manager.values(): proxy.clear() def request_url(self, request, proxies): """Obtain the url to use when making the final request. If the message is being sent through a HTTP proxy, the full URL has to be used. Otherwise, we should only use the path portion of the URL. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter `. :param request: The :class:`PreparedRequest ` being sent. :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs. :rtype: str """ proxy = select_proxy(request.url, proxies) scheme = urlparse(request.url).scheme is_proxied_http_request = (proxy and scheme != 'https') using_socks_proxy = False if proxy: proxy_scheme = urlparse(proxy).scheme.lower() using_socks_proxy = proxy_scheme.startswith('socks') url = request.path_url if is_proxied_http_request and not using_socks_proxy: url = urldefragauth(request.url) return url def add_headers(self, request, **kwargs): """Add any headers needed by the connection. As of v2.0 this does nothing by default, but is left for overriding by users that subclass the :class:`HTTPAdapter `. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter `. :param request: The :class:`PreparedRequest ` to add headers to. :param kwargs: The keyword arguments from the call to send(). """ pass def proxy_headers(self, proxy): """Returns a dictionary of the headers to add to any request sent through a proxy. This works with urllib3 magic to ensure that they are correctly sent to the proxy, rather than in a tunnelled request if CONNECT is being used. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter `. :param proxies: The url of the proxy being used for this request. :rtype: dict """ headers = {} username, password = get_auth_from_url(proxy) if username: headers['Proxy-Authorization'] = _basic_auth_str(username, password) return headers def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None): """Sends PreparedRequest object. Returns Response object. :param request: The :class:`PreparedRequest ` being sent. :param stream: (optional) Whether to stream the request content. :param timeout: (optional) How long to wait for the server to send data before giving up, as a float, or a :ref:`(connect timeout, read timeout) ` tuple. :type timeout: float or tuple or urllib3 Timeout object :param verify: (optional) Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use :param cert: (optional) Any user-provided SSL certificate to be trusted. :param proxies: (optional) The proxies dictionary to apply to the request. :rtype: requests.Response """ conn = self.get_connection(request.url, proxies) self.cert_verify(conn, request.url, verify, cert) url = self.request_url(request, proxies) self.add_headers(request) chunked = not (request.body is None or 'Content-Length' in request.headers) if isinstance(timeout, tuple): try: connect, read = timeout timeout = TimeoutSauce(connect=connect, read=read) except ValueError as e: # this may raise a string formatting error. err = ("Invalid timeout {0}. Pass a (connect, read) " "timeout tuple, or a single float to set " "both timeouts to the same value".format(timeout)) raise ValueError(err) elif isinstance(timeout, TimeoutSauce): pass else: timeout = TimeoutSauce(connect=timeout, read=timeout) try: if not chunked: resp = conn.urlopen( method=request.method, url=url, body=request.body, headers=request.headers, redirect=False, assert_same_host=False, preload_content=False, decode_content=False, retries=self.max_retries, timeout=timeout ) # Send the request. else: if hasattr(conn, 'proxy_pool'): conn = conn.proxy_pool low_conn = conn._get_conn(timeout=DEFAULT_POOL_TIMEOUT) try: low_conn.putrequest(request.method, url, skip_accept_encoding=True) for header, value in request.headers.items(): low_conn.putheader(header, value) low_conn.endheaders() for i in request.body: low_conn.send(hex(len(i))[2:].encode('utf-8')) low_conn.send(b'\r\n') low_conn.send(i) low_conn.send(b'\r\n') low_conn.send(b'0\r\n\r\n') # Receive the response from the server try: # For Python 2.7+ versions, use buffering of HTTP # responses r = low_conn.getresponse(buffering=True) except TypeError: # For compatibility with Python 2.6 versions and back r = low_conn.getresponse() resp = HTTPResponse.from_httplib( r, pool=conn, connection=low_conn, preload_content=False, decode_content=False ) except: # If we hit any problems here, clean up the connection. # Then, reraise so that we can handle the actual exception. low_conn.close() raise except (ProtocolError, socket.error) as err: raise ConnectionError(err, request=request) except MaxRetryError as e: if isinstance(e.reason, ConnectTimeoutError): # TODO: Remove this in 3.0.0: see #2811 if not isinstance(e.reason, NewConnectionError): raise ConnectTimeout(e, request=request) if isinstance(e.reason, ResponseError): raise RetryError(e, request=request) if isinstance(e.reason, _ProxyError): raise ProxyError(e, request=request) if isinstance(e.reason, _SSLError): # This branch is for urllib3 v1.22 and later. raise SSLError(e, request=request) raise ConnectionError(e, request=request) except ClosedPoolError as e: raise ConnectionError(e, request=request) except _ProxyError as e: raise ProxyError(e) except (_SSLError, _HTTPError) as e: if isinstance(e, _SSLError): # This branch is for urllib3 versions earlier than v1.22 raise SSLError(e, request=request) elif isinstance(e, ReadTimeoutError): raise ReadTimeout(e, request=request) else: raise return self.build_response(request, resp) __pycache__/__init__.cpython-38.pyc000064400000000250147205317600013145 0ustar00U af@sdS)NrrrM/opt/nydus/tmp/pip-target-53d1vnqk/lib/python/primordial/requests/__init__.py__pycache__/adapters.cpython-38.pyc000064400000001646147205317600013223 0ustar00U af@s ddlmZGdddeZdS)) HTTPAdaptercs4eZdZdZeddfdd ZfddZZS)CustomHostnameHTTPSAdapterz2Allow for setting a custom hostname on an adapter.N)custom_hostnamereturncs||_tdSN)rsuper__init__)selfr __class__M/opt/nydus/tmp/pip-target-53d1vnqk/lib/python/primordial/requests/adapters.pyr sz#CustomHostnameHTTPSAdapter.__init__cs|j|_t||||Sr)rassert_hostnamer cert_verify)r connurlverifycertr r r r sz&CustomHostnameHTTPSAdapter.cert_verify)__name__ __module__ __qualname____doc__strrr __classcell__r r r r rsrN)Zrequests.adaptersrrr r r r s status_codes.pyc000064400000011031147205436720007767 0ustar00 abc@skddlmZiDdd6dd6dd6dd 6dd 6dd6dd6dd6dd6dd6dd 6dd#6dd(6dd*6dd,6dd.6dd26dd46dd76dd96dd;6dd=6ddA6ddE6ddH6ddJ6ddM6ddO6ddR6ddU6ddW6dd[6dd^6dd`6ddb6ddd6ddg6ddi6ddk6ddo6dds6ddu6ddy6dd{6dd~6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6ZeddZxcejD]U\ZZxFeD]>Zeeeeej ds!eeej eq!q!WqWdS(i(t LookupDicttcontinueidtswitching_protocolsiet processingift checkpointigt uri_too_longtrequest_uri_too_longiztoktokaytall_oktall_okaytall_goods\o/s✓itcreateditaccepteditnon_authoritative_infotnon_authoritative_informationit no_contentit reset_contenttresetitpartial_contenttpartialit multi_statustmultiple_statust multi_statitmultiple_statiitalready_reporteditim_useditmultiple_choicesi,tmoved_permanentlytmoveds\o-i-tfoundi.t see_othertotheri/t not_modifiedi0t use_proxyi1t switch_proxyi2ttemporary_redirectttemporary_movedt temporaryi3tpermanent_redirecttresume_incompletetresumei4t bad_requesttbadit unauthorizeditpayment_requiredtpaymentit forbiddenit not_founds-o-itmethod_not_allowedt not_alloweditnot_acceptableitproxy_authentication_requiredt proxy_authtproxy_authenticationitrequest_timeoutttimeoutitconflictitgoneitlength_requireditprecondition_failedt preconditionitrequest_entity_too_largeitrequest_uri_too_largeitunsupported_media_typetunsupported_mediat media_typeitrequested_range_not_satisfiabletrequested_rangetrange_not_satisfiableitexpectation_failedit im_a_teapottteapott i_am_a_teapotitmisdirected_requestitunprocessable_entityt unprocessableitlockeditfailed_dependencyt dependencyitunordered_collectiont unordereditupgrade_requiredtupgradeitprecondition_requiredittoo_many_requeststtoo_manyitheader_fields_too_largetfields_too_largeit no_responsetnoneit retry_withtretryit$blocked_by_windows_parental_controlstparental_controlsitunavailable_for_legal_reasonst legal_reasonsitclient_closed_requestitinternal_server_errort server_errors/o\s✗itnot_implementedit bad_gatewayitservice_unavailablet unavailableitgateway_timeoutithttp_version_not_supportedt http_versionitvariant_also_negotiatesitinsufficient_storageitbandwidth_limit_exceededt bandwidthit not_extendeditnetwork_authentication_requiredt network_authtnetwork_authenticationitnamet status_codess\t/N(R(R(R(R(RR(RRR R R s\o/s✓(R (R (RR(R(RR(RR(RRRR(R(R(R(RRs\o-(R(RR (R!(R"(R#(R$R%R&(R'R(R)(R*R+(R,(R-R.(R/(R0s-o-(R1R2(R3(R4R5R6(R7R8(R9(R:(R;(R<R=(R>(R?(R@RARB(RCRDRE(RF(RGRHRI(RJ(RKRL(RM(RNRO(RPRQ(RRRS(RTR=(RURV(RWRX(RYRZ(R[R\(R]R^(R_R`(Ra(RbRcs/o\s✗(Rd(Re(RfRg(Rh(RiRj(Rk(Rl(RmRn(Ro(RpRqRr(s\Ru( t structuresRt_codestcodestitemstcodettitlesttitletsetattrt startswithtupper(((sE/usr/lib/python2.7/site-packages/pip/_vendor/requests/status_codes.pyts  structures.pyc000064400000012453147205436720007523 0ustar00 abc@sUdZddlZddlmZdejfdYZdefdYZdS( sO requests.structures ~~~~~~~~~~~~~~~~~~~ Data structures that power Requests. iNi(t OrderedDicttCaseInsensitiveDictcBskeZdZd dZdZdZdZdZdZ dZ dZ d Z d Z RS( sA case-insensitive ``dict``-like object. Implements all methods and operations of ``collections.MutableMapping`` as well as dict's ``copy``. Also provides ``lower_items``. All keys are expected to be strings. The structure remembers the case of the last key to be set, and ``iter(instance)``, ``keys()``, ``items()``, ``iterkeys()``, and ``iteritems()`` will contain case-sensitive keys. However, querying and contains testing is case insensitive:: cid = CaseInsensitiveDict() cid['Accept'] = 'application/json' cid['aCCEPT'] == 'application/json' # True list(cid) == ['Accept'] # True For example, ``headers['content-encoding']`` will return the value of a ``'Content-Encoding'`` response header, regardless of how the header name was originally stored. If the constructor, ``.update``, or equality comparison operations are given keys that have equal ``.lower()``s, the behavior is undefined. cKs5t|_|dkr!i}n|j||dS(N(Rt_storetNonetupdate(tselftdatatkwargs((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyt__init__*s   cCs||f|j|j<s(Rtvalues(R((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyt__iter__;scCs t|jS(N(tlenR(R((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyt__len__>scCsd|jjDS(s.Like iteritems(), but with all lowercase keys.css%|]\}}||dfVqdS(iN((Rtlowerkeytkeyval((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pys Ds(Rtitems(R((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyt lower_itemsAscCsGt|tjr!t|}ntSt|jt|jkS(N(t isinstancet collectionstMappingRtNotImplementedtdictR(Rtother((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyt__eq__IscCst|jjS(N(RRR(R((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pytcopyRscCstt|jS(N(tstrRR(R((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyt__repr__UsN(t__name__t __module__t__doc__RRR R RRRRR R!R#(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyRs        t LookupDictcBs8eZdZddZdZdZddZRS(sDictionary lookup object.cCs ||_tt|jdS(N(tnametsuperR'R(RR(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyR\s cCs d|jS(Ns (R((R((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyR#`scCs|jj|dS(N(t__dict__tgetR(RR ((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyR cscCs|jj||S(N(R*R+(RR tdefault((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyR+hsN(R$R%R&RRR#R R+(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyR'Ys    (R&RtcompatRtMutableMappingRRR'(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyts Jmodels.pyc000064400000071030147205436720006557 0ustar00 abc@sdZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z mZmZmZddlmZdd lmZdd lmZdd lmZdd lmZmZmZdd lmZmZm Z m!Z!m"Z"m#Z#m$Z$ddl%m&Z&m'Z'ddl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2ddl3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=ddl3m>Z?ddl@mAZAeAjBeAjCeAjDeAjEeAjFfZGdZHddZIdZJdeKfdYZLdeKfdYZMdeMfdYZNdeLeMfdYZOdeKfd YZPdS(!s` requests.models ~~~~~~~~~~~~~~~ This module contains the primary objects that power Requests. iN(t RequestField(tencode_multipart_formdata(t parse_url(t DecodeErrortReadTimeoutErrort ProtocolErrortLocationParseError(tUnsupportedOperationi(t default_hooks(tCaseInsensitiveDict(t HTTPBasicAuth(tcookiejar_from_dicttget_cookie_headert_copy_cookie_jar(t HTTPErrort MissingSchemat InvalidURLtChunkedEncodingErrortContentDecodingErrortConnectionErrortStreamConsumedError(tto_native_stringtunicode_is_ascii( tguess_filenametget_auth_from_urlt requote_uritstream_decode_response_unicodetto_key_val_listtparse_header_linkst iter_slicestguess_json_utft super_lentcheck_header_validity( t cookielibt urlunparseturlsplitt urlencodetstrtbytestis_py2tchardett builtin_strt basestring(tjson(tcodesii iitRequestEncodingMixincBs5eZedZedZedZRS(cCssg}t|j}|j}|s-d}n|j||j}|rf|jd|j|ndj|S(sBuild the path URL to use.t/t?t(R#turltpathtappendtquerytjoin(tselfR1tpR2R4((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pytpath_url=s     cCst|ttfr|St|dr,|St|drg}xt|D]\}}t|tsyt|d r|g}nxl|D]d}|dk r|jt|tr|jdn|t|tr|jdn|fqqWqNWt |dt S|SdS(sEncode parameters in a piece of data. Will successfully encode parameters when passed as a dict or a list of 2-tuples. Order is retained if data is a list of 2-tuples but arbitrary if parameters are supplied as a dict. treadt__iter__sutf-8tdoseqN( t isinstanceR%R&thasattrRR*tNoneR3tencodeR$tTrue(tdatatresulttktvstv((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt_encode_paramsRs    !3c Cs]|stdnt|tr3tdng}t|pEi}t|pWi}x|D]\}}t|tst|d r|g}nx|D]}|d k rt|tst|}n|jt|tr|j dn|t|tr|j dn|fqqWqdWx|D] \}}d }d } t|t t frt |dkr|\} } qt |dkr|\} } }q|\} } }} nt|p|} |} t| tttfr| } n | j} td|d| d | d | } | jd ||j| q3Wt|\}}||fS( sBuild the body for a multipart/form-data request. Will successfully encode files when passed as a dict or a list of tuples. Order is retained if data is a list of tuples but arbitrary if parameters are supplied as a dict. The tuples may be 2-tuples (filename, fileobj), 3-tuples (filename, fileobj, contentype) or 4-tuples (filename, fileobj, contentype, custom_headers). sFiles must be provided.sData must not be a string.R:sutf-8iitnameRAtfilenametheaderst content_typeN(t ValueErrorR<R*RR=R>R&R%R3tdecodeR?ttupletlisttlenRt bytearrayR9Rtmake_multipartR(tfilesRAt new_fieldstfieldstfieldtvalRERCtfttfhtfntfptfdatatrftbodyRJ((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt _encode_filesmsH    !3  !(t__name__t __module__tpropertyR8t staticmethodRFR^(((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyR-<stRequestHooksMixincBseZdZdZRS(cCs||jkr"td|nt|tjrK|j|j|n0t|dr{|j|jd|DndS(sProperly register a hook.s1Unsupported event specified, with event name "%s"R:css'|]}t|tjr|VqdS(N(R<t collectionstCallable(t.0th((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pys sN(thooksRKR<RdReR3R=textend(R6teventthook((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt register_hooks cCs5y|j|j|tSWntk r0tSXdS(siDeregister a previously registered hook. Returns True if the hook existed, False if not. N(RhtremoveR@RKtFalse(R6RjRk((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pytderegister_hooks  (R_R`RlRo(((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRcs tRequestc BsGeZdZddddddddddd ZdZdZRS(sA user-created :class:`Request ` object. Used to prepare a :class:`PreparedRequest `, which is sent to the server. :param method: HTTP method to use. :param url: URL to send. :param headers: dictionary of headers to send. :param files: dictionary of {filename: fileobject} files to multipart upload. :param data: the body to attach to the request. If a dictionary is provided, form-encoding will take place. :param json: json for the body to attach to the request (if files or data is not specified). :param params: dictionary of URL parameters to append to the URL. :param auth: Auth handler or (user, pass) tuple. :param cookies: dictionary or CookieJar of cookies to attach to this request. :param hooks: dictionary of callback hooks, for internal usage. Usage:: >>> import requests >>> req = requests.Request('GET', 'http://httpbin.org/get') >>> req.prepare() c Cs|dkrgn|}|dkr*gn|}|dkrBin|}|dkrZin|}| dkrrin| } t|_x6t| jD]"\} } |jd| d| qW||_||_||_||_ ||_ | |_ ||_ ||_ ||_dS(NRjRk(R>RRhRNtitemsRltmethodR1RIRRRAR+tparamstauthtcookies( R6RrR1RIRRRARsRtRuRhR+RCRE((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt__init__s"         cCs d|jS(Ns(Rr(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt__repr__scCsqt}|jd|jd|jd|jd|jd|jd|jd|jd|j d |j d |j |S( sXConstructs a :class:`PreparedRequest ` for transmission and returns it.RrR1RIRRRAR+RsRtRuRh( tPreparedRequesttprepareRrR1RIRRRAR+RsRtRuRh(R6R7((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRys            N(R_R`t__doc__R>RvRwRy(((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRps  Rxc BseZdZdZddddddddddd ZdZdZdZe dZ dZ dZ dd Z d Zd d Zd ZdZRS(sThe fully mutable :class:`PreparedRequest ` object, containing the exact bytes that will be sent to the server. Generated from either a :class:`Request ` object or manually. Usage:: >>> import requests >>> req = requests.Request('GET', 'http://httpbin.org/get') >>> r = req.prepare() >>> s = requests.Session() >>> s.send(r) cCsFd|_d|_d|_d|_d|_t|_d|_dS(N( R>RrR1RIt_cookiesR]RRht_body_position(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRvs      c Csk|j||j|||j||j||j||| |j|||j| dS(s6Prepares the entire request with the given parameters.N(tprepare_methodt prepare_urltprepare_headerstprepare_cookiest prepare_bodyt prepare_autht prepare_hooks( R6RrR1RIRRRARsRtRuRhR+((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRy+s   cCs d|jS(Ns(Rr(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRw=scCst}|j|_|j|_|jdk r?|jjnd|_t|j|_|j|_|j |_ |j |_ |S(N( RxRrR1RIR>tcopyR R{R]RhR|(R6R7((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyR@s   '   cCs7||_|jdk r3t|jj|_ndS(sPrepares the given HTTP method.N(RrR>Rtupper(R6Rr((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyR}Ks cCsOddl}y"|j|dtjd}Wn|jk rJtnX|S(Nituts46sutf-8(tidnaR?R@RLt IDNAErrort UnicodeError(thostR((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt_get_idna_encoded_hostQs  " cCst|tr!|jd}ntr3t|n t|}|j}d|krz|jjd rz||_ dSy%t |\}}}}}}} Wn"t k r} t | j nX|sd} | jt|d} t| n|st d|nt|sRy|j|}Wqptk rNt dqpXn|jdrpt dn|pyd } | r| d 7} n| |7} |r| dt|7} n|sd }ntrst|tr|jd }nt| tr | jd } nt|tr.|jd }nt|trO|jd }nt| trs| jd } qsnt|ttfrt|}n|j|} | r|rd || f}q| }ntt|| |d|| g}||_ dS(sPrepares the given HTTP URL.tutf8t:thttpNsDInvalid URL {0!r}: No schema supplied. Perhaps you meant http://{0}?s Invalid URL %r: No host suppliedsURL has an invalid label.u*R0t@R.sutf-8s%s&%s(R<R&RLR'tunicodeR%tlstriptlowert startswithR1RRRtargstformatRRRRRR?RFRR"R>(R6R1RstschemeRtRtportR2R4tfragmentteterrortnetloct enc_params((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyR~[sh " %       $cCsYt|_|rUx@|jD]/}t||\}}||jt|t complexjsontdumpsR<R&R?tallR=R*RNRMRdtMappingRt TypeErrortAttributeErrorRtgetattrRR|tIOErrortOSErrortobjecttNotImplementedErrorR)RIR^RFtprepare_content_lengthR](R6RARRR+R]RJt is_streamtlength((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRsJ %    cCsr|dk r7t|}|rnt||jdPrepare Content-Length header based on request method and bodysContent-LengthtGETtHEADt0N(RR(R>RR)RIRrtget(R6R]R((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRs   'R0cCs|dkr6t|j}t|r-|nd}n|rt|trlt|dkrlt|}n||}|jj |j|j |j ndS(s"Prepares the given HTTP auth data.iN( R>RR1tanyR<RMROR t__dict__tupdateRR](R6RtR1turl_authtr((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRs ! cCs_t|tjr||_nt||_t|j|}|dk r[||jd` object. Any subsequent calls to ``prepare_cookies`` will have no actual effect, unless the "Cookie" header is removed beforehand. tCookieN(R<R!t CookieJarR{R R R>RI(R6Rut cookie_header((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyR$s   cCs5|p g}x"|D]}|j|||qWdS(sPrepares the given hooks.N(Rl(R6RhRj((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyR8s  N(R_R`RzRvR>RyRwRR}RbRR~RRRRRR(((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRxs    V E  tResponsec Bs7eZdZddddddddd d g Zd Zd Zd ZdZdZdZ dZ dZ dZ e dZe dZe dZe dZe dZdedZed"d"dZe dZe dZdZe dZd Zd!ZRS(#shThe :class:`Response ` object, which contains a server's response to an HTTP request. t_contentt status_codeRIR1thistorytencodingtreasonRutelapsedtrequestcCst|_t|_d|_d|_t|_d|_d|_ d|_ g|_ d|_ t i|_tjd|_d|_dS(Ni(RnRt_content_consumedR>t_nextRR RItrawR1RRRR Rutdatetimet timedeltaRR(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRvLs          cCs|S(N((R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt __enter__{scGs|jdS(N(tclose(R6R((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt__exit__~scs0jsjntfdjDS(Nc3s'|]}|t|dfVqdS(N(RR>(Rftattr(R6(s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pys s(Rtcontenttdictt __attrs__(R6((R6s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt __getstate__s    cCsQx*|jD]\}}t|||q Wt|dtt|dddS(NRR(RqtsetattrR@R>(R6tstateRGR((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt __setstate__scCs d|jS(Ns(R(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRwscCs|jS(skReturns True if :attr:`status_code` is less than 400. This attribute checks if the status code of the response is between 400 and 600 to see if there was a client error or a server error. If the status code, is between 200 and 400, this will return True. This is **not** a check to see if the response code is ``200 OK``. (tok(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt__bool__scCs|jS(skReturns True if :attr:`status_code` is less than 400. This attribute checks if the status code of the response is between 400 and 600 to see if there was a client error or a server error. If the status code, is between 200 and 400, this will return True. This is **not** a check to see if the response code is ``200 OK``. (R(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt __nonzero__scCs |jdS(s,Allows you to use a response as an iterator.i(t iter_content(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyR:scCs'y|jWntk r"tSXtS(skReturns True if :attr:`status_code` is less than 400. This attribute checks if the status code of the response is between 400 and 600 to see if there was a client error or a server error. If the status code, is between 200 and 400, this will return True. This is **not** a check to see if the response code is ``200 OK``. (traise_for_statusRRnR@(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRs  cCsd|jko|jtkS(sTrue if this Response is a well-formed HTTP redirect that could have been processed automatically (by :meth:`Session.resolve_redirects`). tlocation(RIRtREDIRECT_STATI(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt is_redirectscCs(d|jko'|jtjtjfkS(s@True if this Response one of the permanent versions of redirect.R(RIRR,tmoved_permanentlytpermanent_redirect(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pytis_permanent_redirectscCs|jS(sTReturns a PreparedRequest for the next request in a redirect chain, if there is one.(R(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pytnextscCstj|jdS(s7The apparent encoding, provided by the chardet library.R(R(tdetectR(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pytapparent_encodingsicsfd}jr9tjtr9tn5dk rntt rntdtnt j}|}jr|n|}|rt |}n|S(sIterates over the response data. When stream=True is set on the request, this avoids reading the content at once into memory for large responses. The chunk size is the number of bytes it should read into memory. This is not necessarily the length of each item returned as decoding can take place. chunk_size must be of type int or None. A value of None will function differently depending on the value of `stream`. stream=True will read data as it arrives in whatever size the chunks are received. If stream=False, data is returned as a single chunk. If decode_unicode is True, content will be decoded using the best available encoding based on the response. c3stjdry,x%jjdtD] }|Vq.WWqtk r_}t|qtk r}}t|qtk r}t |qXn.x+trjj }|sPn|VqWt_ dS(Ntstreamtdecode_content( R=RRR@RRRRRRR9R(tchunkR(t chunk_sizeR6(s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pytgenerates    s.chunk_size must be an int, it is instead a %s.N( RR<RtboolRR>tintRttypeRR(R6Rtdecode_unicodeRt reused_chunkst stream_chunkstchunks((RR6s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRs  ccsd}x|jd|d|D]}|dk r>||}n|rV|j|}n |j}|r|dr|r|dd|dkr|j}nd}x|D] }|VqWqW|dk r|VndS(sIterates over the response data, one line at a time. When stream=True is set on the request, this avoids reading the content at once into memory for large responses. .. note:: This method is not reentrant safe. RRiN(R>Rtsplitt splitlinestpop(R6RRt delimitertpendingRtlinestline((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt iter_lines s   .   cCs|jtkr{|jr'tdn|jdksE|jdkrQd|_q{tj|j t prt|_nt |_|jS(s"Content of the response, in bytes.s2The content for this response was already consumediN( RRnRt RuntimeErrorRRR>R&R5RtCONTENT_CHUNK_SIZER@(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyR*s   * cCsd}|j}|js"tdS|jdkr=|j}nyt|j|dd}Wn,ttfk rt|jdd}nX|S(sContent of the response, in unicode. If Response.encoding is None, encoding will be guessed using ``chardet``. The encoding of the response content is determined based solely on HTTP headers, following RFC 2616 to the letter. If you can take advantage of non-HTTP knowledge to make a better guess at the encoding, you should set ``r.encoding`` appropriately before accessing this property. R0terrorstreplaceN(R>RRR%Rt LookupErrorR(R6RR((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyttext>s    cKs|j r}|jr}t|jdkr}t|j}|dk r}y tj|jj||SWqztk rvqzXq}ntj|j |S(sReturns the json-encoded content of a response, if any. :param \*\*kwargs: Optional arguments that ``json.loads`` takes. :raises ValueError: If the response body does not contain valid json. iN( RRRORR>RtloadsRLtUnicodeDecodeErrorR(R6tkwargsR((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyR+ds(   cCsj|jjd}i}|rft|}x9|D].}|jdpR|jd}|||(R6R((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRs   N(R_R`RzRRvRRRRRwRRR:RaRRRRRRnRtITER_CHUNK_SIZER>RRRR+RRR(((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRBs2 /     7&  (QRzRdRtsystencodings.idnat encodingstpip._vendor.urllib3.fieldsRtpip._vendor.urllib3.filepostRtpip._vendor.urllib3.utilRtpip._vendor.urllib3.exceptionsRRRRtioRRhRt structuresR RtR RuR R R t exceptionsRRRRRRRt_internal_utilsRRtutilsRRRRRRRRRR tcompatR!R"R#R$R%R&R'R(R)R*R+Rt status_codesR,tmovedtfoundtotherttemporary_redirectRRtDEFAULT_REDIRECT_LIMITRRRR-RcRpRxR(((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pytsB    "4FF  nF;models.pyo000064400000071030147205436720006573 0ustar00 abc@sdZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z mZmZmZddlmZdd lmZdd lmZdd lmZdd lmZmZmZdd lmZmZm Z m!Z!m"Z"m#Z#m$Z$ddl%m&Z&m'Z'ddl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2ddl3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=ddl3m>Z?ddl@mAZAeAjBeAjCeAjDeAjEeAjFfZGdZHddZIdZJdeKfdYZLdeKfdYZMdeMfdYZNdeLeMfdYZOdeKfd YZPdS(!s` requests.models ~~~~~~~~~~~~~~~ This module contains the primary objects that power Requests. iN(t RequestField(tencode_multipart_formdata(t parse_url(t DecodeErrortReadTimeoutErrort ProtocolErrortLocationParseError(tUnsupportedOperationi(t default_hooks(tCaseInsensitiveDict(t HTTPBasicAuth(tcookiejar_from_dicttget_cookie_headert_copy_cookie_jar(t HTTPErrort MissingSchemat InvalidURLtChunkedEncodingErrortContentDecodingErrortConnectionErrortStreamConsumedError(tto_native_stringtunicode_is_ascii( tguess_filenametget_auth_from_urlt requote_uritstream_decode_response_unicodetto_key_val_listtparse_header_linkst iter_slicestguess_json_utft super_lentcheck_header_validity( t cookielibt urlunparseturlsplitt urlencodetstrtbytestis_py2tchardett builtin_strt basestring(tjson(tcodesii iitRequestEncodingMixincBs5eZedZedZedZRS(cCssg}t|j}|j}|s-d}n|j||j}|rf|jd|j|ndj|S(sBuild the path URL to use.t/t?t(R#turltpathtappendtquerytjoin(tselfR1tpR2R4((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pytpath_url=s     cCst|ttfr|St|dr,|St|drg}xt|D]\}}t|tsyt|d r|g}nxl|D]d}|dk r|jt|tr|jdn|t|tr|jdn|fqqWqNWt |dt S|SdS(sEncode parameters in a piece of data. Will successfully encode parameters when passed as a dict or a list of 2-tuples. Order is retained if data is a list of 2-tuples but arbitrary if parameters are supplied as a dict. treadt__iter__sutf-8tdoseqN( t isinstanceR%R&thasattrRR*tNoneR3tencodeR$tTrue(tdatatresulttktvstv((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt_encode_paramsRs    !3c Cs]|stdnt|tr3tdng}t|pEi}t|pWi}x|D]\}}t|tst|d r|g}nx|D]}|d k rt|tst|}n|jt|tr|j dn|t|tr|j dn|fqqWqdWx|D] \}}d }d } t|t t frt |dkr|\} } qt |dkr|\} } }q|\} } }} nt|p|} |} t| tttfr| } n | j} td|d| d | d | } | jd ||j| q3Wt|\}}||fS( sBuild the body for a multipart/form-data request. Will successfully encode files when passed as a dict or a list of tuples. Order is retained if data is a list of tuples but arbitrary if parameters are supplied as a dict. The tuples may be 2-tuples (filename, fileobj), 3-tuples (filename, fileobj, contentype) or 4-tuples (filename, fileobj, contentype, custom_headers). sFiles must be provided.sData must not be a string.R:sutf-8iitnameRAtfilenametheaderst content_typeN(t ValueErrorR<R*RR=R>R&R%R3tdecodeR?ttupletlisttlenRt bytearrayR9Rtmake_multipartR(tfilesRAt new_fieldstfieldstfieldtvalRERCtfttfhtfntfptfdatatrftbodyRJ((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt _encode_filesmsH    !3  !(t__name__t __module__tpropertyR8t staticmethodRFR^(((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyR-<stRequestHooksMixincBseZdZdZRS(cCs||jkr"td|nt|tjrK|j|j|n0t|dr{|j|jd|DndS(sProperly register a hook.s1Unsupported event specified, with event name "%s"R:css'|]}t|tjr|VqdS(N(R<t collectionstCallable(t.0th((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pys sN(thooksRKR<RdReR3R=textend(R6teventthook((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt register_hooks cCs5y|j|j|tSWntk r0tSXdS(siDeregister a previously registered hook. Returns True if the hook existed, False if not. N(RhtremoveR@RKtFalse(R6RjRk((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pytderegister_hooks  (R_R`RlRo(((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRcs tRequestc BsGeZdZddddddddddd ZdZdZRS(sA user-created :class:`Request ` object. Used to prepare a :class:`PreparedRequest `, which is sent to the server. :param method: HTTP method to use. :param url: URL to send. :param headers: dictionary of headers to send. :param files: dictionary of {filename: fileobject} files to multipart upload. :param data: the body to attach to the request. If a dictionary is provided, form-encoding will take place. :param json: json for the body to attach to the request (if files or data is not specified). :param params: dictionary of URL parameters to append to the URL. :param auth: Auth handler or (user, pass) tuple. :param cookies: dictionary or CookieJar of cookies to attach to this request. :param hooks: dictionary of callback hooks, for internal usage. Usage:: >>> import requests >>> req = requests.Request('GET', 'http://httpbin.org/get') >>> req.prepare() c Cs|dkrgn|}|dkr*gn|}|dkrBin|}|dkrZin|}| dkrrin| } t|_x6t| jD]"\} } |jd| d| qW||_||_||_||_ ||_ | |_ ||_ ||_ ||_dS(NRjRk(R>RRhRNtitemsRltmethodR1RIRRRAR+tparamstauthtcookies( R6RrR1RIRRRARsRtRuRhR+RCRE((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt__init__s"         cCs d|jS(Ns(Rr(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt__repr__scCsqt}|jd|jd|jd|jd|jd|jd|jd|jd|j d |j d |j |S( sXConstructs a :class:`PreparedRequest ` for transmission and returns it.RrR1RIRRRAR+RsRtRuRh( tPreparedRequesttprepareRrR1RIRRRAR+RsRtRuRh(R6R7((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRys            N(R_R`t__doc__R>RvRwRy(((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRps  Rxc BseZdZdZddddddddddd ZdZdZdZe dZ dZ dZ dd Z d Zd d Zd ZdZRS(sThe fully mutable :class:`PreparedRequest ` object, containing the exact bytes that will be sent to the server. Generated from either a :class:`Request ` object or manually. Usage:: >>> import requests >>> req = requests.Request('GET', 'http://httpbin.org/get') >>> r = req.prepare() >>> s = requests.Session() >>> s.send(r) cCsFd|_d|_d|_d|_d|_t|_d|_dS(N( R>RrR1RIt_cookiesR]RRht_body_position(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRvs      c Csk|j||j|||j||j||j||| |j|||j| dS(s6Prepares the entire request with the given parameters.N(tprepare_methodt prepare_urltprepare_headerstprepare_cookiest prepare_bodyt prepare_autht prepare_hooks( R6RrR1RIRRRARsRtRuRhR+((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRy+s   cCs d|jS(Ns(Rr(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRw=scCst}|j|_|j|_|jdk r?|jjnd|_t|j|_|j|_|j |_ |j |_ |S(N( RxRrR1RIR>tcopyR R{R]RhR|(R6R7((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyR@s   '   cCs7||_|jdk r3t|jj|_ndS(sPrepares the given HTTP method.N(RrR>Rtupper(R6Rr((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyR}Ks cCsOddl}y"|j|dtjd}Wn|jk rJtnX|S(Nituts46sutf-8(tidnaR?R@RLt IDNAErrort UnicodeError(thostR((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt_get_idna_encoded_hostQs  " cCst|tr!|jd}ntr3t|n t|}|j}d|krz|jjd rz||_ dSy%t |\}}}}}}} Wn"t k r} t | j nX|sd} | jt|d} t| n|st d|nt|sRy|j|}Wqptk rNt dqpXn|jdrpt dn|pyd } | r| d 7} n| |7} |r| dt|7} n|sd }ntrst|tr|jd }nt| tr | jd } nt|tr.|jd }nt|trO|jd }nt| trs| jd } qsnt|ttfrt|}n|j|} | r|rd || f}q| }ntt|| |d|| g}||_ dS(sPrepares the given HTTP URL.tutf8t:thttpNsDInvalid URL {0!r}: No schema supplied. Perhaps you meant http://{0}?s Invalid URL %r: No host suppliedsURL has an invalid label.u*R0t@R.sutf-8s%s&%s(R<R&RLR'tunicodeR%tlstriptlowert startswithR1RRRtargstformatRRRRRR?RFRR"R>(R6R1RstschemeRtRtportR2R4tfragmentteterrortnetloct enc_params((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyR~[sh " %       $cCsYt|_|rUx@|jD]/}t||\}}||jt|t complexjsontdumpsR<R&R?tallR=R*RNRMRdtMappingRt TypeErrortAttributeErrorRtgetattrRR|tIOErrortOSErrortobjecttNotImplementedErrorR)RIR^RFtprepare_content_lengthR](R6RARRR+R]RJt is_streamtlength((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRsJ %    cCsr|dk r7t|}|rnt||jdPrepare Content-Length header based on request method and bodysContent-LengthtGETtHEADt0N(RR(R>RR)RIRrtget(R6R]R((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRs   'R0cCs|dkr6t|j}t|r-|nd}n|rt|trlt|dkrlt|}n||}|jj |j|j |j ndS(s"Prepares the given HTTP auth data.iN( R>RR1tanyR<RMROR t__dict__tupdateRR](R6RtR1turl_authtr((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRs ! cCs_t|tjr||_nt||_t|j|}|dk r[||jd` object. Any subsequent calls to ``prepare_cookies`` will have no actual effect, unless the "Cookie" header is removed beforehand. tCookieN(R<R!t CookieJarR{R R R>RI(R6Rut cookie_header((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyR$s   cCs5|p g}x"|D]}|j|||qWdS(sPrepares the given hooks.N(Rl(R6RhRj((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyR8s  N(R_R`RzRvR>RyRwRR}RbRR~RRRRRR(((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRxs    V E  tResponsec Bs7eZdZddddddddd d g Zd Zd Zd ZdZdZdZ dZ dZ dZ e dZe dZe dZe dZe dZdedZed"d"dZe dZe dZdZe dZd Zd!ZRS(#shThe :class:`Response ` object, which contains a server's response to an HTTP request. t_contentt status_codeRIR1thistorytencodingtreasonRutelapsedtrequestcCst|_t|_d|_d|_t|_d|_d|_ d|_ g|_ d|_ t i|_tjd|_d|_dS(Ni(RnRt_content_consumedR>t_nextRR RItrawR1RRRR Rutdatetimet timedeltaRR(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRvLs          cCs|S(N((R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt __enter__{scGs|jdS(N(tclose(R6R((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt__exit__~scs0jsjntfdjDS(Nc3s'|]}|t|dfVqdS(N(RR>(Rftattr(R6(s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pys s(Rtcontenttdictt __attrs__(R6((R6s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt __getstate__s    cCsQx*|jD]\}}t|||q Wt|dtt|dddS(NRR(RqtsetattrR@R>(R6tstateRGR((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt __setstate__scCs d|jS(Ns(R(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRwscCs|jS(skReturns True if :attr:`status_code` is less than 400. This attribute checks if the status code of the response is between 400 and 600 to see if there was a client error or a server error. If the status code, is between 200 and 400, this will return True. This is **not** a check to see if the response code is ``200 OK``. (tok(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt__bool__scCs|jS(skReturns True if :attr:`status_code` is less than 400. This attribute checks if the status code of the response is between 400 and 600 to see if there was a client error or a server error. If the status code, is between 200 and 400, this will return True. This is **not** a check to see if the response code is ``200 OK``. (R(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt __nonzero__scCs |jdS(s,Allows you to use a response as an iterator.i(t iter_content(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyR:scCs'y|jWntk r"tSXtS(skReturns True if :attr:`status_code` is less than 400. This attribute checks if the status code of the response is between 400 and 600 to see if there was a client error or a server error. If the status code, is between 200 and 400, this will return True. This is **not** a check to see if the response code is ``200 OK``. (traise_for_statusRRnR@(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRs  cCsd|jko|jtkS(sTrue if this Response is a well-formed HTTP redirect that could have been processed automatically (by :meth:`Session.resolve_redirects`). tlocation(RIRtREDIRECT_STATI(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt is_redirectscCs(d|jko'|jtjtjfkS(s@True if this Response one of the permanent versions of redirect.R(RIRR,tmoved_permanentlytpermanent_redirect(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pytis_permanent_redirectscCs|jS(sTReturns a PreparedRequest for the next request in a redirect chain, if there is one.(R(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pytnextscCstj|jdS(s7The apparent encoding, provided by the chardet library.R(R(tdetectR(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pytapparent_encodingsicsfd}jr9tjtr9tn5dk rntt rntdtnt j}|}jr|n|}|rt |}n|S(sIterates over the response data. When stream=True is set on the request, this avoids reading the content at once into memory for large responses. The chunk size is the number of bytes it should read into memory. This is not necessarily the length of each item returned as decoding can take place. chunk_size must be of type int or None. A value of None will function differently depending on the value of `stream`. stream=True will read data as it arrives in whatever size the chunks are received. If stream=False, data is returned as a single chunk. If decode_unicode is True, content will be decoded using the best available encoding based on the response. c3stjdry,x%jjdtD] }|Vq.WWqtk r_}t|qtk r}}t|qtk r}t |qXn.x+trjj }|sPn|VqWt_ dS(Ntstreamtdecode_content( R=RRR@RRRRRRR9R(tchunkR(t chunk_sizeR6(s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pytgenerates    s.chunk_size must be an int, it is instead a %s.N( RR<RtboolRR>tintRttypeRR(R6Rtdecode_unicodeRt reused_chunkst stream_chunkstchunks((RR6s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRs  ccsd}x|jd|d|D]}|dk r>||}n|rV|j|}n |j}|r|dr|r|dd|dkr|j}nd}x|D] }|VqWqW|dk r|VndS(sIterates over the response data, one line at a time. When stream=True is set on the request, this avoids reading the content at once into memory for large responses. .. note:: This method is not reentrant safe. RRiN(R>Rtsplitt splitlinestpop(R6RRt delimitertpendingRtlinestline((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyt iter_lines s   .   cCs|jtkr{|jr'tdn|jdksE|jdkrQd|_q{tj|j t prt|_nt |_|jS(s"Content of the response, in bytes.s2The content for this response was already consumediN( RRnRt RuntimeErrorRRR>R&R5RtCONTENT_CHUNK_SIZER@(R6((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyR*s   * cCsd}|j}|js"tdS|jdkr=|j}nyt|j|dd}Wn,ttfk rt|jdd}nX|S(sContent of the response, in unicode. If Response.encoding is None, encoding will be guessed using ``chardet``. The encoding of the response content is determined based solely on HTTP headers, following RFC 2616 to the letter. If you can take advantage of non-HTTP knowledge to make a better guess at the encoding, you should set ``r.encoding`` appropriately before accessing this property. R0terrorstreplaceN(R>RRR%Rt LookupErrorR(R6RR((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyttext>s    cKs|j r}|jr}t|jdkr}t|j}|dk r}y tj|jj||SWqztk rvqzXq}ntj|j |S(sReturns the json-encoded content of a response, if any. :param \*\*kwargs: Optional arguments that ``json.loads`` takes. :raises ValueError: If the response body does not contain valid json. iN( RRRORR>RtloadsRLtUnicodeDecodeErrorR(R6tkwargsR((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyR+ds(   cCsj|jjd}i}|rft|}x9|D].}|jdpR|jd}|||(R6R((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRs   N(R_R`RzRRvRRRRRwRRR:RaRRRRRRnRtITER_CHUNK_SIZER>RRRR+RRR(((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pyRBs2 /     7&  (QRzRdRtsystencodings.idnat encodingstpip._vendor.urllib3.fieldsRtpip._vendor.urllib3.filepostRtpip._vendor.urllib3.utilRtpip._vendor.urllib3.exceptionsRRRRtioRRhRt structuresR RtR RuR R R t exceptionsRRRRRRRt_internal_utilsRRtutilsRRRRRRRRRR tcompatR!R"R#R$R%R&R'R(R)R*R+Rt status_codesR,tmovedtfoundtotherttemporary_redirectRRtDEFAULT_REDIRECT_LIMITRRRR-RcRpRxR(((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/models.pytsB    "4FF  nF;packages.py000064400000001267147205436720006714 0ustar00import sys # This code exists for backwards compatibility reasons. # I don't like it either. Just look the other way. :) for package in ('urllib3', 'idna', 'chardet'): vendored_package = "pip._vendor." + package locals()[package] = __import__(vendored_package) # This traversal is apparently necessary such that the identities are # preserved (requests.packages.urllib3.* is urllib3.*) for mod in list(sys.modules): if mod == vendored_package or mod.startswith(vendored_package + '.'): unprefixed_mod = mod[len("pip._vendor."):] sys.modules['pip._vendor.requests.packages.' + unprefixed_mod] = sys.modules[mod] # Kinda cool, though, right? packages.pyc000064400000001102147205436720007043 0ustar00 abc@sddlZxdD]ZdeZeeees   packages.pyo000064400000001102147205436720007057 0ustar00 abc@sddlZxdD]ZdeZeeees   sessions.py000064400000070021147205436720006776 0ustar00# -*- coding: utf-8 -*- """ requests.session ~~~~~~~~~~~~~~~~ This module provides a Session object to manage and persist settings across requests (cookies, auth, proxies). """ import os import platform import time from collections import Mapping from datetime import timedelta from .auth import _basic_auth_str from .compat import cookielib, is_py3, OrderedDict, urljoin, urlparse from .cookies import ( cookiejar_from_dict, extract_cookies_to_jar, RequestsCookieJar, merge_cookies) from .models import Request, PreparedRequest, DEFAULT_REDIRECT_LIMIT from .hooks import default_hooks, dispatch_hook from ._internal_utils import to_native_string from .utils import to_key_val_list, default_headers from .exceptions import ( TooManyRedirects, InvalidSchema, ChunkedEncodingError, ContentDecodingError) from .structures import CaseInsensitiveDict from .adapters import HTTPAdapter from .utils import ( requote_uri, get_environ_proxies, get_netrc_auth, should_bypass_proxies, get_auth_from_url, rewind_body, DEFAULT_PORTS ) from .status_codes import codes # formerly defined here, reexposed here for backward compatibility from .models import REDIRECT_STATI # Preferred clock, based on which one is more accurate on a given system. if platform.system() == 'Windows': try: # Python 3.3+ preferred_clock = time.perf_counter except AttributeError: # Earlier than Python 3. preferred_clock = time.clock else: preferred_clock = time.time def merge_setting(request_setting, session_setting, dict_class=OrderedDict): """Determines appropriate setting for a given request, taking into account the explicit setting on that request, and the setting in the session. If a setting is a dictionary, they will be merged together using `dict_class` """ if session_setting is None: return request_setting if request_setting is None: return session_setting # Bypass if not a dictionary (e.g. verify) if not ( isinstance(session_setting, Mapping) and isinstance(request_setting, Mapping) ): return request_setting merged_setting = dict_class(to_key_val_list(session_setting)) merged_setting.update(to_key_val_list(request_setting)) # Remove keys that are set to None. Extract keys first to avoid altering # the dictionary during iteration. none_keys = [k for (k, v) in merged_setting.items() if v is None] for key in none_keys: del merged_setting[key] return merged_setting def merge_hooks(request_hooks, session_hooks, dict_class=OrderedDict): """Properly merges both requests and session hooks. This is necessary because when request_hooks == {'response': []}, the merge breaks Session hooks entirely. """ if session_hooks is None or session_hooks.get('response') == []: return request_hooks if request_hooks is None or request_hooks.get('response') == []: return session_hooks return merge_setting(request_hooks, session_hooks, dict_class) class SessionRedirectMixin(object): def get_redirect_target(self, resp): """Receives a Response. Returns a redirect URI or ``None``""" # Due to the nature of how requests processes redirects this method will # be called at least once upon the original response and at least twice # on each subsequent redirect response (if any). # If a custom mixin is used to handle this logic, it may be advantageous # to cache the redirect location onto the response object as a private # attribute. if resp.is_redirect: location = resp.headers['location'] # Currently the underlying http module on py3 decode headers # in latin1, but empirical evidence suggests that latin1 is very # rarely used with non-ASCII characters in HTTP headers. # It is more likely to get UTF8 header rather than latin1. # This causes incorrect handling of UTF8 encoded location headers. # To solve this, we re-encode the location in latin1. if is_py3: location = location.encode('latin1') return to_native_string(location, 'utf8') return None def should_strip_auth(self, old_url, new_url): """Decide whether Authorization header should be removed when redirecting""" old_parsed = urlparse(old_url) new_parsed = urlparse(new_url) if old_parsed.hostname != new_parsed.hostname: return True # Special case: allow http -> https redirect when using the standard # ports. This isn't specified by RFC 7235, but is kept to avoid # breaking backwards compatibility with older versions of requests # that allowed any redirects on the same host. if (old_parsed.scheme == 'http' and old_parsed.port in (80, None) and new_parsed.scheme == 'https' and new_parsed.port in (443, None)): return False # Handle default port usage corresponding to scheme. changed_port = old_parsed.port != new_parsed.port changed_scheme = old_parsed.scheme != new_parsed.scheme default_port = (DEFAULT_PORTS.get(old_parsed.scheme, None), None) if (not changed_scheme and old_parsed.port in default_port and new_parsed.port in default_port): return False # Standard case: root URI must match return changed_port or changed_scheme def resolve_redirects(self, resp, req, stream=False, timeout=None, verify=True, cert=None, proxies=None, yield_requests=False, **adapter_kwargs): """Receives a Response. Returns a generator of Responses or Requests.""" hist = [] # keep track of history url = self.get_redirect_target(resp) while url: prepared_request = req.copy() # Update history and keep track of redirects. # resp.history must ignore the original request in this loop hist.append(resp) resp.history = hist[1:] try: resp.content # Consume socket so it can be released except (ChunkedEncodingError, ContentDecodingError, RuntimeError): resp.raw.read(decode_content=False) if len(resp.history) >= self.max_redirects: raise TooManyRedirects('Exceeded %s redirects.' % self.max_redirects, response=resp) # Release the connection back into the pool. resp.close() # Handle redirection without scheme (see: RFC 1808 Section 4) if url.startswith('//'): parsed_rurl = urlparse(resp.url) url = '%s:%s' % (to_native_string(parsed_rurl.scheme), url) # The scheme should be lower case... parsed = urlparse(url) url = parsed.geturl() # Facilitate relative 'location' headers, as allowed by RFC 7231. # (e.g. '/path/to/resource' instead of 'http://domain.tld/path/to/resource') # Compliant with RFC3986, we percent encode the url. if not parsed.netloc: url = urljoin(resp.url, requote_uri(url)) else: url = requote_uri(url) prepared_request.url = to_native_string(url) self.rebuild_method(prepared_request, resp) # https://github.com/requests/requests/issues/1084 if resp.status_code not in (codes.temporary_redirect, codes.permanent_redirect): # https://github.com/requests/requests/issues/3490 purged_headers = ('Content-Length', 'Content-Type', 'Transfer-Encoding') for header in purged_headers: prepared_request.headers.pop(header, None) prepared_request.body = None headers = prepared_request.headers try: del headers['Cookie'] except KeyError: pass # Extract any cookies sent on the response to the cookiejar # in the new request. Because we've mutated our copied prepared # request, use the old one that we haven't yet touched. extract_cookies_to_jar(prepared_request._cookies, req, resp.raw) merge_cookies(prepared_request._cookies, self.cookies) prepared_request.prepare_cookies(prepared_request._cookies) # Rebuild auth and proxy information. proxies = self.rebuild_proxies(prepared_request, proxies) self.rebuild_auth(prepared_request, resp) # A failed tell() sets `_body_position` to `object()`. This non-None # value ensures `rewindable` will be True, allowing us to raise an # UnrewindableBodyError, instead of hanging the connection. rewindable = ( prepared_request._body_position is not None and ('Content-Length' in headers or 'Transfer-Encoding' in headers) ) # Attempt to rewind consumed file-like object. if rewindable: rewind_body(prepared_request) # Override the original request. req = prepared_request if yield_requests: yield req else: resp = self.send( req, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies, allow_redirects=False, **adapter_kwargs ) extract_cookies_to_jar(self.cookies, prepared_request, resp.raw) # extract redirect url, if any, for the next loop url = self.get_redirect_target(resp) yield resp def rebuild_auth(self, prepared_request, response): """When being redirected we may want to strip authentication from the request to avoid leaking credentials. This method intelligently removes and reapplies authentication where possible to avoid credential loss. """ headers = prepared_request.headers url = prepared_request.url if 'Authorization' in headers and self.should_strip_auth(response.request.url, url): # If we get redirected to a new host, we should strip out any # authentication headers. del headers['Authorization'] # .netrc might have more auth for us on our new host. new_auth = get_netrc_auth(url) if self.trust_env else None if new_auth is not None: prepared_request.prepare_auth(new_auth) return def rebuild_proxies(self, prepared_request, proxies): """This method re-evaluates the proxy configuration by considering the environment variables. If we are redirected to a URL covered by NO_PROXY, we strip the proxy configuration. Otherwise, we set missing proxy keys for this URL (in case they were stripped by a previous redirect). This method also replaces the Proxy-Authorization header where necessary. :rtype: dict """ proxies = proxies if proxies is not None else {} headers = prepared_request.headers url = prepared_request.url scheme = urlparse(url).scheme new_proxies = proxies.copy() no_proxy = proxies.get('no_proxy') bypass_proxy = should_bypass_proxies(url, no_proxy=no_proxy) if self.trust_env and not bypass_proxy: environ_proxies = get_environ_proxies(url, no_proxy=no_proxy) proxy = environ_proxies.get(scheme, environ_proxies.get('all')) if proxy: new_proxies.setdefault(scheme, proxy) if 'Proxy-Authorization' in headers: del headers['Proxy-Authorization'] try: username, password = get_auth_from_url(new_proxies[scheme]) except KeyError: username, password = None, None if username and password: headers['Proxy-Authorization'] = _basic_auth_str(username, password) return new_proxies def rebuild_method(self, prepared_request, response): """When being redirected we may want to change the method of the request based on certain specs or browser behavior. """ method = prepared_request.method # http://tools.ietf.org/html/rfc7231#section-6.4.4 if response.status_code == codes.see_other and method != 'HEAD': method = 'GET' # Do what the browsers do, despite standards... # First, turn 302s into GETs. if response.status_code == codes.found and method != 'HEAD': method = 'GET' # Second, if a POST is responded to with a 301, turn it into a GET. # This bizarre behaviour is explained in Issue 1704. if response.status_code == codes.moved and method == 'POST': method = 'GET' prepared_request.method = method class Session(SessionRedirectMixin): """A Requests session. Provides cookie persistence, connection-pooling, and configuration. Basic Usage:: >>> import requests >>> s = requests.Session() >>> s.get('http://httpbin.org/get') Or as a context manager:: >>> with requests.Session() as s: >>> s.get('http://httpbin.org/get') """ __attrs__ = [ 'headers', 'cookies', 'auth', 'proxies', 'hooks', 'params', 'verify', 'cert', 'prefetch', 'adapters', 'stream', 'trust_env', 'max_redirects', ] def __init__(self): #: A case-insensitive dictionary of headers to be sent on each #: :class:`Request ` sent from this #: :class:`Session `. self.headers = default_headers() #: Default Authentication tuple or object to attach to #: :class:`Request `. self.auth = None #: Dictionary mapping protocol or protocol and host to the URL of the proxy #: (e.g. {'http': 'foo.bar:3128', 'http://host.name': 'foo.bar:4012'}) to #: be used on each :class:`Request `. self.proxies = {} #: Event-handling hooks. self.hooks = default_hooks() #: Dictionary of querystring data to attach to each #: :class:`Request `. The dictionary values may be lists for #: representing multivalued query parameters. self.params = {} #: Stream response content default. self.stream = False #: SSL Verification default. self.verify = True #: SSL client certificate default, if String, path to ssl client #: cert file (.pem). If Tuple, ('cert', 'key') pair. self.cert = None #: Maximum number of redirects allowed. If the request exceeds this #: limit, a :class:`TooManyRedirects` exception is raised. #: This defaults to requests.models.DEFAULT_REDIRECT_LIMIT, which is #: 30. self.max_redirects = DEFAULT_REDIRECT_LIMIT #: Trust environment settings for proxy configuration, default #: authentication and similar. self.trust_env = True #: A CookieJar containing all currently outstanding cookies set on this #: session. By default it is a #: :class:`RequestsCookieJar `, but #: may be any other ``cookielib.CookieJar`` compatible object. self.cookies = cookiejar_from_dict({}) # Default connection adapters. self.adapters = OrderedDict() self.mount('https://', HTTPAdapter()) self.mount('http://', HTTPAdapter()) def __enter__(self): return self def __exit__(self, *args): self.close() def prepare_request(self, request): """Constructs a :class:`PreparedRequest ` for transmission and returns it. The :class:`PreparedRequest` has settings merged from the :class:`Request ` instance and those of the :class:`Session`. :param request: :class:`Request` instance to prepare with this session's settings. :rtype: requests.PreparedRequest """ cookies = request.cookies or {} # Bootstrap CookieJar. if not isinstance(cookies, cookielib.CookieJar): cookies = cookiejar_from_dict(cookies) # Merge with session cookies merged_cookies = merge_cookies( merge_cookies(RequestsCookieJar(), self.cookies), cookies) # Set environment's basic authentication if not explicitly set. auth = request.auth if self.trust_env and not auth and not self.auth: auth = get_netrc_auth(request.url) p = PreparedRequest() p.prepare( method=request.method.upper(), url=request.url, files=request.files, data=request.data, json=request.json, headers=merge_setting(request.headers, self.headers, dict_class=CaseInsensitiveDict), params=merge_setting(request.params, self.params), auth=merge_setting(auth, self.auth), cookies=merged_cookies, hooks=merge_hooks(request.hooks, self.hooks), ) return p def request(self, method, url, params=None, data=None, headers=None, cookies=None, files=None, auth=None, timeout=None, allow_redirects=True, proxies=None, hooks=None, stream=None, verify=None, cert=None, json=None): """Constructs a :class:`Request `, prepares it and sends it. Returns :class:`Response ` object. :param method: method for the new :class:`Request` object. :param url: URL for the new :class:`Request` object. :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json to send in the body of the :class:`Request`. :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`. :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`. :param files: (optional) Dictionary of ``'filename': file-like-objects`` for multipart encoding upload. :param auth: (optional) Auth tuple or callable to enable Basic/Digest/Custom HTTP Auth. :param timeout: (optional) How long to wait for the server to send data before giving up, as a float, or a :ref:`(connect timeout, read timeout) ` tuple. :type timeout: float or tuple :param allow_redirects: (optional) Set to True by default. :type allow_redirects: bool :param proxies: (optional) Dictionary mapping protocol or protocol and hostname to the URL of the proxy. :param stream: (optional) whether to immediately download the response content. Defaults to ``False``. :param verify: (optional) Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use. Defaults to ``True``. :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair. :rtype: requests.Response """ # Create the Request. req = Request( method=method.upper(), url=url, headers=headers, files=files, data=data or {}, json=json, params=params or {}, auth=auth, cookies=cookies, hooks=hooks, ) prep = self.prepare_request(req) proxies = proxies or {} settings = self.merge_environment_settings( prep.url, proxies, stream, verify, cert ) # Send the request. send_kwargs = { 'timeout': timeout, 'allow_redirects': allow_redirects, } send_kwargs.update(settings) resp = self.send(prep, **send_kwargs) return resp def get(self, url, **kwargs): r"""Sends a GET request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response """ kwargs.setdefault('allow_redirects', True) return self.request('GET', url, **kwargs) def options(self, url, **kwargs): r"""Sends a OPTIONS request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response """ kwargs.setdefault('allow_redirects', True) return self.request('OPTIONS', url, **kwargs) def head(self, url, **kwargs): r"""Sends a HEAD request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response """ kwargs.setdefault('allow_redirects', False) return self.request('HEAD', url, **kwargs) def post(self, url, data=None, json=None, **kwargs): r"""Sends a POST request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response """ return self.request('POST', url, data=data, json=json, **kwargs) def put(self, url, data=None, **kwargs): r"""Sends a PUT request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response """ return self.request('PUT', url, data=data, **kwargs) def patch(self, url, data=None, **kwargs): r"""Sends a PATCH request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response """ return self.request('PATCH', url, data=data, **kwargs) def delete(self, url, **kwargs): r"""Sends a DELETE request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response """ return self.request('DELETE', url, **kwargs) def send(self, request, **kwargs): """Send a given PreparedRequest. :rtype: requests.Response """ # Set defaults that the hooks can utilize to ensure they always have # the correct parameters to reproduce the previous request. kwargs.setdefault('stream', self.stream) kwargs.setdefault('verify', self.verify) kwargs.setdefault('cert', self.cert) kwargs.setdefault('proxies', self.proxies) # It's possible that users might accidentally send a Request object. # Guard against that specific failure case. if isinstance(request, Request): raise ValueError('You can only send PreparedRequests.') # Set up variables needed for resolve_redirects and dispatching of hooks allow_redirects = kwargs.pop('allow_redirects', True) stream = kwargs.get('stream') hooks = request.hooks # Get the appropriate adapter to use adapter = self.get_adapter(url=request.url) # Start time (approximately) of the request start = preferred_clock() # Send the request r = adapter.send(request, **kwargs) # Total elapsed time of the request (approximately) elapsed = preferred_clock() - start r.elapsed = timedelta(seconds=elapsed) # Response manipulation hooks r = dispatch_hook('response', hooks, r, **kwargs) # Persist cookies if r.history: # If the hooks create history then we want those cookies too for resp in r.history: extract_cookies_to_jar(self.cookies, resp.request, resp.raw) extract_cookies_to_jar(self.cookies, request, r.raw) # Redirect resolving generator. gen = self.resolve_redirects(r, request, **kwargs) # Resolve redirects if allowed. history = [resp for resp in gen] if allow_redirects else [] # Shuffle things around if there's history. if history: # Insert the first (original) request at the start history.insert(0, r) # Get the last request made r = history.pop() r.history = history # If redirects aren't being followed, store the response on the Request for Response.next(). if not allow_redirects: try: r._next = next(self.resolve_redirects(r, request, yield_requests=True, **kwargs)) except StopIteration: pass if not stream: r.content return r def merge_environment_settings(self, url, proxies, stream, verify, cert): """ Check the environment and merge it with some settings. :rtype: dict """ # Gather clues from the surrounding environment. if self.trust_env: # Set environment's proxies. no_proxy = proxies.get('no_proxy') if proxies is not None else None env_proxies = get_environ_proxies(url, no_proxy=no_proxy) for (k, v) in env_proxies.items(): proxies.setdefault(k, v) # Look for requests environment configuration and be compatible # with cURL. if verify is True or verify is None: verify = (os.environ.get('REQUESTS_CA_BUNDLE') or os.environ.get('CURL_CA_BUNDLE')) # Merge all the kwargs. proxies = merge_setting(proxies, self.proxies) stream = merge_setting(stream, self.stream) verify = merge_setting(verify, self.verify) cert = merge_setting(cert, self.cert) return {'verify': verify, 'proxies': proxies, 'stream': stream, 'cert': cert} def get_adapter(self, url): """ Returns the appropriate connection adapter for the given URL. :rtype: requests.adapters.BaseAdapter """ for (prefix, adapter) in self.adapters.items(): if url.lower().startswith(prefix): return adapter # Nothing matches :-/ raise InvalidSchema("No connection adapters were found for '%s'" % url) def close(self): """Closes all adapters and as such the session""" for v in self.adapters.values(): v.close() def mount(self, prefix, adapter): """Registers a connection adapter to a prefix. Adapters are sorted in descending order by prefix length. """ self.adapters[prefix] = adapter keys_to_move = [k for k in self.adapters if len(k) < len(prefix)] for key in keys_to_move: self.adapters[key] = self.adapters.pop(key) def __getstate__(self): state = dict((attr, getattr(self, attr, None)) for attr in self.__attrs__) return state def __setstate__(self, state): for attr, value in state.items(): setattr(self, attr, value) def session(): """ Returns a :class:`Session` for context-management. :rtype: Session """ return Session() sessions.pyc000064400000053544147205436720007154 0ustar00 abc@s+dZddlZddlZddlZddlmZddlmZddlm Z ddl m Z m Z m Z mZmZddlmZmZmZmZdd lmZmZmZdd lmZmZdd lmZdd lmZm Z dd l!m"Z"m#Z#m$Z$m%Z%ddl&m'Z'ddl(m)Z)ddlm*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0ddl1m2Z2ddlm3Z3ej4dkry ej5Z6Wne7k rej8Z6nXn ejZ6e dZ9e dZ:de;fdYZ<de<fdYZ=dZ>dS(s requests.session ~~~~~~~~~~~~~~~~ This module provides a Session object to manage and persist settings across requests (cookies, auth, proxies). iN(tMapping(t timedeltai(t_basic_auth_str(t cookielibtis_py3t OrderedDictturljointurlparse(tcookiejar_from_dicttextract_cookies_to_jartRequestsCookieJart merge_cookies(tRequesttPreparedRequesttDEFAULT_REDIRECT_LIMIT(t default_hookst dispatch_hook(tto_native_string(tto_key_val_listtdefault_headers(tTooManyRedirectst InvalidSchematChunkedEncodingErrortContentDecodingError(tCaseInsensitiveDict(t HTTPAdapter(t requote_uritget_environ_proxiestget_netrc_authtshould_bypass_proxiestget_auth_from_urlt rewind_bodyt DEFAULT_PORTS(tcodes(tREDIRECT_STATItWindowscCs|dkr|S|dkr |St|to;t|tsB|S|t|}|jt|g|jD]\}}|dkrt|^qt}x|D] }||=qW|S(sDetermines appropriate setting for a given request, taking into account the explicit setting on that request, and the setting in the session. If a setting is a dictionary, they will be merged together using `dict_class` N(tNonet isinstanceRRtupdatetitems(trequest_settingtsession_settingt dict_classtmerged_settingtktvt none_keystkey((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt merge_setting2s  1  cCsZ|dks!|jdgkr%|S|dksF|jdgkrJ|St|||S(sProperly merges both requests and session hooks. This is necessary because when request_hooks == {'response': []}, the merge breaks Session hooks entirely. tresponseN(R$tgetR0(t request_hookst session_hooksR*((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt merge_hooksQs !!tSessionRedirectMixincBsPeZdZdZededdedZdZdZ dZ RS(cCs?|jr;|jd}tr.|jd}nt|dSdS(s7Receives a Response. Returns a redirect URI or ``None``tlocationtlatin1tutf8N(t is_redirecttheadersRtencodeRR$(tselftrespR7((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytget_redirect_targetbs    cCst|}t|}|j|jkr.tS|jdkrn|jdkrn|jdkrn|jdkrntS|j|jk}|j|jk}tj|jddf}| r|j|kr|j|krtS|p|S(sFDecide whether Authorization header should be removed when redirectingthttpiPthttpsiN(iPN(iN( RthostnametTruetschemetportR$tFalseR R2(R=told_urltnew_urlt old_parsedt new_parsedt changed_porttchanged_schemet default_port((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytshould_strip_authxs  c ksg} |j|} x| r|j} | j|| d|_y |jWn-tttfk r~|jj dt nXt |j|j krt d|j d|n|j| jdrt|j} dt| j| f} nt| }|j} |js3t|jt| } n t| } t| | _|j| ||jtjtjfkrd}x!|D]}| jj|dqWd| _ n| j}y |d =Wnt!k rnXt"| j#||jt$| j#|j%| j&| j#|j'| |}|j(| || j)dk oVd|kpVd |k}|rlt*| n| }|r|Vq|j+|d |d |d |d|d|dt | }t"|j%| |j|j|} |VqWdS(sBReceives a Response. Returns a generator of Responses or Requests.itdecode_contentsExceeded %s redirects.R1s//s%s:%ssContent-Lengths Content-TypesTransfer-EncodingtCookietstreamttimeouttverifytcerttproxiestallow_redirectsN(sContent-Lengths Content-TypesTransfer-Encoding(,R?tcopytappendthistorytcontentRRt RuntimeErrortrawtreadRFtlent max_redirectsRtcloset startswithRturlRRDtgeturltnetlocRRtrebuild_methodt status_codeR!ttemporary_redirecttpermanent_redirectR;tpopR$tbodytKeyErrorR t_cookiesR tcookiestprepare_cookiestrebuild_proxiest rebuild_autht_body_positionRtsend(R=R>treqRQRRRSRTRUtyield_requeststadapter_kwargsthistRbtprepared_requestt parsed_rurltparsedtpurged_headerstheaderR;t rewindable((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytresolve_redirectssr                 cCs{|j}|j}d|kr@|j|jj|r@|d=n|jrUt|nd}|dk rw|j|ndS(sWhen being redirected we may want to strip authentication from the request to avoid leaking credentials. This method intelligently removes and reapplies authentication where possible to avoid credential loss. t AuthorizationN(R;RbRNtrequestt trust_envRR$t prepare_auth(R=RwR1R;Rbtnew_auth((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyRps  $  c Cs5|dk r|ni}|j}|j}t|j}|j}|jd}t|d|}|jr| rt |d|} | j|| jd} | r|j || qnd|kr|d=nyt ||\} } Wnt k rd\} } nX| r1| r1t | | |d>> import requests >>> s = requests.Session() >>> s.get('http://httpbin.org/get') Or as a context manager:: >>> with requests.Session() as s: >>> s.get('http://httpbin.org/get') R;RmtauthRUthookstparamsRSRTtprefetchtadaptersRQRR_cCst|_d|_i|_t|_i|_t|_ t |_ d|_ t |_t |_ti|_t|_|jdt|jdtdS(Nshttps://shttp://(RR;R$RRURRRRFRQRCRSRTRR_RRRmRRtmountR(R=((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt__init__js           cCs|S(N((R=((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt __enter__scGs|jdS(N(R`(R=targs((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt__exit__scCs*|jp i}t|tjs0t|}nttt|j|}|j}|jr| r|j rt |j }nt }|j d|j jd|j d|jd|jd|jdt|j|jdtdt|j|jd t||jd |d t|j|j |S( sConstructs a :class:`PreparedRequest ` for transmission and returns it. The :class:`PreparedRequest` has settings merged from the :class:`Request ` instance and those of the :class:`Session`. :param request: :class:`Request` instance to prepare with this session's settings. :rtype: requests.PreparedRequest RRbtfilestdatatjsonR;R*RRRmR(RmR%Rt CookieJarRR R RRRRbR tprepareRtupperRRRR0R;RRR5R(R=RRmtmerged_cookiesRtp((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytprepare_requests*        cCstd|jd|d|d|d|p-id|d|p?id|d |d | }|j|}| poi} |j|j| | ||}i| d 6| d 6}|j||j||}|S( sConstructs a :class:`Request `, prepares it and sends it. Returns :class:`Response ` object. :param method: method for the new :class:`Request` object. :param url: URL for the new :class:`Request` object. :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json to send in the body of the :class:`Request`. :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`. :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`. :param files: (optional) Dictionary of ``'filename': file-like-objects`` for multipart encoding upload. :param auth: (optional) Auth tuple or callable to enable Basic/Digest/Custom HTTP Auth. :param timeout: (optional) How long to wait for the server to send data before giving up, as a float, or a :ref:`(connect timeout, read timeout) ` tuple. :type timeout: float or tuple :param allow_redirects: (optional) Set to True by default. :type allow_redirects: bool :param proxies: (optional) Dictionary mapping protocol or protocol and hostname to the URL of the proxy. :param stream: (optional) whether to immediately download the response content. Defaults to ``False``. :param verify: (optional) Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use. Defaults to ``True``. :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair. :rtype: requests.Response RRbR;RRRRRRmRRRRV(R RRtmerge_environment_settingsRbR&Rr(R=RRbRRR;RmRRRRRVRURRQRSRTRRstpreptsettingst send_kwargsR>((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyRs*)       cKs#|jdt|jd||S(sSends a GET request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response RVR(RRCR(R=Rbtkwargs((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyR2scKs#|jdt|jd||S(sSends a OPTIONS request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response RVtOPTIONS(RRCR(R=RbR((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytoptions!scKs#|jdt|jd||S(sSends a HEAD request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response RVR(RRFR(R=RbR((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pythead,scKs|jd|d|d||S(sSends a POST request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response RRR(R(R=RbRRR((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytpost7s cKs|jd|d||S(sYSends a PUT request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response tPUTR(R(R=RbRR((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytputCs cKs|jd|d||S(s[Sends a PATCH request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response tPATCHR(R(R=RbRR((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytpatchNs cKs|jd||S(sSends a DELETE request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response tDELETE(R(R=RbR((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytdeleteYsc Ks|jd|j|jd|j|jd|j|jd|jt|trjtdn|jdt }|j d}|j }|j d|j }t}|j||}t|} td| |_td |||}|jr1x-|jD]} t|j| j| jq Wnt|j||j|j|||} |r{g| D]} | ^qing} | r| jd || j}| |_n|sy(t|j||d t ||_Wqtk rqXn|s|jn|S( sISend a given PreparedRequest. :rtype: requests.Response RQRSRTRUs#You can only send PreparedRequests.RVRbtsecondsR1iRt(RRQRSRTRUR%R t ValueErrorRiRCR2Rt get_adapterRbtpreferred_clockRrRtelapsedRRYR RmRR\R}tinserttnextt_nextt StopIterationRZ( R=RRRVRQRtadaptertstarttrRR>tgenRY((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyRrcsB     %  (  c Cs|jr|dk r$|jdnd}t|d|}x*|jD]\}} |j|| qIW|tks|dkrtjjdptjjd}qnt ||j }t ||j }t ||j }t ||j }i|d6|d6|d6|d6S( s^ Check the environment and merge it with some settings. :rtype: dict RtREQUESTS_CA_BUNDLEtCURL_CA_BUNDLERSRURQRTN(RR$R2RR'RRCtostenvironR0RURQRSRT( R=RbRURQRSRTRt env_proxiesR,R-((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyRs !cCsMx6|jjD]%\}}|jj|r|SqWtd|dS(s~ Returns the appropriate connection adapter for the given URL. :rtype: requests.adapters.BaseAdapter s*No connection adapters were found for '%s'N(RR'tlowerRaR(R=RbtprefixR((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyRscCs(x!|jjD]}|jqWdS(s+Closes all adapters and as such the sessionN(RtvaluesR`(R=R-((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyR`scCso||j|s(tdictt __attrs__(R=tstate((R=sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt __getstate__scCs1x*|jD]\}}t|||q WdS(N(R'tsetattr(R=RRtvalue((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt __setstate__sN(RRt__doc__RRRRRR$RCRR2RRRRRRRrRRR`RRR(((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyRQs2  7   ) D  I    cCstS(sQ Returns a :class:`Session` for context-management. :rtype: Session (R(((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytsessions(?RRtplatformttimet collectionsRtdatetimeRRRtcompatRRRRRRmRR R R tmodelsR R RRRRt_internal_utilsRtutilsRRt exceptionsRRRRt structuresRRRRRRRRRR t status_codesR!R"tsystemt perf_counterRtAttributeErrortclockR0R5tobjectR6RR(((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt s<   (""4     sessions.pyo000064400000053544147205436720007170 0ustar00 abc@s+dZddlZddlZddlZddlmZddlmZddlm Z ddl m Z m Z m Z mZmZddlmZmZmZmZdd lmZmZmZdd lmZmZdd lmZdd lmZm Z dd l!m"Z"m#Z#m$Z$m%Z%ddl&m'Z'ddl(m)Z)ddlm*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0ddl1m2Z2ddlm3Z3ej4dkry ej5Z6Wne7k rej8Z6nXn ejZ6e dZ9e dZ:de;fdYZ<de<fdYZ=dZ>dS(s requests.session ~~~~~~~~~~~~~~~~ This module provides a Session object to manage and persist settings across requests (cookies, auth, proxies). iN(tMapping(t timedeltai(t_basic_auth_str(t cookielibtis_py3t OrderedDictturljointurlparse(tcookiejar_from_dicttextract_cookies_to_jartRequestsCookieJart merge_cookies(tRequesttPreparedRequesttDEFAULT_REDIRECT_LIMIT(t default_hookst dispatch_hook(tto_native_string(tto_key_val_listtdefault_headers(tTooManyRedirectst InvalidSchematChunkedEncodingErrortContentDecodingError(tCaseInsensitiveDict(t HTTPAdapter(t requote_uritget_environ_proxiestget_netrc_authtshould_bypass_proxiestget_auth_from_urlt rewind_bodyt DEFAULT_PORTS(tcodes(tREDIRECT_STATItWindowscCs|dkr|S|dkr |St|to;t|tsB|S|t|}|jt|g|jD]\}}|dkrt|^qt}x|D] }||=qW|S(sDetermines appropriate setting for a given request, taking into account the explicit setting on that request, and the setting in the session. If a setting is a dictionary, they will be merged together using `dict_class` N(tNonet isinstanceRRtupdatetitems(trequest_settingtsession_settingt dict_classtmerged_settingtktvt none_keystkey((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt merge_setting2s  1  cCsZ|dks!|jdgkr%|S|dksF|jdgkrJ|St|||S(sProperly merges both requests and session hooks. This is necessary because when request_hooks == {'response': []}, the merge breaks Session hooks entirely. tresponseN(R$tgetR0(t request_hookst session_hooksR*((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt merge_hooksQs !!tSessionRedirectMixincBsPeZdZdZededdedZdZdZ dZ RS(cCs?|jr;|jd}tr.|jd}nt|dSdS(s7Receives a Response. Returns a redirect URI or ``None``tlocationtlatin1tutf8N(t is_redirecttheadersRtencodeRR$(tselftrespR7((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytget_redirect_targetbs    cCst|}t|}|j|jkr.tS|jdkrn|jdkrn|jdkrn|jdkrntS|j|jk}|j|jk}tj|jddf}| r|j|kr|j|krtS|p|S(sFDecide whether Authorization header should be removed when redirectingthttpiPthttpsiN(iPN(iN( RthostnametTruetschemetportR$tFalseR R2(R=told_urltnew_urlt old_parsedt new_parsedt changed_porttchanged_schemet default_port((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytshould_strip_authxs  c ksg} |j|} x| r|j} | j|| d|_y |jWn-tttfk r~|jj dt nXt |j|j krt d|j d|n|j| jdrt|j} dt| j| f} nt| }|j} |js3t|jt| } n t| } t| | _|j| ||jtjtjfkrd}x!|D]}| jj|dqWd| _ n| j}y |d =Wnt!k rnXt"| j#||jt$| j#|j%| j&| j#|j'| |}|j(| || j)dk oVd|kpVd |k}|rlt*| n| }|r|Vq|j+|d |d |d |d|d|dt | }t"|j%| |j|j|} |VqWdS(sBReceives a Response. Returns a generator of Responses or Requests.itdecode_contentsExceeded %s redirects.R1s//s%s:%ssContent-Lengths Content-TypesTransfer-EncodingtCookietstreamttimeouttverifytcerttproxiestallow_redirectsN(sContent-Lengths Content-TypesTransfer-Encoding(,R?tcopytappendthistorytcontentRRt RuntimeErrortrawtreadRFtlent max_redirectsRtcloset startswithRturlRRDtgeturltnetlocRRtrebuild_methodt status_codeR!ttemporary_redirecttpermanent_redirectR;tpopR$tbodytKeyErrorR t_cookiesR tcookiestprepare_cookiestrebuild_proxiest rebuild_autht_body_positionRtsend(R=R>treqRQRRRSRTRUtyield_requeststadapter_kwargsthistRbtprepared_requestt parsed_rurltparsedtpurged_headerstheaderR;t rewindable((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytresolve_redirectssr                 cCs{|j}|j}d|kr@|j|jj|r@|d=n|jrUt|nd}|dk rw|j|ndS(sWhen being redirected we may want to strip authentication from the request to avoid leaking credentials. This method intelligently removes and reapplies authentication where possible to avoid credential loss. t AuthorizationN(R;RbRNtrequestt trust_envRR$t prepare_auth(R=RwR1R;Rbtnew_auth((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyRps  $  c Cs5|dk r|ni}|j}|j}t|j}|j}|jd}t|d|}|jr| rt |d|} | j|| jd} | r|j || qnd|kr|d=nyt ||\} } Wnt k rd\} } nX| r1| r1t | | |d>> import requests >>> s = requests.Session() >>> s.get('http://httpbin.org/get') Or as a context manager:: >>> with requests.Session() as s: >>> s.get('http://httpbin.org/get') R;RmtauthRUthookstparamsRSRTtprefetchtadaptersRQRR_cCst|_d|_i|_t|_i|_t|_ t |_ d|_ t |_t |_ti|_t|_|jdt|jdtdS(Nshttps://shttp://(RR;R$RRURRRRFRQRCRSRTRR_RRRmRRtmountR(R=((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt__init__js           cCs|S(N((R=((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt __enter__scGs|jdS(N(R`(R=targs((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt__exit__scCs*|jp i}t|tjs0t|}nttt|j|}|j}|jr| r|j rt |j }nt }|j d|j jd|j d|jd|jd|jdt|j|jdtdt|j|jd t||jd |d t|j|j |S( sConstructs a :class:`PreparedRequest ` for transmission and returns it. The :class:`PreparedRequest` has settings merged from the :class:`Request ` instance and those of the :class:`Session`. :param request: :class:`Request` instance to prepare with this session's settings. :rtype: requests.PreparedRequest RRbtfilestdatatjsonR;R*RRRmR(RmR%Rt CookieJarRR R RRRRbR tprepareRtupperRRRR0R;RRR5R(R=RRmtmerged_cookiesRtp((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytprepare_requests*        cCstd|jd|d|d|d|p-id|d|p?id|d |d | }|j|}| poi} |j|j| | ||}i| d 6| d 6}|j||j||}|S( sConstructs a :class:`Request `, prepares it and sends it. Returns :class:`Response ` object. :param method: method for the new :class:`Request` object. :param url: URL for the new :class:`Request` object. :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json to send in the body of the :class:`Request`. :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`. :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`. :param files: (optional) Dictionary of ``'filename': file-like-objects`` for multipart encoding upload. :param auth: (optional) Auth tuple or callable to enable Basic/Digest/Custom HTTP Auth. :param timeout: (optional) How long to wait for the server to send data before giving up, as a float, or a :ref:`(connect timeout, read timeout) ` tuple. :type timeout: float or tuple :param allow_redirects: (optional) Set to True by default. :type allow_redirects: bool :param proxies: (optional) Dictionary mapping protocol or protocol and hostname to the URL of the proxy. :param stream: (optional) whether to immediately download the response content. Defaults to ``False``. :param verify: (optional) Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use. Defaults to ``True``. :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair. :rtype: requests.Response RRbR;RRRRRRmRRRRV(R RRtmerge_environment_settingsRbR&Rr(R=RRbRRR;RmRRRRRVRURRQRSRTRRstpreptsettingst send_kwargsR>((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyRs*)       cKs#|jdt|jd||S(sSends a GET request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response RVR(RRCR(R=Rbtkwargs((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyR2scKs#|jdt|jd||S(sSends a OPTIONS request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response RVtOPTIONS(RRCR(R=RbR((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytoptions!scKs#|jdt|jd||S(sSends a HEAD request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response RVR(RRFR(R=RbR((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pythead,scKs|jd|d|d||S(sSends a POST request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response RRR(R(R=RbRRR((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytpost7s cKs|jd|d||S(sYSends a PUT request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response tPUTR(R(R=RbRR((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytputCs cKs|jd|d||S(s[Sends a PATCH request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response tPATCHR(R(R=RbRR((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytpatchNs cKs|jd||S(sSends a DELETE request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response tDELETE(R(R=RbR((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytdeleteYsc Ks|jd|j|jd|j|jd|j|jd|jt|trjtdn|jdt }|j d}|j }|j d|j }t}|j||}t|} td| |_td |||}|jr1x-|jD]} t|j| j| jq Wnt|j||j|j|||} |r{g| D]} | ^qing} | r| jd || j}| |_n|sy(t|j||d t ||_Wqtk rqXn|s|jn|S( sISend a given PreparedRequest. :rtype: requests.Response RQRSRTRUs#You can only send PreparedRequests.RVRbtsecondsR1iRt(RRQRSRTRUR%R t ValueErrorRiRCR2Rt get_adapterRbtpreferred_clockRrRtelapsedRRYR RmRR\R}tinserttnextt_nextt StopIterationRZ( R=RRRVRQRtadaptertstarttrRR>tgenRY((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyRrcsB     %  (  c Cs|jr|dk r$|jdnd}t|d|}x*|jD]\}} |j|| qIW|tks|dkrtjjdptjjd}qnt ||j }t ||j }t ||j }t ||j }i|d6|d6|d6|d6S( s^ Check the environment and merge it with some settings. :rtype: dict RtREQUESTS_CA_BUNDLEtCURL_CA_BUNDLERSRURQRTN(RR$R2RR'RRCtostenvironR0RURQRSRT( R=RbRURQRSRTRt env_proxiesR,R-((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyRs !cCsMx6|jjD]%\}}|jj|r|SqWtd|dS(s~ Returns the appropriate connection adapter for the given URL. :rtype: requests.adapters.BaseAdapter s*No connection adapters were found for '%s'N(RR'tlowerRaR(R=RbtprefixR((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyRscCs(x!|jjD]}|jqWdS(s+Closes all adapters and as such the sessionN(RtvaluesR`(R=R-((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyR`scCso||j|s(tdictt __attrs__(R=tstate((R=sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt __getstate__scCs1x*|jD]\}}t|||q WdS(N(R'tsetattr(R=RRtvalue((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt __setstate__sN(RRt__doc__RRRRRR$RCRR2RRRRRRRrRRR`RRR(((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyRQs2  7   ) D  I    cCstS(sQ Returns a :class:`Session` for context-management. :rtype: Session (R(((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pytsessions(?RRtplatformttimet collectionsRtdatetimeRRRtcompatRRRRRRmRR R R tmodelsR R RRRRt_internal_utilsRtutilsRRt exceptionsRRRRt structuresRRRRRRRRRR t status_codesR!R"tsystemt perf_counterRtAttributeErrortclockR0R5tobjectR6RR(((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.pyt s<   (""4     status_codes.py000064400000006373147205436720007641 0ustar00# -*- coding: utf-8 -*- from .structures import LookupDict _codes = { # Informational. 100: ('continue',), 101: ('switching_protocols',), 102: ('processing',), 103: ('checkpoint',), 122: ('uri_too_long', 'request_uri_too_long'), 200: ('ok', 'okay', 'all_ok', 'all_okay', 'all_good', '\\o/', '✓'), 201: ('created',), 202: ('accepted',), 203: ('non_authoritative_info', 'non_authoritative_information'), 204: ('no_content',), 205: ('reset_content', 'reset'), 206: ('partial_content', 'partial'), 207: ('multi_status', 'multiple_status', 'multi_stati', 'multiple_stati'), 208: ('already_reported',), 226: ('im_used',), # Redirection. 300: ('multiple_choices',), 301: ('moved_permanently', 'moved', '\\o-'), 302: ('found',), 303: ('see_other', 'other'), 304: ('not_modified',), 305: ('use_proxy',), 306: ('switch_proxy',), 307: ('temporary_redirect', 'temporary_moved', 'temporary'), 308: ('permanent_redirect', 'resume_incomplete', 'resume',), # These 2 to be removed in 3.0 # Client Error. 400: ('bad_request', 'bad'), 401: ('unauthorized',), 402: ('payment_required', 'payment'), 403: ('forbidden',), 404: ('not_found', '-o-'), 405: ('method_not_allowed', 'not_allowed'), 406: ('not_acceptable',), 407: ('proxy_authentication_required', 'proxy_auth', 'proxy_authentication'), 408: ('request_timeout', 'timeout'), 409: ('conflict',), 410: ('gone',), 411: ('length_required',), 412: ('precondition_failed', 'precondition'), 413: ('request_entity_too_large',), 414: ('request_uri_too_large',), 415: ('unsupported_media_type', 'unsupported_media', 'media_type'), 416: ('requested_range_not_satisfiable', 'requested_range', 'range_not_satisfiable'), 417: ('expectation_failed',), 418: ('im_a_teapot', 'teapot', 'i_am_a_teapot'), 421: ('misdirected_request',), 422: ('unprocessable_entity', 'unprocessable'), 423: ('locked',), 424: ('failed_dependency', 'dependency'), 425: ('unordered_collection', 'unordered'), 426: ('upgrade_required', 'upgrade'), 428: ('precondition_required', 'precondition'), 429: ('too_many_requests', 'too_many'), 431: ('header_fields_too_large', 'fields_too_large'), 444: ('no_response', 'none'), 449: ('retry_with', 'retry'), 450: ('blocked_by_windows_parental_controls', 'parental_controls'), 451: ('unavailable_for_legal_reasons', 'legal_reasons'), 499: ('client_closed_request',), # Server Error. 500: ('internal_server_error', 'server_error', '/o\\', '✗'), 501: ('not_implemented',), 502: ('bad_gateway',), 503: ('service_unavailable', 'unavailable'), 504: ('gateway_timeout',), 505: ('http_version_not_supported', 'http_version'), 506: ('variant_also_negotiates',), 507: ('insufficient_storage',), 509: ('bandwidth_limit_exceeded', 'bandwidth'), 510: ('not_extended',), 511: ('network_authentication_required', 'network_auth', 'network_authentication'), } codes = LookupDict(name='status_codes') for code, titles in _codes.items(): for title in titles: setattr(codes, title, code) if not title.startswith(('\\', '/')): setattr(codes, title.upper(), code) status_codes.pyo000064400000011031147205436720010003 0ustar00 abc@skddlmZiDdd6dd6dd6dd 6dd 6dd6dd6dd6dd6dd6dd 6dd#6dd(6dd*6dd,6dd.6dd26dd46dd76dd96dd;6dd=6ddA6ddE6ddH6ddJ6ddM6ddO6ddR6ddU6ddW6dd[6dd^6dd`6ddb6ddd6ddg6ddi6ddk6ddo6dds6ddu6ddy6dd{6dd~6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6ZeddZxcejD]U\ZZxFeD]>Zeeeeej ds!eeej eq!q!WqWdS(i(t LookupDicttcontinueidtswitching_protocolsiet processingift checkpointigt uri_too_longtrequest_uri_too_longiztoktokaytall_oktall_okaytall_goods\o/s✓itcreateditaccepteditnon_authoritative_infotnon_authoritative_informationit no_contentit reset_contenttresetitpartial_contenttpartialit multi_statustmultiple_statust multi_statitmultiple_statiitalready_reporteditim_useditmultiple_choicesi,tmoved_permanentlytmoveds\o-i-tfoundi.t see_othertotheri/t not_modifiedi0t use_proxyi1t switch_proxyi2ttemporary_redirectttemporary_movedt temporaryi3tpermanent_redirecttresume_incompletetresumei4t bad_requesttbadit unauthorizeditpayment_requiredtpaymentit forbiddenit not_founds-o-itmethod_not_allowedt not_alloweditnot_acceptableitproxy_authentication_requiredt proxy_authtproxy_authenticationitrequest_timeoutttimeoutitconflictitgoneitlength_requireditprecondition_failedt preconditionitrequest_entity_too_largeitrequest_uri_too_largeitunsupported_media_typetunsupported_mediat media_typeitrequested_range_not_satisfiabletrequested_rangetrange_not_satisfiableitexpectation_failedit im_a_teapottteapott i_am_a_teapotitmisdirected_requestitunprocessable_entityt unprocessableitlockeditfailed_dependencyt dependencyitunordered_collectiont unordereditupgrade_requiredtupgradeitprecondition_requiredittoo_many_requeststtoo_manyitheader_fields_too_largetfields_too_largeit no_responsetnoneit retry_withtretryit$blocked_by_windows_parental_controlstparental_controlsitunavailable_for_legal_reasonst legal_reasonsitclient_closed_requestitinternal_server_errort server_errors/o\s✗itnot_implementedit bad_gatewayitservice_unavailablet unavailableitgateway_timeoutithttp_version_not_supportedt http_versionitvariant_also_negotiatesitinsufficient_storageitbandwidth_limit_exceededt bandwidthit not_extendeditnetwork_authentication_requiredt network_authtnetwork_authenticationitnamet status_codess\t/N(R(R(R(R(RR(RRR R R s\o/s✓(R (R (RR(R(RR(RR(RRRR(R(R(R(RRs\o-(R(RR (R!(R"(R#(R$R%R&(R'R(R)(R*R+(R,(R-R.(R/(R0s-o-(R1R2(R3(R4R5R6(R7R8(R9(R:(R;(R<R=(R>(R?(R@RARB(RCRDRE(RF(RGRHRI(RJ(RKRL(RM(RNRO(RPRQ(RRRS(RTR=(RURV(RWRX(RYRZ(R[R\(R]R^(R_R`(Ra(RbRcs/o\s✗(Rd(Re(RfRg(Rh(RiRj(Rk(Rl(RmRn(Ro(RpRqRr(s\Ru( t structuresRt_codestcodestitemstcodettitlesttitletsetattrt startswithtupper(((sE/usr/lib/python2.7/site-packages/pip/_vendor/requests/status_codes.pyts  structures.py000064400000005704147205436720007361 0ustar00# -*- coding: utf-8 -*- """ requests.structures ~~~~~~~~~~~~~~~~~~~ Data structures that power Requests. """ import collections from .compat import OrderedDict class CaseInsensitiveDict(collections.MutableMapping): """A case-insensitive ``dict``-like object. Implements all methods and operations of ``collections.MutableMapping`` as well as dict's ``copy``. Also provides ``lower_items``. All keys are expected to be strings. The structure remembers the case of the last key to be set, and ``iter(instance)``, ``keys()``, ``items()``, ``iterkeys()``, and ``iteritems()`` will contain case-sensitive keys. However, querying and contains testing is case insensitive:: cid = CaseInsensitiveDict() cid['Accept'] = 'application/json' cid['aCCEPT'] == 'application/json' # True list(cid) == ['Accept'] # True For example, ``headers['content-encoding']`` will return the value of a ``'Content-Encoding'`` response header, regardless of how the header name was originally stored. If the constructor, ``.update``, or equality comparison operations are given keys that have equal ``.lower()``s, the behavior is undefined. """ def __init__(self, data=None, **kwargs): self._store = OrderedDict() if data is None: data = {} self.update(data, **kwargs) def __setitem__(self, key, value): # Use the lowercased key for lookups, but store the actual # key alongside the value. self._store[key.lower()] = (key, value) def __getitem__(self, key): return self._store[key.lower()][1] def __delitem__(self, key): del self._store[key.lower()] def __iter__(self): return (casedkey for casedkey, mappedvalue in self._store.values()) def __len__(self): return len(self._store) def lower_items(self): """Like iteritems(), but with all lowercase keys.""" return ( (lowerkey, keyval[1]) for (lowerkey, keyval) in self._store.items() ) def __eq__(self, other): if isinstance(other, collections.Mapping): other = CaseInsensitiveDict(other) else: return NotImplemented # Compare insensitively return dict(self.lower_items()) == dict(other.lower_items()) # Copy is required def copy(self): return CaseInsensitiveDict(self._store.values()) def __repr__(self): return str(dict(self.items())) class LookupDict(dict): """Dictionary lookup object.""" def __init__(self, name=None): self.name = name super(LookupDict, self).__init__() def __repr__(self): return '' % (self.name) def __getitem__(self, key): # We allow fall-through here, so values default to None return self.__dict__.get(key, None) def get(self, key, default=None): return self.__dict__.get(key, default) structures.pyo000064400000012453147205436720007537 0ustar00 abc@sUdZddlZddlmZdejfdYZdefdYZdS( sO requests.structures ~~~~~~~~~~~~~~~~~~~ Data structures that power Requests. iNi(t OrderedDicttCaseInsensitiveDictcBskeZdZd dZdZdZdZdZdZ dZ dZ d Z d Z RS( sA case-insensitive ``dict``-like object. Implements all methods and operations of ``collections.MutableMapping`` as well as dict's ``copy``. Also provides ``lower_items``. All keys are expected to be strings. The structure remembers the case of the last key to be set, and ``iter(instance)``, ``keys()``, ``items()``, ``iterkeys()``, and ``iteritems()`` will contain case-sensitive keys. However, querying and contains testing is case insensitive:: cid = CaseInsensitiveDict() cid['Accept'] = 'application/json' cid['aCCEPT'] == 'application/json' # True list(cid) == ['Accept'] # True For example, ``headers['content-encoding']`` will return the value of a ``'Content-Encoding'`` response header, regardless of how the header name was originally stored. If the constructor, ``.update``, or equality comparison operations are given keys that have equal ``.lower()``s, the behavior is undefined. cKs5t|_|dkr!i}n|j||dS(N(Rt_storetNonetupdate(tselftdatatkwargs((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyt__init__*s   cCs||f|j|j<s(Rtvalues(R((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyt__iter__;scCs t|jS(N(tlenR(R((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyt__len__>scCsd|jjDS(s.Like iteritems(), but with all lowercase keys.css%|]\}}||dfVqdS(iN((Rtlowerkeytkeyval((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pys Ds(Rtitems(R((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyt lower_itemsAscCsGt|tjr!t|}ntSt|jt|jkS(N(t isinstancet collectionstMappingRtNotImplementedtdictR(Rtother((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyt__eq__IscCst|jjS(N(RRR(R((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pytcopyRscCstt|jS(N(tstrRR(R((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyt__repr__UsN(t__name__t __module__t__doc__RRR R RRRRR R!R#(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyRs        t LookupDictcBs8eZdZddZdZdZddZRS(sDictionary lookup object.cCs ||_tt|jdS(N(tnametsuperR'R(RR(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyR\s cCs d|jS(Ns (R((R((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyR#`scCs|jj|dS(N(t__dict__tgetR(RR ((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyR cscCs|jj||S(N(R*R+(RR tdefault((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyR+hsN(R$R%R&RRR#R R+(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyR'Ys    (R&RtcompatRtMutableMappingRRR'(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/structures.pyts Jutils.py000064400000066057147205436720006306 0ustar00# -*- coding: utf-8 -*- """ requests.utils ~~~~~~~~~~~~~~ This module provides utility functions that are used within Requests that are also useful for external consumption. """ import cgi import codecs import collections import contextlib import io import os import platform import re import socket import struct import warnings from .__version__ import __version__ from . import certs # to_native_string is unused here, but imported here for backwards compatibility from ._internal_utils import to_native_string from .compat import parse_http_list as _parse_list_header from .compat import ( quote, urlparse, bytes, str, OrderedDict, unquote, getproxies, proxy_bypass, urlunparse, basestring, integer_types, is_py3, proxy_bypass_environment, getproxies_environment) from .cookies import cookiejar_from_dict from .structures import CaseInsensitiveDict from .exceptions import ( InvalidURL, InvalidHeader, FileModeWarning, UnrewindableBodyError) NETRC_FILES = ('.netrc', '_netrc') DEFAULT_CA_BUNDLE_PATH = certs.where() DEFAULT_PORTS = {'http': 80, 'https': 443} if platform.system() == 'Windows': # provide a proxy_bypass version on Windows without DNS lookups def proxy_bypass_registry(host): if is_py3: import winreg else: import _winreg as winreg try: internetSettings = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'Software\Microsoft\Windows\CurrentVersion\Internet Settings') proxyEnable = winreg.QueryValueEx(internetSettings, 'ProxyEnable')[0] proxyOverride = winreg.QueryValueEx(internetSettings, 'ProxyOverride')[0] except OSError: return False if not proxyEnable or not proxyOverride: return False # make a check value list from the registry entry: replace the # '' string by the localhost entry and the corresponding # canonical entry. proxyOverride = proxyOverride.split(';') # now check if we match one of the registry values. for test in proxyOverride: if test == '': if '.' not in host: return True test = test.replace(".", r"\.") # mask dots test = test.replace("*", r".*") # change glob sequence test = test.replace("?", r".") # change glob char if re.match(test, host, re.I): return True return False def proxy_bypass(host): # noqa """Return True, if the host should be bypassed. Checks proxy settings gathered from the environment, if specified, or the registry. """ if getproxies_environment(): return proxy_bypass_environment(host) else: return proxy_bypass_registry(host) def dict_to_sequence(d): """Returns an internal sequence dictionary update.""" if hasattr(d, 'items'): d = d.items() return d def super_len(o): total_length = None current_position = 0 if hasattr(o, '__len__'): total_length = len(o) elif hasattr(o, 'len'): total_length = o.len elif hasattr(o, 'fileno'): try: fileno = o.fileno() except io.UnsupportedOperation: pass else: total_length = os.fstat(fileno).st_size # Having used fstat to determine the file length, we need to # confirm that this file was opened up in binary mode. if 'b' not in o.mode: warnings.warn(( "Requests has determined the content-length for this " "request using the binary size of the file: however, the " "file has been opened in text mode (i.e. without the 'b' " "flag in the mode). This may lead to an incorrect " "content-length. In Requests 3.0, support will be removed " "for files in text mode."), FileModeWarning ) if hasattr(o, 'tell'): try: current_position = o.tell() except (OSError, IOError): # This can happen in some weird situations, such as when the file # is actually a special file descriptor like stdin. In this # instance, we don't know what the length is, so set it to zero and # let requests chunk it instead. if total_length is not None: current_position = total_length else: if hasattr(o, 'seek') and total_length is None: # StringIO and BytesIO have seek but no useable fileno try: # seek to end of file o.seek(0, 2) total_length = o.tell() # seek back to current position to support # partially read file-like objects o.seek(current_position or 0) except (OSError, IOError): total_length = 0 if total_length is None: total_length = 0 return max(0, total_length - current_position) def get_netrc_auth(url, raise_errors=False): """Returns the Requests tuple auth for a given url from netrc.""" try: from netrc import netrc, NetrcParseError netrc_path = None for f in NETRC_FILES: try: loc = os.path.expanduser('~/{0}'.format(f)) except KeyError: # os.path.expanduser can fail when $HOME is undefined and # getpwuid fails. See http://bugs.python.org/issue20164 & # https://github.com/requests/requests/issues/1846 return if os.path.exists(loc): netrc_path = loc break # Abort early if there isn't one. if netrc_path is None: return ri = urlparse(url) # Strip port numbers from netloc. This weird `if...encode`` dance is # used for Python 3.2, which doesn't support unicode literals. splitstr = b':' if isinstance(url, str): splitstr = splitstr.decode('ascii') host = ri.netloc.split(splitstr)[0] try: _netrc = netrc(netrc_path).authenticators(host) if _netrc: # Return with login / password login_i = (0 if _netrc[0] else 1) return (_netrc[login_i], _netrc[2]) except (NetrcParseError, IOError): # If there was a parsing error or a permissions issue reading the file, # we'll just skip netrc auth unless explicitly asked to raise errors. if raise_errors: raise # AppEngine hackiness. except (ImportError, AttributeError): pass def guess_filename(obj): """Tries to guess the filename of the given object.""" name = getattr(obj, 'name', None) if (name and isinstance(name, basestring) and name[0] != '<' and name[-1] != '>'): return os.path.basename(name) def from_key_val_list(value): """Take an object and test to see if it can be represented as a dictionary. Unless it can not be represented as such, return an OrderedDict, e.g., :: >>> from_key_val_list([('key', 'val')]) OrderedDict([('key', 'val')]) >>> from_key_val_list('string') ValueError: need more than 1 value to unpack >>> from_key_val_list({'key': 'val'}) OrderedDict([('key', 'val')]) :rtype: OrderedDict """ if value is None: return None if isinstance(value, (str, bytes, bool, int)): raise ValueError('cannot encode objects that are not 2-tuples') return OrderedDict(value) def to_key_val_list(value): """Take an object and test to see if it can be represented as a dictionary. If it can be, return a list of tuples, e.g., :: >>> to_key_val_list([('key', 'val')]) [('key', 'val')] >>> to_key_val_list({'key': 'val'}) [('key', 'val')] >>> to_key_val_list('string') ValueError: cannot encode objects that are not 2-tuples. :rtype: list """ if value is None: return None if isinstance(value, (str, bytes, bool, int)): raise ValueError('cannot encode objects that are not 2-tuples') if isinstance(value, collections.Mapping): value = value.items() return list(value) # From mitsuhiko/werkzeug (used with permission). def parse_list_header(value): """Parse lists as described by RFC 2068 Section 2. In particular, parse comma-separated lists where the elements of the list may include quoted-strings. A quoted-string could contain a comma. A non-quoted string could have quotes in the middle. Quotes are removed automatically after parsing. It basically works like :func:`parse_set_header` just that items may appear multiple times and case sensitivity is preserved. The return value is a standard :class:`list`: >>> parse_list_header('token, "quoted value"') ['token', 'quoted value'] To create a header from the :class:`list` again, use the :func:`dump_header` function. :param value: a string with a list header. :return: :class:`list` :rtype: list """ result = [] for item in _parse_list_header(value): if item[:1] == item[-1:] == '"': item = unquote_header_value(item[1:-1]) result.append(item) return result # From mitsuhiko/werkzeug (used with permission). def parse_dict_header(value): """Parse lists of key, value pairs as described by RFC 2068 Section 2 and convert them into a python dict: >>> d = parse_dict_header('foo="is a fish", bar="as well"') >>> type(d) is dict True >>> sorted(d.items()) [('bar', 'as well'), ('foo', 'is a fish')] If there is no value for a key it will be `None`: >>> parse_dict_header('key_without_value') {'key_without_value': None} To create a header from the :class:`dict` again, use the :func:`dump_header` function. :param value: a string with a dict header. :return: :class:`dict` :rtype: dict """ result = {} for item in _parse_list_header(value): if '=' not in item: result[item] = None continue name, value = item.split('=', 1) if value[:1] == value[-1:] == '"': value = unquote_header_value(value[1:-1]) result[name] = value return result # From mitsuhiko/werkzeug (used with permission). def unquote_header_value(value, is_filename=False): r"""Unquotes a header value. (Reversal of :func:`quote_header_value`). This does not use the real unquoting but what browsers are actually using for quoting. :param value: the header value to unquote. :rtype: str """ if value and value[0] == value[-1] == '"': # this is not the real unquoting, but fixing this so that the # RFC is met will result in bugs with internet explorer and # probably some other browsers as well. IE for example is # uploading files with "C:\foo\bar.txt" as filename value = value[1:-1] # if this is a filename and the starting characters look like # a UNC path, then just return the value without quotes. Using the # replace sequence below on a UNC path has the effect of turning # the leading double slash into a single slash and then # _fix_ie_filename() doesn't work correctly. See #458. if not is_filename or value[:2] != '\\\\': return value.replace('\\\\', '\\').replace('\\"', '"') return value def dict_from_cookiejar(cj): """Returns a key/value dictionary from a CookieJar. :param cj: CookieJar object to extract cookies from. :rtype: dict """ cookie_dict = {} for cookie in cj: cookie_dict[cookie.name] = cookie.value return cookie_dict def add_dict_to_cookiejar(cj, cookie_dict): """Returns a CookieJar from a key/value dictionary. :param cj: CookieJar to insert cookies into. :param cookie_dict: Dict of key/values to insert into CookieJar. :rtype: CookieJar """ return cookiejar_from_dict(cookie_dict, cj) def get_encodings_from_content(content): """Returns encodings from given content string. :param content: bytestring to extract encodings from. """ warnings.warn(( 'In requests 3.0, get_encodings_from_content will be removed. For ' 'more information, please see the discussion on issue #2266. (This' ' warning should only appear once.)'), DeprecationWarning) charset_re = re.compile(r']', flags=re.I) pragma_re = re.compile(r']', flags=re.I) xml_re = re.compile(r'^<\?xml.*?encoding=["\']*(.+?)["\'>]') return (charset_re.findall(content) + pragma_re.findall(content) + xml_re.findall(content)) def get_encoding_from_headers(headers): """Returns encodings from given HTTP Header Dict. :param headers: dictionary to extract encoding from. :rtype: str """ content_type = headers.get('content-type') if not content_type: return None content_type, params = cgi.parse_header(content_type) if 'charset' in params: return params['charset'].strip("'\"") if 'text' in content_type: return 'ISO-8859-1' def stream_decode_response_unicode(iterator, r): """Stream decodes a iterator.""" if r.encoding is None: for item in iterator: yield item return decoder = codecs.getincrementaldecoder(r.encoding)(errors='replace') for chunk in iterator: rv = decoder.decode(chunk) if rv: yield rv rv = decoder.decode(b'', final=True) if rv: yield rv def iter_slices(string, slice_length): """Iterate over slices of a string.""" pos = 0 if slice_length is None or slice_length <= 0: slice_length = len(string) while pos < len(string): yield string[pos:pos + slice_length] pos += slice_length def get_unicode_from_response(r): """Returns the requested content back in unicode. :param r: Response object to get unicode content from. Tried: 1. charset from content-type 2. fall back and replace all unicode characters :rtype: str """ warnings.warn(( 'In requests 3.0, get_unicode_from_response will be removed. For ' 'more information, please see the discussion on issue #2266. (This' ' warning should only appear once.)'), DeprecationWarning) tried_encodings = [] # Try charset from content-type encoding = get_encoding_from_headers(r.headers) if encoding: try: return str(r.content, encoding) except UnicodeError: tried_encodings.append(encoding) # Fall back: try: return str(r.content, encoding, errors='replace') except TypeError: return r.content # The unreserved URI characters (RFC 3986) UNRESERVED_SET = frozenset( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + "0123456789-._~") def unquote_unreserved(uri): """Un-escape any percent-escape sequences in a URI that are unreserved characters. This leaves all reserved, illegal and non-ASCII bytes encoded. :rtype: str """ parts = uri.split('%') for i in range(1, len(parts)): h = parts[i][0:2] if len(h) == 2 and h.isalnum(): try: c = chr(int(h, 16)) except ValueError: raise InvalidURL("Invalid percent-escape sequence: '%s'" % h) if c in UNRESERVED_SET: parts[i] = c + parts[i][2:] else: parts[i] = '%' + parts[i] else: parts[i] = '%' + parts[i] return ''.join(parts) def requote_uri(uri): """Re-quote the given URI. This function passes the given URI through an unquote/quote cycle to ensure that it is fully and consistently quoted. :rtype: str """ safe_with_percent = "!#$%&'()*+,/:;=?@[]~" safe_without_percent = "!#$&'()*+,/:;=?@[]~" try: # Unquote only the unreserved characters # Then quote only illegal characters (do not quote reserved, # unreserved, or '%') return quote(unquote_unreserved(uri), safe=safe_with_percent) except InvalidURL: # We couldn't unquote the given URI, so let's try quoting it, but # there may be unquoted '%'s in the URI. We need to make sure they're # properly quoted so they do not cause issues elsewhere. return quote(uri, safe=safe_without_percent) def address_in_network(ip, net): """This function allows you to check if an IP belongs to a network subnet Example: returns True if ip = 192.168.1.1 and net = 192.168.1.0/24 returns False if ip = 192.168.1.1 and net = 192.168.100.0/24 :rtype: bool """ ipaddr = struct.unpack('=L', socket.inet_aton(ip))[0] netaddr, bits = net.split('/') netmask = struct.unpack('=L', socket.inet_aton(dotted_netmask(int(bits))))[0] network = struct.unpack('=L', socket.inet_aton(netaddr))[0] & netmask return (ipaddr & netmask) == (network & netmask) def dotted_netmask(mask): """Converts mask from /xx format to xxx.xxx.xxx.xxx Example: if mask is 24 function returns 255.255.255.0 :rtype: str """ bits = 0xffffffff ^ (1 << 32 - mask) - 1 return socket.inet_ntoa(struct.pack('>I', bits)) def is_ipv4_address(string_ip): """ :rtype: bool """ try: socket.inet_aton(string_ip) except socket.error: return False return True def is_valid_cidr(string_network): """ Very simple check of the cidr format in no_proxy variable. :rtype: bool """ if string_network.count('/') == 1: try: mask = int(string_network.split('/')[1]) except ValueError: return False if mask < 1 or mask > 32: return False try: socket.inet_aton(string_network.split('/')[0]) except socket.error: return False else: return False return True @contextlib.contextmanager def set_environ(env_name, value): """Set the environment variable 'env_name' to 'value' Save previous value, yield, and then restore the previous value stored in the environment variable 'env_name'. If 'value' is None, do nothing""" value_changed = value is not None if value_changed: old_value = os.environ.get(env_name) os.environ[env_name] = value try: yield finally: if value_changed: if old_value is None: del os.environ[env_name] else: os.environ[env_name] = old_value def should_bypass_proxies(url, no_proxy): """ Returns whether we should bypass proxies or not. :rtype: bool """ get_proxy = lambda k: os.environ.get(k) or os.environ.get(k.upper()) # First check whether no_proxy is defined. If it is, check that the URL # we're getting isn't in the no_proxy list. no_proxy_arg = no_proxy if no_proxy is None: no_proxy = get_proxy('no_proxy') netloc = urlparse(url).netloc if no_proxy: # We need to check whether we match here. We need to see if we match # the end of the netloc, both with and without the port. no_proxy = ( host for host in no_proxy.replace(' ', '').split(',') if host ) ip = netloc.split(':')[0] if is_ipv4_address(ip): for proxy_ip in no_proxy: if is_valid_cidr(proxy_ip): if address_in_network(ip, proxy_ip): return True elif ip == proxy_ip: # If no_proxy ip was defined in plain IP notation instead of cidr notation & # matches the IP of the index return True else: for host in no_proxy: if netloc.endswith(host) or netloc.split(':')[0].endswith(host): # The URL does match something in no_proxy, so we don't want # to apply the proxies on this URL. return True # If the system proxy settings indicate that this URL should be bypassed, # don't proxy. # The proxy_bypass function is incredibly buggy on OS X in early versions # of Python 2.6, so allow this call to fail. Only catch the specific # exceptions we've seen, though: this call failing in other ways can reveal # legitimate problems. with set_environ('no_proxy', no_proxy_arg): try: bypass = proxy_bypass(netloc) except (TypeError, socket.gaierror): bypass = False if bypass: return True return False def get_environ_proxies(url, no_proxy=None): """ Return a dict of environment proxies. :rtype: dict """ if should_bypass_proxies(url, no_proxy=no_proxy): return {} else: return getproxies() def select_proxy(url, proxies): """Select a proxy for the url, if applicable. :param url: The url being for the request :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs """ proxies = proxies or {} urlparts = urlparse(url) if urlparts.hostname is None: return proxies.get(urlparts.scheme, proxies.get('all')) proxy_keys = [ urlparts.scheme + '://' + urlparts.hostname, urlparts.scheme, 'all://' + urlparts.hostname, 'all', ] proxy = None for proxy_key in proxy_keys: if proxy_key in proxies: proxy = proxies[proxy_key] break return proxy def default_user_agent(name="python-requests"): """ Return a string representing the default user agent. :rtype: str """ return '%s/%s' % (name, __version__) def default_headers(): """ :rtype: requests.structures.CaseInsensitiveDict """ return CaseInsensitiveDict({ 'User-Agent': default_user_agent(), 'Accept-Encoding': ', '.join(('gzip', 'deflate')), 'Accept': '*/*', 'Connection': 'keep-alive', }) def parse_header_links(value): """Return a dict of parsed link headers proxies. i.e. Link: ; rel=front; type="image/jpeg",; rel=back;type="image/jpeg" :rtype: list """ links = [] replace_chars = ' \'"' for val in re.split(', *<', value): try: url, params = val.split(';', 1) except ValueError: url, params = val, '' link = {'url': url.strip('<> \'"')} for param in params.split(';'): try: key, value = param.split('=') except ValueError: break link[key.strip(replace_chars)] = value.strip(replace_chars) links.append(link) return links # Null bytes; no need to recreate these on each call to guess_json_utf _null = '\x00'.encode('ascii') # encoding to ASCII for Python 3 _null2 = _null * 2 _null3 = _null * 3 def guess_json_utf(data): """ :rtype: str """ # JSON always starts with two ASCII characters, so detection is as # easy as counting the nulls and from their location and count # determine the encoding. Also detect a BOM, if present. sample = data[:4] if sample in (codecs.BOM_UTF32_LE, codecs.BOM_UTF32_BE): return 'utf-32' # BOM included if sample[:3] == codecs.BOM_UTF8: return 'utf-8-sig' # BOM included, MS style (discouraged) if sample[:2] in (codecs.BOM_UTF16_LE, codecs.BOM_UTF16_BE): return 'utf-16' # BOM included nullcount = sample.count(_null) if nullcount == 0: return 'utf-8' if nullcount == 2: if sample[::2] == _null2: # 1st and 3rd are null return 'utf-16-be' if sample[1::2] == _null2: # 2nd and 4th are null return 'utf-16-le' # Did not detect 2 valid UTF-16 ascii-range characters if nullcount == 3: if sample[:3] == _null3: return 'utf-32-be' if sample[1:] == _null3: return 'utf-32-le' # Did not detect a valid UTF-32 ascii-range character return None def prepend_scheme_if_needed(url, new_scheme): """Given a URL that may or may not have a scheme, prepend the given scheme. Does not replace a present scheme with the one provided as an argument. :rtype: str """ scheme, netloc, path, params, query, fragment = urlparse(url, new_scheme) # urlparse is a finicky beast, and sometimes decides that there isn't a # netloc present. Assume that it's being over-cautious, and switch netloc # and path if urlparse decided there was no netloc. if not netloc: netloc, path = path, netloc return urlunparse((scheme, netloc, path, params, query, fragment)) def get_auth_from_url(url): """Given a url with authentication components, extract them into a tuple of username,password. :rtype: (str,str) """ parsed = urlparse(url) try: auth = (unquote(parsed.username), unquote(parsed.password)) except (AttributeError, TypeError): auth = ('', '') return auth # Moved outside of function to avoid recompile every call _CLEAN_HEADER_REGEX_BYTE = re.compile(b'^\\S[^\\r\\n]*$|^$') _CLEAN_HEADER_REGEX_STR = re.compile(r'^\S[^\r\n]*$|^$') def check_header_validity(header): """Verifies that header value is a string which doesn't contain leading whitespace or return characters. This prevents unintended header injection. :param header: tuple, in the format (name, value). """ name, value = header if isinstance(value, bytes): pat = _CLEAN_HEADER_REGEX_BYTE else: pat = _CLEAN_HEADER_REGEX_STR try: if not pat.match(value): raise InvalidHeader("Invalid return character or leading space in header: %s" % name) except TypeError: raise InvalidHeader("Value for header {%s: %s} must be of type str or " "bytes, not %s" % (name, value, type(value))) def urldefragauth(url): """ Given a url remove the fragment and the authentication part. :rtype: str """ scheme, netloc, path, params, query, fragment = urlparse(url) # see func:`prepend_scheme_if_needed` if not netloc: netloc, path = path, netloc netloc = netloc.rsplit('@', 1)[-1] return urlunparse((scheme, netloc, path, params, query, '')) def rewind_body(prepared_request): """Move file pointer back to its recorded starting position so it can be read again on redirect. """ body_seek = getattr(prepared_request.body, 'seek', None) if body_seek is not None and isinstance(prepared_request._body_position, integer_types): try: body_seek(prepared_request._body_position) except (IOError, OSError): raise UnrewindableBodyError("An error occurred when rewinding request " "body for redirect.") else: raise UnrewindableBodyError("Unable to rewind request body for redirect.") utils.pyc000064400000062046147205436720006443 0ustar00 abc@s\dZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddl mZddlmZddlmZddlmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!dd l"m#Z#dd l$m%Z%dd l&m'Z'm(Z(m)Z)m*Z*d@Z+ej,Z-idd6dd6Z.ej/dkrdZ0dZndZ1dZ2e3dZ4dZ5dZ6dZ7dZ8dZ9e3dZ:dZ;dZ<d Z=d!Z>d"Z?d#Z@d$ZAeBd%d&ZCd'ZDd(ZEd)ZFd*ZGd+ZHd,ZIejJd-ZKd.ZLdd/ZNd0ZOd1d2ZPd3ZQd4ZRd5jSd6ZTeTd7ZUeTd8ZVd9ZWd:ZXd;ZYejZd<Z[ejZd<Z\d=Z]d>Z^d?Z_dS(As requests.utils ~~~~~~~~~~~~~~ This module provides utility functions that are used within Requests that are also useful for external consumption. iNi(t __version__(tcerts(tto_native_string(tparse_http_list(tquoteturlparsetbyteststrt OrderedDicttunquotet getproxiest proxy_bypasst urlunparset basestringt integer_typestis_py3tproxy_bypass_environmenttgetproxies_environment(tcookiejar_from_dict(tCaseInsensitiveDict(t InvalidURLt InvalidHeadertFileModeWarningtUnrewindableBodyErrors.netrct_netrciPthttpithttpstWindowscCs"trddl}n ddl}yE|j|jd}|j|dd}|j|dd}Wntk rztSX| s| rtS|jd}x|D]w}|dkrd|krt Sn|j dd }|j d d }|j d d}t j ||t j rt SqWtS( Nis;Software\Microsoft\Windows\CurrentVersion\Internet Settingst ProxyEnableit ProxyOverridet;st.s\.t*s.*t?(Rtwinregt_winregtOpenKeytHKEY_CURRENT_USERt QueryValueExtOSErrortFalsetsplittTruetreplacetretmatchtI(thostR"tinternetSettingst proxyEnablet proxyOverridettest((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytproxy_bypass_registry.s2          cCs!trt|St|SdS(sReturn True, if the host should be bypassed. Checks proxy settings gathered from the environment, if specified, or the registry. N(RRR4(R/((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyR Os  cCs"t|dr|j}n|S(s/Returns an internal sequence dictionary update.titems(thasattrR5(td((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytdict_to_sequence[scCsd}d}t|dr*t|}nt|drE|j}nmt|dry|j}Wntjk rzqXtj|j}d|j krt j dt qnt|drty|j }Wn,ttfk r|dk rq|}qqqtXt|drt|dkrty3|jdd |j }|j|pIdWqqttfk rmd}qqXqtn|dkrd}ntd||S( Nit__len__tlentfilenotbs%Requests has determined the content-length for this request using the binary size of the file: however, the file has been opened in text mode (i.e. without the 'b' flag in the mode). This may lead to an incorrect content-length. In Requests 3.0, support will be removed for files in text mode.ttelltseeki(tNoneR6R:R;tiotUnsupportedOperationtostfstattst_sizetmodetwarningstwarnRR=R'tIOErrorR>tmax(tot total_lengthtcurrent_positionR;((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyt super_lends@       c CseyGddlm}m}d}x^tD]V}ytjjdj|}Wntk r_dSXtjj |r&|}Pq&q&W|dkrdSt |}d}t |t r|j d}n|jj|d} yG||j| } | r| drdnd} | | | d fSWn#|tfk rE|rFqFnXWnttfk r`nXdS( s;Returns the Requests tuple auth for a given url from netrc.i(tnetrctNetrcParseErrors~/{0}Nt:tasciiiii(RNROR?t NETRC_FILESRBtpatht expandusertformattKeyErrortexistsRt isinstanceRtdecodetnetlocR)tauthenticatorsRHt ImportErrortAttributeError( turlt raise_errorsRNROt netrc_pathtftloctritsplitstrR/Rtlogin_i((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytget_netrc_auths8    cCs[t|dd}|rWt|trW|ddkrW|ddkrWtjj|SdS(s0Tries to guess the filename of the given object.tnameitN(tgetattrR?RXR RBRStbasename(tobjRg((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytguess_filenames%cCsD|dkrdSt|ttttfr:tdnt|S(sTake an object and test to see if it can be represented as a dictionary. Unless it can not be represented as such, return an OrderedDict, e.g., :: >>> from_key_val_list([('key', 'val')]) OrderedDict([('key', 'val')]) >>> from_key_val_list('string') ValueError: need more than 1 value to unpack >>> from_key_val_list({'key': 'val'}) OrderedDict([('key', 'val')]) :rtype: OrderedDict s+cannot encode objects that are not 2-tuplesN(R?RXRRtbooltintt ValueErrorR(tvalue((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytfrom_key_val_lists  cCse|dkrdSt|ttttfr:tdnt|tjr[|j }nt |S(sTake an object and test to see if it can be represented as a dictionary. If it can be, return a list of tuples, e.g., :: >>> to_key_val_list([('key', 'val')]) [('key', 'val')] >>> to_key_val_list({'key': 'val'}) [('key', 'val')] >>> to_key_val_list('string') ValueError: cannot encode objects that are not 2-tuples. :rtype: list s+cannot encode objects that are not 2-tuplesN( R?RXRRRnRoRpt collectionstMappingR5tlist(Rq((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytto_key_val_lists cCshg}x[t|D]M}|d |dko8dknrSt|dd!}n|j|qW|S(sParse lists as described by RFC 2068 Section 2. In particular, parse comma-separated lists where the elements of the list may include quoted-strings. A quoted-string could contain a comma. A non-quoted string could have quotes in the middle. Quotes are removed automatically after parsing. It basically works like :func:`parse_set_header` just that items may appear multiple times and case sensitivity is preserved. The return value is a standard :class:`list`: >>> parse_list_header('token, "quoted value"') ['token', 'quoted value'] To create a header from the :class:`list` again, use the :func:`dump_header` function. :param value: a string with a list header. :return: :class:`list` :rtype: list iit"(t_parse_list_headertunquote_header_valuetappend(Rqtresulttitem((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytparse_list_headers $cCsi}xt|D]~}d|kr5d||>> d = parse_dict_header('foo="is a fish", bar="as well"') >>> type(d) is dict True >>> sorted(d.items()) [('bar', 'as well'), ('foo', 'is a fish')] If there is no value for a key it will be `None`: >>> parse_dict_header('key_without_value') {'key_without_value': None} To create a header from the :class:`dict` again, use the :func:`dump_header` function. :param value: a string with a dict header. :return: :class:`dict` :rtype: dict t=iiRwN(RxR?R)Ry(RqR{R|Rg((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytparse_dict_header1s  $cCsq|rm|d|dko%dknrm|dd!}| sN|d dkrm|jddjddSn|S( sUnquotes a header value. (Reversal of :func:`quote_header_value`). This does not use the real unquoting but what browsers are actually using for quoting. :param value: the header value to unquote. :rtype: str iiRwiis\\s\s\"(R+(Rqt is_filename((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyRyTs * cCs+i}x|D]}|j||j/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytdict_from_cookiejarms cCs t||S(sReturns a CookieJar from a key/value dictionary. :param cj: CookieJar to insert cookies into. :param cookie_dict: Dict of key/values to insert into CookieJar. :rtype: CookieJar (R(RR((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytadd_dict_to_cookiejar|scCsvtjdttjddtj}tjddtj}tjd}|j||j||j|S(slReturns encodings from given content string. :param content: bytestring to extract encodings from. sIn requests 3.0, get_encodings_from_content will be removed. For more information, please see the discussion on issue #2266. (This warning should only appear once.)s!]tflagss+]s$^<\?xml.*?encoding=["\']*(.+?)["\'>](RFRGtDeprecationWarningR,tcompileR.tfindall(tcontentt charset_ret pragma_retxml_re((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytget_encodings_from_contentscCs_|jd}|sdStj|\}}d|krK|djdSd|kr[dSdS(s}Returns encodings from given HTTP Header Dict. :param headers: dictionary to extract encoding from. :rtype: str s content-typetcharsets'"ttexts ISO-8859-1N(tgetR?tcgit parse_headertstrip(theaderst content_typetparams((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytget_encoding_from_headerss  ccs|jdkr)x|D] }|VqWdStj|jdd}x+|D]#}|j|}|rK|VqKqKW|jddt}|r|VndS(sStream decodes a iterator.NterrorsR+ttfinal(tencodingR?tcodecstgetincrementaldecoderRYR*(titeratortrR|tdecodertchunktrv((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytstream_decode_response_unicodes    ccsdd}|dks|dkr-t|}nx0|t|kr_||||!V||7}q0WdS(s Iterate over slices of a string.iN(R?R:(tstringt slice_lengthtpos((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyt iter_slicess cCstjdtg}t|j}|rcyt|j|SWqctk r_|j|qcXnyt|j|ddSWnt k r|jSXdS(sReturns the requested content back in unicode. :param r: Response object to get unicode content from. Tried: 1. charset from content-type 2. fall back and replace all unicode characters :rtype: str sIn requests 3.0, get_unicode_from_response will be removed. For more information, please see the discussion on issue #2266. (This warning should only appear once.)RR+N( RFRGRRRRRt UnicodeErrorRzt TypeError(Rttried_encodingsR((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytget_unicode_from_responses   t4ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzs0123456789-._~cCs|jd}xtdt|D]}||dd!}t|dkr|jrytt|d}Wn!tk rtd|nX|tkr|||d||/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytunquote_unreserveds  cCsKd}d}ytt|d|SWntk rFt|d|SXdS(sRe-quote the given URI. This function passes the given URI through an unquote/quote cycle to ensure that it is fully and consistently quoted. :rtype: str s!#$%&'()*+,/:;=?@[]~s!#$&'()*+,/:;=?@[]~tsafeN(RRR(Rtsafe_with_percenttsafe_without_percent((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyt requote_uri s  cCstjdtj|d}|jd\}}tjdtjtt|d}tjdtj|d|@}||@||@kS(sThis function allows you to check if an IP belongs to a network subnet Example: returns True if ip = 192.168.1.1 and net = 192.168.1.0/24 returns False if ip = 192.168.1.1 and net = 192.168.100.0/24 :rtype: bool s=Lit/(tstructtunpacktsockett inet_atonR)tdotted_netmaskRo(tiptnettipaddrtnetaddrtbitstnetmasktnetwork((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytaddress_in_network#s +#cCs/ddd|>dA}tjtjd|S(sConverts mask from /xx format to xxx.xxx.xxx.xxx Example: if mask is 24 function returns 255.255.255.0 :rtype: str Iii s>I(Rt inet_ntoaRtpack(tmaskR((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyR2scCs-ytj|Wntjk r(tSXtS(s :rtype: bool (RRterrorR(R*(t string_ip((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytis_ipv4_address=s cCs|jddkryt|jdd}Wntk rFtSX|dks_|dkrctSytj|jddWqtjk rtSXntStS(sV Very simple check of the cidr format in no_proxy variable. :rtype: bool Rii i( tcountRoR)RpR(RRRR*(tstring_networkR((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyt is_valid_cidrHs ccst|dk }|r4tjj|}|tj|/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyt set_environ`s    c Cscd}|}|d kr*|d}nt|j}|r d|jddjdD}|jdd}t|rx|D]8}t|rt||rtSq||krtSqWq x@|D]5}|j |s|jddj |rtSqWnt d|8yt |}Wn t t jfk rNt}nXWd QX|r_tStS( sL Returns whether we should bypass proxies or not. :rtype: bool cSs(tjj|p'tjj|jS(N(RBRRtupper(tk((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyt|Rtno_proxycss|]}|r|VqdS(N((t.0R/((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pys st Rt,RPiN(R?RRZR+R)RRRR*tendswithRR RRtgaierrorR(( R^Rt get_proxyt no_proxy_argRZRtproxy_ipR/tbypass((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytshould_bypass_proxiesvs4  %      + cCs!t|d|riStSdS(sA Return a dict of environment proxies. :rtype: dict RN(RR (R^R((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytget_environ_proxiesscCs|p i}t|}|jdkrC|j|j|jdS|jd|j|jd|jdg}d}x(|D] }||krz||}PqzqzW|S(sSelect a proxy for the url, if applicable. :param url: The url being for the request :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs talls://sall://N(RthostnameR?Rtscheme(R^tproxiesturlpartst proxy_keystproxyt proxy_key((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyt select_proxys       spython-requestscCsd|tfS(sO Return a string representing the default user agent. :rtype: str s%s/%s(R(Rg((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytdefault_user_agentscCs2titd6djd d6dd6dd 6S( s9 :rtype: requests.structures.CaseInsensitiveDict s User-Agents, tgziptdeflatesAccept-Encodings*/*tAccepts keep-alivet Connection(RR(RRR(((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytdefault_headerss  c Csg}d}xtjd|D]}y|jdd\}}Wntk ra|d}}nXi|jdd6}xa|jdD]P}y|jd\}}Wntk rPnX|j|||j|; rel=front; type="image/jpeg",; rel=back;type="image/jpeg" :rtype: list s '"s, * '"R^R~(R,R)RpRRz( Rqtlinkst replace_charstvalR^Rtlinktparamtkey((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytparse_header_linkss    sRQiicCs|d }|tjtjfkr&dS|d tjkr=dS|d tjtjfkr]dS|jt}|dkr|dS|dkr|d d dtkrd S|d d dtkrd Sn|dkr|d t krd S|d t krdSnd S(s :rtype: str isutf-32is utf-8-sigisutf-16isutf-8Ns utf-16-beis utf-16-les utf-32-bes utf-32-le( Rt BOM_UTF32_LEt BOM_UTF32_BEtBOM_UTF8t BOM_UTF16_LEt BOM_UTF16_BERt_nullt_null2t_null3R?(tdatatsamplet nullcount((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytguess_json_utfs*    cCsSt||\}}}}}}|s7||}}nt||||||fS(sGiven a URL that may or may not have a scheme, prepend the given scheme. Does not replace a present scheme with the one provided as an argument. :rtype: str (RR (R^t new_schemeRRZRSRtquerytfragment((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytprepend_scheme_if_needed1s!cCsRt|}y"t|jt|jf}Wnttfk rMd}nX|S(s{Given a url with authentication components, extract them into a tuple of username,password. :rtype: (str,str) R(RR(RR tusernametpasswordR]R(R^tparsedtauth((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytget_auth_from_urlBs  " s^\S[^\r\n]*$|^$cCs|\}}t|tr$t}nt}y&|j|sOtd|nWn0tk rtd||t|fnXdS(sVerifies that header value is a string which doesn't contain leading whitespace or return characters. This prevents unintended header injection. :param header: tuple, in the format (name, value). s7Invalid return character or leading space in header: %ss>Value for header {%s: %s} must be of type str or bytes, not %sN(RXRt_CLEAN_HEADER_REGEX_BYTEt_CLEAN_HEADER_REGEX_STRR-RRttype(theaderRgRqtpat((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytcheck_header_validityWs   cCsft|\}}}}}}|s4||}}n|jddd}t|||||dfS(sW Given a url remove the fragment and the authentication part. :rtype: str t@iiR(RtrsplitR (R^RRZRSRR R ((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyt urldefragauthls cCs}t|jdd}|dk rmt|jtrmy||jWqyttfk ritdqyXn tddS(sfMove file pointer back to its recorded starting position so it can be read again on redirect. R>s;An error occurred when rewinding request body for redirect.s+Unable to rewind request body for redirect.N( RjtbodyR?RXt_body_positionRRHR'R(tprepared_requestt body_seek((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyt rewind_body}s(s.netrcR(`t__doc__RRRst contextlibR@RBtplatformR,RRRFRRRt_internal_utilsRtcompatRRxRRRRRR R R R R RRRRtcookiesRt structuresRt exceptionsRRRRRRtwheretDEFAULT_CA_BUNDLE_PATHt DEFAULT_PORTStsystemR4R8RMR(RfRmRrRvR}RRyRRRRRRRt frozensetRRRRRRRtcontextmanagerRRR?RRRRRtencodeRRRR RRRRRRRR!(((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyt s           ^"  ! = 3    #      %      9  "      utils.pyo000064400000062046147205436720006457 0ustar00 abc@s\dZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddl mZddlmZddlmZddlmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!dd l"m#Z#dd l$m%Z%dd l&m'Z'm(Z(m)Z)m*Z*d@Z+ej,Z-idd6dd6Z.ej/dkrdZ0dZndZ1dZ2e3dZ4dZ5dZ6dZ7dZ8dZ9e3dZ:dZ;dZ<d Z=d!Z>d"Z?d#Z@d$ZAeBd%d&ZCd'ZDd(ZEd)ZFd*ZGd+ZHd,ZIejJd-ZKd.ZLdd/ZNd0ZOd1d2ZPd3ZQd4ZRd5jSd6ZTeTd7ZUeTd8ZVd9ZWd:ZXd;ZYejZd<Z[ejZd<Z\d=Z]d>Z^d?Z_dS(As requests.utils ~~~~~~~~~~~~~~ This module provides utility functions that are used within Requests that are also useful for external consumption. iNi(t __version__(tcerts(tto_native_string(tparse_http_list(tquoteturlparsetbyteststrt OrderedDicttunquotet getproxiest proxy_bypasst urlunparset basestringt integer_typestis_py3tproxy_bypass_environmenttgetproxies_environment(tcookiejar_from_dict(tCaseInsensitiveDict(t InvalidURLt InvalidHeadertFileModeWarningtUnrewindableBodyErrors.netrct_netrciPthttpithttpstWindowscCs"trddl}n ddl}yE|j|jd}|j|dd}|j|dd}Wntk rztSX| s| rtS|jd}x|D]w}|dkrd|krt Sn|j dd }|j d d }|j d d}t j ||t j rt SqWtS( Nis;Software\Microsoft\Windows\CurrentVersion\Internet Settingst ProxyEnableit ProxyOverridet;st.s\.t*s.*t?(Rtwinregt_winregtOpenKeytHKEY_CURRENT_USERt QueryValueExtOSErrortFalsetsplittTruetreplacetretmatchtI(thostR"tinternetSettingst proxyEnablet proxyOverridettest((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytproxy_bypass_registry.s2          cCs!trt|St|SdS(sReturn True, if the host should be bypassed. Checks proxy settings gathered from the environment, if specified, or the registry. N(RRR4(R/((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyR Os  cCs"t|dr|j}n|S(s/Returns an internal sequence dictionary update.titems(thasattrR5(td((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytdict_to_sequence[scCsd}d}t|dr*t|}nt|drE|j}nmt|dry|j}Wntjk rzqXtj|j}d|j krt j dt qnt|drty|j }Wn,ttfk r|dk rq|}qqqtXt|drt|dkrty3|jdd |j }|j|pIdWqqttfk rmd}qqXqtn|dkrd}ntd||S( Nit__len__tlentfilenotbs%Requests has determined the content-length for this request using the binary size of the file: however, the file has been opened in text mode (i.e. without the 'b' flag in the mode). This may lead to an incorrect content-length. In Requests 3.0, support will be removed for files in text mode.ttelltseeki(tNoneR6R:R;tiotUnsupportedOperationtostfstattst_sizetmodetwarningstwarnRR=R'tIOErrorR>tmax(tot total_lengthtcurrent_positionR;((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyt super_lends@       c CseyGddlm}m}d}x^tD]V}ytjjdj|}Wntk r_dSXtjj |r&|}Pq&q&W|dkrdSt |}d}t |t r|j d}n|jj|d} yG||j| } | r| drdnd} | | | d fSWn#|tfk rE|rFqFnXWnttfk r`nXdS( s;Returns the Requests tuple auth for a given url from netrc.i(tnetrctNetrcParseErrors~/{0}Nt:tasciiiii(RNROR?t NETRC_FILESRBtpatht expandusertformattKeyErrortexistsRt isinstanceRtdecodetnetlocR)tauthenticatorsRHt ImportErrortAttributeError( turlt raise_errorsRNROt netrc_pathtftloctritsplitstrR/Rtlogin_i((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytget_netrc_auths8    cCs[t|dd}|rWt|trW|ddkrW|ddkrWtjj|SdS(s0Tries to guess the filename of the given object.tnameitN(tgetattrR?RXR RBRStbasename(tobjRg((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytguess_filenames%cCsD|dkrdSt|ttttfr:tdnt|S(sTake an object and test to see if it can be represented as a dictionary. Unless it can not be represented as such, return an OrderedDict, e.g., :: >>> from_key_val_list([('key', 'val')]) OrderedDict([('key', 'val')]) >>> from_key_val_list('string') ValueError: need more than 1 value to unpack >>> from_key_val_list({'key': 'val'}) OrderedDict([('key', 'val')]) :rtype: OrderedDict s+cannot encode objects that are not 2-tuplesN(R?RXRRtbooltintt ValueErrorR(tvalue((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytfrom_key_val_lists  cCse|dkrdSt|ttttfr:tdnt|tjr[|j }nt |S(sTake an object and test to see if it can be represented as a dictionary. If it can be, return a list of tuples, e.g., :: >>> to_key_val_list([('key', 'val')]) [('key', 'val')] >>> to_key_val_list({'key': 'val'}) [('key', 'val')] >>> to_key_val_list('string') ValueError: cannot encode objects that are not 2-tuples. :rtype: list s+cannot encode objects that are not 2-tuplesN( R?RXRRRnRoRpt collectionstMappingR5tlist(Rq((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytto_key_val_lists cCshg}x[t|D]M}|d |dko8dknrSt|dd!}n|j|qW|S(sParse lists as described by RFC 2068 Section 2. In particular, parse comma-separated lists where the elements of the list may include quoted-strings. A quoted-string could contain a comma. A non-quoted string could have quotes in the middle. Quotes are removed automatically after parsing. It basically works like :func:`parse_set_header` just that items may appear multiple times and case sensitivity is preserved. The return value is a standard :class:`list`: >>> parse_list_header('token, "quoted value"') ['token', 'quoted value'] To create a header from the :class:`list` again, use the :func:`dump_header` function. :param value: a string with a list header. :return: :class:`list` :rtype: list iit"(t_parse_list_headertunquote_header_valuetappend(Rqtresulttitem((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytparse_list_headers $cCsi}xt|D]~}d|kr5d||>> d = parse_dict_header('foo="is a fish", bar="as well"') >>> type(d) is dict True >>> sorted(d.items()) [('bar', 'as well'), ('foo', 'is a fish')] If there is no value for a key it will be `None`: >>> parse_dict_header('key_without_value') {'key_without_value': None} To create a header from the :class:`dict` again, use the :func:`dump_header` function. :param value: a string with a dict header. :return: :class:`dict` :rtype: dict t=iiRwN(RxR?R)Ry(RqR{R|Rg((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytparse_dict_header1s  $cCsq|rm|d|dko%dknrm|dd!}| sN|d dkrm|jddjddSn|S( sUnquotes a header value. (Reversal of :func:`quote_header_value`). This does not use the real unquoting but what browsers are actually using for quoting. :param value: the header value to unquote. :rtype: str iiRwiis\\s\s\"(R+(Rqt is_filename((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyRyTs * cCs+i}x|D]}|j||j/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytdict_from_cookiejarms cCs t||S(sReturns a CookieJar from a key/value dictionary. :param cj: CookieJar to insert cookies into. :param cookie_dict: Dict of key/values to insert into CookieJar. :rtype: CookieJar (R(RR((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytadd_dict_to_cookiejar|scCsvtjdttjddtj}tjddtj}tjd}|j||j||j|S(slReturns encodings from given content string. :param content: bytestring to extract encodings from. sIn requests 3.0, get_encodings_from_content will be removed. For more information, please see the discussion on issue #2266. (This warning should only appear once.)s!]tflagss+]s$^<\?xml.*?encoding=["\']*(.+?)["\'>](RFRGtDeprecationWarningR,tcompileR.tfindall(tcontentt charset_ret pragma_retxml_re((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytget_encodings_from_contentscCs_|jd}|sdStj|\}}d|krK|djdSd|kr[dSdS(s}Returns encodings from given HTTP Header Dict. :param headers: dictionary to extract encoding from. :rtype: str s content-typetcharsets'"ttexts ISO-8859-1N(tgetR?tcgit parse_headertstrip(theaderst content_typetparams((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytget_encoding_from_headerss  ccs|jdkr)x|D] }|VqWdStj|jdd}x+|D]#}|j|}|rK|VqKqKW|jddt}|r|VndS(sStream decodes a iterator.NterrorsR+ttfinal(tencodingR?tcodecstgetincrementaldecoderRYR*(titeratortrR|tdecodertchunktrv((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytstream_decode_response_unicodes    ccsdd}|dks|dkr-t|}nx0|t|kr_||||!V||7}q0WdS(s Iterate over slices of a string.iN(R?R:(tstringt slice_lengthtpos((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyt iter_slicess cCstjdtg}t|j}|rcyt|j|SWqctk r_|j|qcXnyt|j|ddSWnt k r|jSXdS(sReturns the requested content back in unicode. :param r: Response object to get unicode content from. Tried: 1. charset from content-type 2. fall back and replace all unicode characters :rtype: str sIn requests 3.0, get_unicode_from_response will be removed. For more information, please see the discussion on issue #2266. (This warning should only appear once.)RR+N( RFRGRRRRRt UnicodeErrorRzt TypeError(Rttried_encodingsR((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytget_unicode_from_responses   t4ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzs0123456789-._~cCs|jd}xtdt|D]}||dd!}t|dkr|jrytt|d}Wn!tk rtd|nX|tkr|||d||/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytunquote_unreserveds  cCsKd}d}ytt|d|SWntk rFt|d|SXdS(sRe-quote the given URI. This function passes the given URI through an unquote/quote cycle to ensure that it is fully and consistently quoted. :rtype: str s!#$%&'()*+,/:;=?@[]~s!#$&'()*+,/:;=?@[]~tsafeN(RRR(Rtsafe_with_percenttsafe_without_percent((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyt requote_uri s  cCstjdtj|d}|jd\}}tjdtjtt|d}tjdtj|d|@}||@||@kS(sThis function allows you to check if an IP belongs to a network subnet Example: returns True if ip = 192.168.1.1 and net = 192.168.1.0/24 returns False if ip = 192.168.1.1 and net = 192.168.100.0/24 :rtype: bool s=Lit/(tstructtunpacktsockett inet_atonR)tdotted_netmaskRo(tiptnettipaddrtnetaddrtbitstnetmasktnetwork((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytaddress_in_network#s +#cCs/ddd|>dA}tjtjd|S(sConverts mask from /xx format to xxx.xxx.xxx.xxx Example: if mask is 24 function returns 255.255.255.0 :rtype: str Iii s>I(Rt inet_ntoaRtpack(tmaskR((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyR2scCs-ytj|Wntjk r(tSXtS(s :rtype: bool (RRterrorR(R*(t string_ip((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytis_ipv4_address=s cCs|jddkryt|jdd}Wntk rFtSX|dks_|dkrctSytj|jddWqtjk rtSXntStS(sV Very simple check of the cidr format in no_proxy variable. :rtype: bool Rii i( tcountRoR)RpR(RRRR*(tstring_networkR((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyt is_valid_cidrHs ccst|dk }|r4tjj|}|tj|/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyt set_environ`s    c Cscd}|}|d kr*|d}nt|j}|r d|jddjdD}|jdd}t|rx|D]8}t|rt||rtSq||krtSqWq x@|D]5}|j |s|jddj |rtSqWnt d|8yt |}Wn t t jfk rNt}nXWd QX|r_tStS( sL Returns whether we should bypass proxies or not. :rtype: bool cSs(tjj|p'tjj|jS(N(RBRRtupper(tk((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyt|Rtno_proxycss|]}|r|VqdS(N((t.0R/((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pys st Rt,RPiN(R?RRZR+R)RRRR*tendswithRR RRtgaierrorR(( R^Rt get_proxyt no_proxy_argRZRtproxy_ipR/tbypass((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytshould_bypass_proxiesvs4  %      + cCs!t|d|riStSdS(sA Return a dict of environment proxies. :rtype: dict RN(RR (R^R((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytget_environ_proxiesscCs|p i}t|}|jdkrC|j|j|jdS|jd|j|jd|jdg}d}x(|D] }||krz||}PqzqzW|S(sSelect a proxy for the url, if applicable. :param url: The url being for the request :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs talls://sall://N(RthostnameR?Rtscheme(R^tproxiesturlpartst proxy_keystproxyt proxy_key((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyt select_proxys       spython-requestscCsd|tfS(sO Return a string representing the default user agent. :rtype: str s%s/%s(R(Rg((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytdefault_user_agentscCs2titd6djd d6dd6dd 6S( s9 :rtype: requests.structures.CaseInsensitiveDict s User-Agents, tgziptdeflatesAccept-Encodings*/*tAccepts keep-alivet Connection(RR(RRR(((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytdefault_headerss  c Csg}d}xtjd|D]}y|jdd\}}Wntk ra|d}}nXi|jdd6}xa|jdD]P}y|jd\}}Wntk rPnX|j|||j|; rel=front; type="image/jpeg",; rel=back;type="image/jpeg" :rtype: list s '"s, * '"R^R~(R,R)RpRRz( Rqtlinkst replace_charstvalR^Rtlinktparamtkey((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytparse_header_linkss    sRQiicCs|d }|tjtjfkr&dS|d tjkr=dS|d tjtjfkr]dS|jt}|dkr|dS|dkr|d d dtkrd S|d d dtkrd Sn|dkr|d t krd S|d t krdSnd S(s :rtype: str isutf-32is utf-8-sigisutf-16isutf-8Ns utf-16-beis utf-16-les utf-32-bes utf-32-le( Rt BOM_UTF32_LEt BOM_UTF32_BEtBOM_UTF8t BOM_UTF16_LEt BOM_UTF16_BERt_nullt_null2t_null3R?(tdatatsamplet nullcount((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytguess_json_utfs*    cCsSt||\}}}}}}|s7||}}nt||||||fS(sGiven a URL that may or may not have a scheme, prepend the given scheme. Does not replace a present scheme with the one provided as an argument. :rtype: str (RR (R^t new_schemeRRZRSRtquerytfragment((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytprepend_scheme_if_needed1s!cCsRt|}y"t|jt|jf}Wnttfk rMd}nX|S(s{Given a url with authentication components, extract them into a tuple of username,password. :rtype: (str,str) R(RR(RR tusernametpasswordR]R(R^tparsedtauth((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytget_auth_from_urlBs  " s^\S[^\r\n]*$|^$cCs|\}}t|tr$t}nt}y&|j|sOtd|nWn0tk rtd||t|fnXdS(sVerifies that header value is a string which doesn't contain leading whitespace or return characters. This prevents unintended header injection. :param header: tuple, in the format (name, value). s7Invalid return character or leading space in header: %ss>Value for header {%s: %s} must be of type str or bytes, not %sN(RXRt_CLEAN_HEADER_REGEX_BYTEt_CLEAN_HEADER_REGEX_STRR-RRttype(theaderRgRqtpat((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pytcheck_header_validityWs   cCsft|\}}}}}}|s4||}}n|jddd}t|||||dfS(sW Given a url remove the fragment and the authentication part. :rtype: str t@iiR(RtrsplitR (R^RRZRSRR R ((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyt urldefragauthls cCs}t|jdd}|dk rmt|jtrmy||jWqyttfk ritdqyXn tddS(sfMove file pointer back to its recorded starting position so it can be read again on redirect. R>s;An error occurred when rewinding request body for redirect.s+Unable to rewind request body for redirect.N( RjtbodyR?RXt_body_positionRRHR'R(tprepared_requestt body_seek((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyt rewind_body}s(s.netrcR(`t__doc__RRRst contextlibR@RBtplatformR,RRRFRRRt_internal_utilsRtcompatRRxRRRRRR R R R R RRRRtcookiesRt structuresRt exceptionsRRRRRRtwheretDEFAULT_CA_BUNDLE_PATHt DEFAULT_PORTStsystemR4R8RMR(RfRmRrRvR}RRyRRRRRRRt frozensetRRRRRRRtcontextmanagerRRR?RRRRRtencodeRRRR RRRRRRRR!(((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/utils.pyt s           ^"  ! = 3    #      %      9  "      __init__.pyc000064400000007420147205436720007035 0ustar00 abc@stdZddlmZddlmZddlZddlmZdZyeejejWn9e e fk rej dj ejejenXdd l mZejd edd lmZmZmZmZdd lmZmZmZmZdd lmZmZddlmZddlmZddlmZmZmZddl m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(ddl)m*Z*m+Z+ddl,m-Z-ddlm.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6ddl7Z7yddl7m8Z8Wn*e9k r@de7j:fdYZ8nXe7j;e<j=e8ejde4de>dS(s Requests HTTP Library ~~~~~~~~~~~~~~~~~~~~~ Requests is an HTTP library, written in Python, for human beings. Basic GET usage: >>> import requests >>> r = requests.get('https://www.python.org') >>> r.status_code 200 >>> 'Python is a programming language' in r.content True ... or POST: >>> payload = dict(key1='value1', key2='value2') >>> r = requests.post('http://httpbin.org/post', data=payload) >>> print(r.text) { ... "form": { "key2": "value2", "key1": "value1" }, ... } The other HTTP methods are supported - see `requests.api`. Full documentation is at . :copyright: (c) 2017 by Kenneth Reitz. :license: Apache 2.0, see LICENSE for more details. i(turllib3(tchardetNi(tRequestsDependencyWarningcCs-|jd}|dgks$tt|dkrF|jdn|\}}}t|t|t|}}}|dkst|dkst|dkst|jdd \}}}t|t|t|}}}|dkst|dkst|dks)tdS( Nt.tdevit0iiii(tsplittAssertionErrortlentappendtint(turllib3_versiontchardet_versiontmajortminortpatch((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/__init__.pytcheck_compatibility1s&&sAurllib3 ({0}) or chardet ({1}) doesn't match a supported version!(tDependencyWarningtignore(t __title__t__description__t__url__t __version__(t __build__t __author__t__author_email__t __license__(t __copyright__t__cake__(tutils(tpackages(tRequesttResponsetPreparedRequest(trequesttgettheadtpostRtputtdeletetoptions(tsessiontSession(tcodes( tRequestExceptiontTimeoutt URLRequiredtTooManyRedirectst HTTPErrortConnectionErrortFileModeWarningtConnectTimeoutt ReadTimeout(t NullHandlerR5cBseZdZRS(cCsdS(N((tselftrecord((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/__init__.pytemitss(t__name__t __module__R8(((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/__init__.pyR5rstdefaultR (?t__doc__t pip._vendorRRtwarningst exceptionsRRRRt ValueErrortwarntformattpip._vendor.urllib3.exceptionsRt simplefilterRRRRRRRRRtRRtmodelsRR R!tapiR"R#R$R%RR&R'R(tsessionsR)R*t status_codesR+R,R-R.R/R0R1R2R3R4tloggingR5t ImportErrortHandlert getLoggerR9t addHandlertTrue(((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/__init__.pyt)s<    "":@  __init__.pyo000064400000007147147205436720007057 0ustar00 abc@stdZddlmZddlmZddlZddlmZdZyeejejWn9e e fk rej dj ejejenXdd l mZejd edd lmZmZmZmZdd lmZmZmZmZdd lmZmZddlmZddlmZddlmZmZmZddl m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(ddl)m*Z*m+Z+ddl,m-Z-ddlm.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6ddl7Z7yddl7m8Z8Wn*e9k r@de7j:fdYZ8nXe7j;e<j=e8ejde4de>dS(s Requests HTTP Library ~~~~~~~~~~~~~~~~~~~~~ Requests is an HTTP library, written in Python, for human beings. Basic GET usage: >>> import requests >>> r = requests.get('https://www.python.org') >>> r.status_code 200 >>> 'Python is a programming language' in r.content True ... or POST: >>> payload = dict(key1='value1', key2='value2') >>> r = requests.post('http://httpbin.org/post', data=payload) >>> print(r.text) { ... "form": { "key2": "value2", "key1": "value1" }, ... } The other HTTP methods are supported - see `requests.api`. Full documentation is at . :copyright: (c) 2017 by Kenneth Reitz. :license: Apache 2.0, see LICENSE for more details. i(turllib3(tchardetNi(tRequestsDependencyWarningcCs|jd}t|dkr1|jdn|\}}}t|t|t|}}}|jdd \}}}t|t|t|}}}dS(Nt.it0i(tsplittlentappendtint(turllib3_versiontchardet_versiontmajortminortpatch((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/__init__.pytcheck_compatibility1s&&sAurllib3 ({0}) or chardet ({1}) doesn't match a supported version!(tDependencyWarningtignore(t __title__t__description__t__url__t __version__(t __build__t __author__t__author_email__t __license__(t __copyright__t__cake__(tutils(tpackages(tRequesttResponsetPreparedRequest(trequesttgettheadtpostR tputtdeletetoptions(tsessiontSession(tcodes( tRequestExceptiontTimeoutt URLRequiredtTooManyRedirectst HTTPErrortConnectionErrortFileModeWarningtConnectTimeoutt ReadTimeout(t NullHandlerR3cBseZdZRS(cCsdS(N((tselftrecord((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/__init__.pytemitss(t__name__t __module__R6(((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/__init__.pyR3rstdefaultR(?t__doc__t pip._vendorRRtwarningst exceptionsRRRtAssertionErrort ValueErrortwarntformattpip._vendor.urllib3.exceptionsRt simplefilterRRRRRRRRRtRRtmodelsRRRtapiR R!R"R#R R$R%R&tsessionsR'R(t status_codesR)R*R+R,R-R.R/R0R1R2tloggingR3t ImportErrortHandlert getLoggerR7t addHandlertTrue(((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/__init__.pyt)s<    "":@  __version__.py000064400000000664147205436720007417 0ustar00# .-. .-. .-. . . .-. .-. .-. .-. # |( |- |.| | | |- `-. | `-. # ' ' `-' `-`.`-' `-' `-' ' `-' __title__ = 'requests' __description__ = 'Python HTTP for Humans.' __url__ = 'http://python-requests.org' __version__ = '2.18.4' __build__ = 0x021804 __author__ = 'Kenneth Reitz' __author_email__ = 'me@kennethreitz.org' __license__ = 'Apache 2.0' __copyright__ = 'Copyright 2017 Kenneth Reitz' __cake__ = u'\u2728 \U0001f370 \u2728' __version__.pyc000064400000001113147205436720007550 0ustar00 abc@s@dZdZdZdZdZdZdZdZdZd Z d S( trequestssPython HTTP for Humans.shttp://python-requests.orgs2.18.4is Kenneth Reitzsme@kennethreitz.orgs Apache 2.0sCopyright 2017 Kenneth Reitzu ✨ 🍰 ✨N( t __title__t__description__t__url__t __version__t __build__t __author__t__author_email__t __license__t __copyright__t__cake__(((sD/usr/lib/python2.7/site-packages/pip/_vendor/requests/__version__.pyts__version__.pyo000064400000001113147205436720007564 0ustar00 abc@s@dZdZdZdZdZdZdZdZdZd Z d S( trequestssPython HTTP for Humans.shttp://python-requests.orgs2.18.4is Kenneth Reitzsme@kennethreitz.orgs Apache 2.0sCopyright 2017 Kenneth Reitzu ✨ 🍰 ✨N( t __title__t__description__t__url__t __version__t __build__t __author__t__author_email__t __license__t __copyright__t__cake__(((sD/usr/lib/python2.7/site-packages/pip/_vendor/requests/__version__.pyts_internal_utils.py000064400000002110147205436720010315 0ustar00# -*- coding: utf-8 -*- """ requests._internal_utils ~~~~~~~~~~~~~~ Provides utility functions that are consumed internally by Requests which depend on extremely few external helpers (such as compat) """ from .compat import is_py2, builtin_str, str def to_native_string(string, encoding='ascii'): """Given a string object, regardless of type, returns a representation of that string in the native string type, encoding and decoding where necessary. This assumes ASCII unless told otherwise. """ if isinstance(string, builtin_str): out = string else: if is_py2: out = string.encode(encoding) else: out = string.decode(encoding) return out def unicode_is_ascii(u_string): """Determine if unicode string only contains ASCII characters. :param str u_string: unicode string to check. Must be unicode and not Python 2 `str`. :rtype: bool """ assert isinstance(u_string, str) try: u_string.encode('ascii') return True except UnicodeEncodeError: return False _internal_utils.pyc000064400000002777147205436720010503 0ustar00 abc@s;dZddlmZmZmZddZdZdS(s requests._internal_utils ~~~~~~~~~~~~~~ Provides utility functions that are consumed internally by Requests which depend on extremely few external helpers (such as compat) i(tis_py2t builtin_strtstrtasciicCsCt|tr|}n'tr0|j|}n|j|}|S(sGiven a string object, regardless of type, returns a representation of that string in the native string type, encoding and decoding where necessary. This assumes ASCII unless told otherwise. (t isinstanceRRtencodetdecode(tstringtencodingtout((sH/usr/lib/python2.7/site-packages/pip/_vendor/requests/_internal_utils.pytto_native_strings  cCsCt|tsty|jdtSWntk r>tSXdS(sDetermine if unicode string only contains ASCII characters. :param str u_string: unicode string to check. Must be unicode and not Python 2 `str`. :rtype: bool RN(RRtAssertionErrorRtTruetUnicodeEncodeErrortFalse(tu_string((sH/usr/lib/python2.7/site-packages/pip/_vendor/requests/_internal_utils.pytunicode_is_asciis   N(t__doc__tcompatRRRR R(((sH/usr/lib/python2.7/site-packages/pip/_vendor/requests/_internal_utils.pyt s _internal_utils.pyo000064400000002713147205436720010505 0ustar00 abc@s;dZddlmZmZmZddZdZdS(s requests._internal_utils ~~~~~~~~~~~~~~ Provides utility functions that are consumed internally by Requests which depend on extremely few external helpers (such as compat) i(tis_py2t builtin_strtstrtasciicCsCt|tr|}n'tr0|j|}n|j|}|S(sGiven a string object, regardless of type, returns a representation of that string in the native string type, encoding and decoding where necessary. This assumes ASCII unless told otherwise. (t isinstanceRRtencodetdecode(tstringtencodingtout((sH/usr/lib/python2.7/site-packages/pip/_vendor/requests/_internal_utils.pytto_native_strings  cCs.y|jdtSWntk r)tSXdS(sDetermine if unicode string only contains ASCII characters. :param str u_string: unicode string to check. Must be unicode and not Python 2 `str`. :rtype: bool RN(RtTruetUnicodeEncodeErrortFalse(tu_string((sH/usr/lib/python2.7/site-packages/pip/_vendor/requests/_internal_utils.pytunicode_is_asciis   N(t__doc__tcompatRRRR R(((sH/usr/lib/python2.7/site-packages/pip/_vendor/requests/_internal_utils.pyt s adapters.pyc000064400000045043147205436720007104 0ustar00 abc@s5dZddlZddlZddlmZmZddlmZddl m Z ddl m Z ddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZm Z ddl!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-m.Z.m/Z/mZmZm0Z0m1Z1ddl2m3Z3yddl4m5Z5Wne6k rdZ5nXe7Z8dZ9dZ:dZ<de=fdYZ>de>fd YZ?dS(!s requests.adapters ~~~~~~~~~~~~~~~~~ This module contains the transport adapters that Requests uses to define and maintain connections. iN(t PoolManagertproxy_from_url(t HTTPResponse(tTimeout(tRetry(tClosedPoolError(tConnectTimeoutError(t HTTPError(t MaxRetryError(tNewConnectionError(t ProxyError(t ProtocolError(tReadTimeoutError(tSSLError(t ResponseErrori(tResponse(turlparset basestring(tDEFAULT_CA_BUNDLE_PATHtget_encoding_from_headerstprepend_scheme_if_neededtget_auth_from_urlt urldefragautht select_proxy(tCaseInsensitiveDict(textract_cookies_to_jar(tConnectionErrortConnectTimeoutt ReadTimeoutR R t RetryErrort InvalidSchema(t_basic_auth_str(tSOCKSProxyManagercOstddS(Ns'Missing dependencies for SOCKS support.(R(targstkwargs((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyR +si it BaseAdaptercBs8eZdZdZededddZdZRS(sThe Base Transport AdaptercCstt|jdS(N(tsuperR#t__init__(tself((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyR%7scCs tdS(sCSends PreparedRequest object. Returns Response object. :param request: The :class:`PreparedRequest ` being sent. :param stream: (optional) Whether to stream the request content. :param timeout: (optional) How long to wait for the server to send data before giving up, as a float, or a :ref:`(connect timeout, read timeout) ` tuple. :type timeout: float or tuple :param verify: (optional) Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use :param cert: (optional) Any user-provided SSL certificate to be trusted. :param proxies: (optional) The proxies dictionary to apply to the request. N(tNotImplementedError(R&trequesttstreamttimeouttverifytcerttproxies((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pytsend:scCs tdS(s!Cleans up adapter specific items.N(R'(R&((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pytcloseLsN( t__name__t __module__t__doc__R%tFalsetNonetTrueR.R/(((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyR#4s   t HTTPAdaptercBseZdZdddddgZeeeedZdZdZ ed Z d Z d Z d Z dd ZdZdZdZdZededddZRS(sThe built-in HTTP Adapter for urllib3. Provides a general-case interface for Requests sessions to contact HTTP and HTTPS urls by implementing the Transport Adapter interface. This class will usually be created by the :class:`Session ` class under the covers. :param pool_connections: The number of urllib3 connection pools to cache. :param pool_maxsize: The maximum number of connections to save in the pool. :param max_retries: The maximum number of retries each connection should attempt. Note, this applies only to failed DNS lookups, socket connections and connection timeouts, never to requests where data has made it to the server. By default, Requests does not retry failed connections. If you need granular control over the conditions under which we retry a request, import urllib3's ``Retry`` class and pass that instead. :param pool_block: Whether the connection pool should block for connections. Usage:: >>> import requests >>> s = requests.Session() >>> a = requests.adapters.HTTPAdapter(max_retries=3) >>> s.mount('http://', a) t max_retriestconfigt_pool_connectionst _pool_maxsizet _pool_blockcCs|tkr$tddt|_ntj||_i|_i|_tt|j ||_ ||_ ||_ |j ||d|dS(Nitreadtblock(tDEFAULT_RETRIESRR3R7tfrom_intR8t proxy_managerR$R6R%R9R:R;tinit_poolmanager(R&tpool_connectionst pool_maxsizeR7t pool_block((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyR%ns      cstfdjDS(Nc3s'|]}|t|dfVqdS(N(tgetattrR4(t.0tattr(R&(sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pys s(tdictt __attrs__(R&((R&sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyt __getstate__scCsbi|_i|_x*|jD]\}}t|||qW|j|j|jd|jdS(NR=(R@R8titemstsetattrRAR9R:R;(R&tstateRGtvalue((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyt __setstate__s   c KsF||_||_||_td|d|d|dt||_dS(sInitializes a urllib3 PoolManager. This method should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter `. :param connections: The number of urllib3 connection pools to cache. :param maxsize: The maximum number of connections to save in the pool. :param block: Block when no free connections are available. :param pool_kwargs: Extra keyword arguments used to initialize the Pool Manager. t num_poolstmaxsizeR=tstrictN(R9R:R;RR5t poolmanager(R&t connectionsRQR=t pool_kwargs((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyRAs   c Ks||jkr|j|}n|jjdrt|\}}t|d|d|d|jd|jd|j|}|j|`. :param proxy: The proxy to return a urllib3 ProxyManager for. :param proxy_kwargs: Extra keyword arguments used to configure the Proxy Manager. :returns: ProxyManager :rtype: urllib3.ProxyManager tsockstusernametpasswordRPRQR=t proxy_headers( R@tlowert startswithRR R9R:R;RYR(R&tproxyt proxy_kwargstmanagerRWRXRY((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pytproxy_manager_fors*     cCs|jjdr|rd }|tk r6|}n|sEt}n| s_tjj| rwtdj |nd|_ tjj |s||_ q||_ nd|_ d |_ d |_ |rt|ts|d|_|d|_n||_d |_|jrCtjj|j rCtdj |jn|jrtjj|j rtdj |jqnd S( sAVerify a SSL certificate. This method should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter `. :param conn: The urllib3 connection object associated with the cert. :param url: The requested URL. :param verify: Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use :param cert: The SSL certificate to verify. thttpssFCould not find a suitable TLS CA certificate bundle, invalid path: {0}t CERT_REQUIREDt CERT_NONEiis:Could not find the TLS certificate file, invalid path: {0}s2Could not find the TLS key file, invalid path: {0}N(RZR[R4R5RtostpathtexiststIOErrortformatt cert_reqstisdirtca_certst ca_cert_dirt isinstanceRt cert_filetkey_file(R&tconnturlR+R,tcert_loc((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyt cert_verifys8                cCst}t|dd|_tt|di|_t|j|_||_|jj |_ t |j t r|j j d|_ n |j |_ t|j||||_||_|S(sBuilds a :class:`Response ` object from a urllib3 response. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter ` :param req: The :class:`PreparedRequest ` used to generate the response. :param resp: The urllib3 response object. :rtype: requests.Response tstatustheaderssutf-8N(RRER4t status_codeRRtRtencodingtrawtreasonRlRptbytestdecodeRtcookiesR(t connection(R&treqtresptresponse((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pytbuild_responses     cCsst||}|rEt|d}|j|}|j|}n*t|}|j}|jj|}|S(sReturns a urllib3 connection for the given URL. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter `. :param url: The URL to connect to. :param proxies: (optional) A Requests-style dictionary of proxies used on this request. :rtype: urllib3.ConnectionPool thttp(RRR_tconnection_from_urlRtgeturlRS(R&RpR-R\R@Rotparsed((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pytget_connection"s   cCs5|jjx!|jjD]}|jqWdS(sDisposes of any internal state. Currently, this closes the PoolManager and any active ProxyManager, which closes any pooled connections. N(RStclearR@tvalues(R&R\((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyR/9s c Cst|j|}t|jj}|o3|dk}t}|rit|jj}|jd}n|j}|r| rt|j}n|S(s?Obtain the url to use when making the final request. If the message is being sent through a HTTP proxy, the full URL has to be used. Otherwise, we should only use the path portion of the URL. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter `. :param request: The :class:`PreparedRequest ` being sent. :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs. :rtype: str R`RV( RRpRtschemeR3RZR[tpath_urlR( R&R(R-R\Rtis_proxied_http_requesttusing_socks_proxyt proxy_schemeRp((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyt request_urlCs  cKsdS(s"Add any headers needed by the connection. As of v2.0 this does nothing by default, but is left for overriding by users that subclass the :class:`HTTPAdapter `. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter `. :param request: The :class:`PreparedRequest ` to add headers to. :param kwargs: The keyword arguments from the call to send(). N((R&R(R"((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyt add_headers`s cCs8i}t|\}}|r4t|||d`. :param proxies: The url of the proxy being used for this request. :rtype: dict sProxy-Authorization(RR(R&R\RtRWRX((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyRYns cCs}|j|j|}|j||j|||j||}|j||jdkphd|jk } t|t ry%|\} } t d| d| }Wqt k r} dj |} t | qXn't|t rnt d|d|}y| s[|j d|jd|d|jd|jd td td td td |jd| }nft|drv|j}n|jdt}y"|j|j|dtx-|jjD]\}}|j||qW|jx^|jD]S}|jtt|djd|jd|j||jdqW|jdy|jdt}Wntk r|j}nXt j!|d|d|d td t}Wn|j"nXWnt#t$j%fk r} t&| d|n{t'k r} t| j(t)r=t| j(t*s=t+| d|q=nt| j(t,rdt-| d|nt| j(t.rt/| d|nt| j(t0rt1| d|nt&| d|nt2k r} t&| d|nt.k r } t/| ndt0t3fk rl} t| t0rBt1| d|qmt| t4rft5| d|qmnX|j6||S(sSends PreparedRequest object. Returns Response object. :param request: The :class:`PreparedRequest ` being sent. :param stream: (optional) Whether to stream the request content. :param timeout: (optional) How long to wait for the server to send data before giving up, as a float, or a :ref:`(connect timeout, read timeout) ` tuple. :type timeout: float or tuple or urllib3 Timeout object :param verify: (optional) Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use :param cert: (optional) Any user-provided SSL certificate to be trusted. :param proxies: (optional) The proxies dictionary to apply to the request. :rtype: requests.Response sContent-LengthtconnectR<ssInvalid timeout {0}. Pass a (connect, read) timeout tuple, or a single float to set both timeouts to the same valuetmethodRptbodyRttredirecttassert_same_hosttpreload_contenttdecode_contenttretriesR*t proxy_pooltskip_accept_encodingisutf-8s s0 t bufferingtpoolR|R(N(7RRpRrRRRR4RtRlttuplet TimeoutSaucet ValueErrorRgturlopenRR3R7thasattrRt _get_conntDEFAULT_POOL_TIMEOUTt putrequestR5RKt putheadert endheadersR.thextlentencodet getresponset TypeErrorRt from_httplibR/R tsocketterrorRRRxRR RRRt _ProxyErrorR t _SSLErrorR Rt _HTTPErrorR RR(R&R(R)R*R+R,R-RoRptchunkedRR<teterrR~tlow_conntheaderRNtitr((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyR.s            &       N(R0R1R2RItDEFAULT_POOLSIZER>tDEFAULT_POOLBLOCKR%RJRORAR_RrRR4RR/RRRYR3R5R.(((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyR6Qs$      % 4 %    (@R2tos.pathRcRtpip._vendor.urllib3.poolmanagerRRtpip._vendor.urllib3.responseRtpip._vendor.urllib3.utilRRtpip._vendor.urllib3.util.retryRtpip._vendor.urllib3.exceptionsRRRRRR R RR R R RRtmodelsRtcompatRRtutilsRRRRRRt structuresRR{Rt exceptionsRRRRRtauthRt!pip._vendor.urllib3.contrib.socksR t ImportErrorR3RRR>R4RtobjectR#R6(((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyt sB  .4  adapters.pyo000064400000045043147205436720007120 0ustar00 abc@s5dZddlZddlZddlmZmZddlmZddl m Z ddl m Z ddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZm Z ddl!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-m.Z.m/Z/mZmZm0Z0m1Z1ddl2m3Z3yddl4m5Z5Wne6k rdZ5nXe7Z8dZ9dZ:dZ<de=fdYZ>de>fd YZ?dS(!s requests.adapters ~~~~~~~~~~~~~~~~~ This module contains the transport adapters that Requests uses to define and maintain connections. iN(t PoolManagertproxy_from_url(t HTTPResponse(tTimeout(tRetry(tClosedPoolError(tConnectTimeoutError(t HTTPError(t MaxRetryError(tNewConnectionError(t ProxyError(t ProtocolError(tReadTimeoutError(tSSLError(t ResponseErrori(tResponse(turlparset basestring(tDEFAULT_CA_BUNDLE_PATHtget_encoding_from_headerstprepend_scheme_if_neededtget_auth_from_urlt urldefragautht select_proxy(tCaseInsensitiveDict(textract_cookies_to_jar(tConnectionErrortConnectTimeoutt ReadTimeoutR R t RetryErrort InvalidSchema(t_basic_auth_str(tSOCKSProxyManagercOstddS(Ns'Missing dependencies for SOCKS support.(R(targstkwargs((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyR +si it BaseAdaptercBs8eZdZdZededddZdZRS(sThe Base Transport AdaptercCstt|jdS(N(tsuperR#t__init__(tself((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyR%7scCs tdS(sCSends PreparedRequest object. Returns Response object. :param request: The :class:`PreparedRequest ` being sent. :param stream: (optional) Whether to stream the request content. :param timeout: (optional) How long to wait for the server to send data before giving up, as a float, or a :ref:`(connect timeout, read timeout) ` tuple. :type timeout: float or tuple :param verify: (optional) Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use :param cert: (optional) Any user-provided SSL certificate to be trusted. :param proxies: (optional) The proxies dictionary to apply to the request. N(tNotImplementedError(R&trequesttstreamttimeouttverifytcerttproxies((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pytsend:scCs tdS(s!Cleans up adapter specific items.N(R'(R&((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pytcloseLsN( t__name__t __module__t__doc__R%tFalsetNonetTrueR.R/(((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyR#4s   t HTTPAdaptercBseZdZdddddgZeeeedZdZdZ ed Z d Z d Z d Z dd ZdZdZdZdZededddZRS(sThe built-in HTTP Adapter for urllib3. Provides a general-case interface for Requests sessions to contact HTTP and HTTPS urls by implementing the Transport Adapter interface. This class will usually be created by the :class:`Session ` class under the covers. :param pool_connections: The number of urllib3 connection pools to cache. :param pool_maxsize: The maximum number of connections to save in the pool. :param max_retries: The maximum number of retries each connection should attempt. Note, this applies only to failed DNS lookups, socket connections and connection timeouts, never to requests where data has made it to the server. By default, Requests does not retry failed connections. If you need granular control over the conditions under which we retry a request, import urllib3's ``Retry`` class and pass that instead. :param pool_block: Whether the connection pool should block for connections. Usage:: >>> import requests >>> s = requests.Session() >>> a = requests.adapters.HTTPAdapter(max_retries=3) >>> s.mount('http://', a) t max_retriestconfigt_pool_connectionst _pool_maxsizet _pool_blockcCs|tkr$tddt|_ntj||_i|_i|_tt|j ||_ ||_ ||_ |j ||d|dS(Nitreadtblock(tDEFAULT_RETRIESRR3R7tfrom_intR8t proxy_managerR$R6R%R9R:R;tinit_poolmanager(R&tpool_connectionst pool_maxsizeR7t pool_block((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyR%ns      cstfdjDS(Nc3s'|]}|t|dfVqdS(N(tgetattrR4(t.0tattr(R&(sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pys s(tdictt __attrs__(R&((R&sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyt __getstate__scCsbi|_i|_x*|jD]\}}t|||qW|j|j|jd|jdS(NR=(R@R8titemstsetattrRAR9R:R;(R&tstateRGtvalue((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyt __setstate__s   c KsF||_||_||_td|d|d|dt||_dS(sInitializes a urllib3 PoolManager. This method should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter `. :param connections: The number of urllib3 connection pools to cache. :param maxsize: The maximum number of connections to save in the pool. :param block: Block when no free connections are available. :param pool_kwargs: Extra keyword arguments used to initialize the Pool Manager. t num_poolstmaxsizeR=tstrictN(R9R:R;RR5t poolmanager(R&t connectionsRQR=t pool_kwargs((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyRAs   c Ks||jkr|j|}n|jjdrt|\}}t|d|d|d|jd|jd|j|}|j|`. :param proxy: The proxy to return a urllib3 ProxyManager for. :param proxy_kwargs: Extra keyword arguments used to configure the Proxy Manager. :returns: ProxyManager :rtype: urllib3.ProxyManager tsockstusernametpasswordRPRQR=t proxy_headers( R@tlowert startswithRR R9R:R;RYR(R&tproxyt proxy_kwargstmanagerRWRXRY((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pytproxy_manager_fors*     cCs|jjdr|rd }|tk r6|}n|sEt}n| s_tjj| rwtdj |nd|_ tjj |s||_ q||_ nd|_ d |_ d |_ |rt|ts|d|_|d|_n||_d |_|jrCtjj|j rCtdj |jn|jrtjj|j rtdj |jqnd S( sAVerify a SSL certificate. This method should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter `. :param conn: The urllib3 connection object associated with the cert. :param url: The requested URL. :param verify: Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use :param cert: The SSL certificate to verify. thttpssFCould not find a suitable TLS CA certificate bundle, invalid path: {0}t CERT_REQUIREDt CERT_NONEiis:Could not find the TLS certificate file, invalid path: {0}s2Could not find the TLS key file, invalid path: {0}N(RZR[R4R5RtostpathtexiststIOErrortformatt cert_reqstisdirtca_certst ca_cert_dirt isinstanceRt cert_filetkey_file(R&tconnturlR+R,tcert_loc((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyt cert_verifys8                cCst}t|dd|_tt|di|_t|j|_||_|jj |_ t |j t r|j j d|_ n |j |_ t|j||||_||_|S(sBuilds a :class:`Response ` object from a urllib3 response. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter ` :param req: The :class:`PreparedRequest ` used to generate the response. :param resp: The urllib3 response object. :rtype: requests.Response tstatustheaderssutf-8N(RRER4t status_codeRRtRtencodingtrawtreasonRlRptbytestdecodeRtcookiesR(t connection(R&treqtresptresponse((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pytbuild_responses     cCsst||}|rEt|d}|j|}|j|}n*t|}|j}|jj|}|S(sReturns a urllib3 connection for the given URL. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter `. :param url: The URL to connect to. :param proxies: (optional) A Requests-style dictionary of proxies used on this request. :rtype: urllib3.ConnectionPool thttp(RRR_tconnection_from_urlRtgeturlRS(R&RpR-R\R@Rotparsed((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pytget_connection"s   cCs5|jjx!|jjD]}|jqWdS(sDisposes of any internal state. Currently, this closes the PoolManager and any active ProxyManager, which closes any pooled connections. N(RStclearR@tvalues(R&R\((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyR/9s c Cst|j|}t|jj}|o3|dk}t}|rit|jj}|jd}n|j}|r| rt|j}n|S(s?Obtain the url to use when making the final request. If the message is being sent through a HTTP proxy, the full URL has to be used. Otherwise, we should only use the path portion of the URL. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter `. :param request: The :class:`PreparedRequest ` being sent. :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs. :rtype: str R`RV( RRpRtschemeR3RZR[tpath_urlR( R&R(R-R\Rtis_proxied_http_requesttusing_socks_proxyt proxy_schemeRp((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyt request_urlCs  cKsdS(s"Add any headers needed by the connection. As of v2.0 this does nothing by default, but is left for overriding by users that subclass the :class:`HTTPAdapter `. This should not be called from user code, and is only exposed for use when subclassing the :class:`HTTPAdapter `. :param request: The :class:`PreparedRequest ` to add headers to. :param kwargs: The keyword arguments from the call to send(). N((R&R(R"((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyt add_headers`s cCs8i}t|\}}|r4t|||d`. :param proxies: The url of the proxy being used for this request. :rtype: dict sProxy-Authorization(RR(R&R\RtRWRX((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyRYns cCs}|j|j|}|j||j|||j||}|j||jdkphd|jk } t|t ry%|\} } t d| d| }Wqt k r} dj |} t | qXn't|t rnt d|d|}y| s[|j d|jd|d|jd|jd td td td td |jd| }nft|drv|j}n|jdt}y"|j|j|dtx-|jjD]\}}|j||qW|jx^|jD]S}|jtt|djd|jd|j||jdqW|jdy|jdt}Wntk r|j}nXt j!|d|d|d td t}Wn|j"nXWnt#t$j%fk r} t&| d|n{t'k r} t| j(t)r=t| j(t*s=t+| d|q=nt| j(t,rdt-| d|nt| j(t.rt/| d|nt| j(t0rt1| d|nt&| d|nt2k r} t&| d|nt.k r } t/| ndt0t3fk rl} t| t0rBt1| d|qmt| t4rft5| d|qmnX|j6||S(sSends PreparedRequest object. Returns Response object. :param request: The :class:`PreparedRequest ` being sent. :param stream: (optional) Whether to stream the request content. :param timeout: (optional) How long to wait for the server to send data before giving up, as a float, or a :ref:`(connect timeout, read timeout) ` tuple. :type timeout: float or tuple or urllib3 Timeout object :param verify: (optional) Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use :param cert: (optional) Any user-provided SSL certificate to be trusted. :param proxies: (optional) The proxies dictionary to apply to the request. :rtype: requests.Response sContent-LengthtconnectR<ssInvalid timeout {0}. Pass a (connect, read) timeout tuple, or a single float to set both timeouts to the same valuetmethodRptbodyRttredirecttassert_same_hosttpreload_contenttdecode_contenttretriesR*t proxy_pooltskip_accept_encodingisutf-8s s0 t bufferingtpoolR|R(N(7RRpRrRRRR4RtRlttuplet TimeoutSaucet ValueErrorRgturlopenRR3R7thasattrRt _get_conntDEFAULT_POOL_TIMEOUTt putrequestR5RKt putheadert endheadersR.thextlentencodet getresponset TypeErrorRt from_httplibR/R tsocketterrorRRRxRR RRRt _ProxyErrorR t _SSLErrorR Rt _HTTPErrorR RR(R&R(R)R*R+R,R-RoRptchunkedRR<teterrR~tlow_conntheaderRNtitr((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyR.s            &       N(R0R1R2RItDEFAULT_POOLSIZER>tDEFAULT_POOLBLOCKR%RJRORAR_RrRR4RR/RRRYR3R5R.(((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyR6Qs$      % 4 %    (@R2tos.pathRcRtpip._vendor.urllib3.poolmanagerRRtpip._vendor.urllib3.responseRtpip._vendor.urllib3.utilRRtpip._vendor.urllib3.util.retryRtpip._vendor.urllib3.exceptionsRRRRRR R RR R R RRtmodelsRtcompatRRtutilsRRRRRRt structuresRR{Rt exceptionsRRRRRtauthRt!pip._vendor.urllib3.contrib.socksR t ImportErrorR3RRR>R4RtobjectR#R6(((sA/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.pyt sB  .4  api.py000064400000014135147205436720005705 0ustar00# -*- coding: utf-8 -*- """ requests.api ~~~~~~~~~~~~ This module implements the Requests API. :copyright: (c) 2012 by Kenneth Reitz. :license: Apache2, see LICENSE for more details. """ from . import sessions def request(method, url, **kwargs): """Constructs and sends a :class:`Request `. :param method: method for the new :class:`Request` object. :param url: URL for the new :class:`Request` object. :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`. :param data: (optional) Dictionary or list of tuples ``[(key, value)]`` (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json data to send in the body of the :class:`Request`. :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`. :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`. :param files: (optional) Dictionary of ``'name': file-like-objects`` (or ``{'name': file-tuple}``) for multipart encoding upload. ``file-tuple`` can be a 2-tuple ``('filename', fileobj)``, 3-tuple ``('filename', fileobj, 'content_type')`` or a 4-tuple ``('filename', fileobj, 'content_type', custom_headers)``, where ``'content-type'`` is a string defining the content type of the given file and ``custom_headers`` a dict-like object containing additional headers to add for the file. :param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth. :param timeout: (optional) How many seconds to wait for the server to send data before giving up, as a float, or a :ref:`(connect timeout, read timeout) ` tuple. :type timeout: float or tuple :param allow_redirects: (optional) Boolean. Enable/disable GET/OPTIONS/POST/PUT/PATCH/DELETE/HEAD redirection. Defaults to ``True``. :type allow_redirects: bool :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy. :param verify: (optional) Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use. Defaults to ``True``. :param stream: (optional) if ``False``, the response content will be immediately downloaded. :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair. :return: :class:`Response ` object :rtype: requests.Response Usage:: >>> import requests >>> req = requests.request('GET', 'http://httpbin.org/get') """ # By using the 'with' statement we are sure the session is closed, thus we # avoid leaving sockets open which can trigger a ResourceWarning in some # cases, and look like a memory leak in others. with sessions.Session() as session: return session.request(method=method, url=url, **kwargs) def get(url, params=None, **kwargs): r"""Sends a GET request. :param url: URL for the new :class:`Request` object. :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response ` object :rtype: requests.Response """ kwargs.setdefault('allow_redirects', True) return request('get', url, params=params, **kwargs) def options(url, **kwargs): r"""Sends an OPTIONS request. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response ` object :rtype: requests.Response """ kwargs.setdefault('allow_redirects', True) return request('options', url, **kwargs) def head(url, **kwargs): r"""Sends a HEAD request. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response ` object :rtype: requests.Response """ kwargs.setdefault('allow_redirects', False) return request('head', url, **kwargs) def post(url, data=None, json=None, **kwargs): r"""Sends a POST request. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json data to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response ` object :rtype: requests.Response """ return request('post', url, data=data, json=json, **kwargs) def put(url, data=None, **kwargs): r"""Sends a PUT request. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json data to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response ` object :rtype: requests.Response """ return request('put', url, data=data, **kwargs) def patch(url, data=None, **kwargs): r"""Sends a PATCH request. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json data to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response ` object :rtype: requests.Response """ return request('patch', url, data=data, **kwargs) def delete(url, **kwargs): r"""Sends a DELETE request. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response ` object :rtype: requests.Response """ return request('delete', url, **kwargs) api.pyc000064400000015624147205436720006054 0ustar00 abc@sqdZddlmZdZd dZdZdZd d dZd dZ d d Z d Z d S( s requests.api ~~~~~~~~~~~~ This module implements the Requests API. :copyright: (c) 2012 by Kenneth Reitz. :license: Apache2, see LICENSE for more details. i(tsessionsc Ks2tj }|jd|d||SWdQXdS(s Constructs and sends a :class:`Request `. :param method: method for the new :class:`Request` object. :param url: URL for the new :class:`Request` object. :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`. :param data: (optional) Dictionary or list of tuples ``[(key, value)]`` (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json data to send in the body of the :class:`Request`. :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`. :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`. :param files: (optional) Dictionary of ``'name': file-like-objects`` (or ``{'name': file-tuple}``) for multipart encoding upload. ``file-tuple`` can be a 2-tuple ``('filename', fileobj)``, 3-tuple ``('filename', fileobj, 'content_type')`` or a 4-tuple ``('filename', fileobj, 'content_type', custom_headers)``, where ``'content-type'`` is a string defining the content type of the given file and ``custom_headers`` a dict-like object containing additional headers to add for the file. :param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth. :param timeout: (optional) How many seconds to wait for the server to send data before giving up, as a float, or a :ref:`(connect timeout, read timeout) ` tuple. :type timeout: float or tuple :param allow_redirects: (optional) Boolean. Enable/disable GET/OPTIONS/POST/PUT/PATCH/DELETE/HEAD redirection. Defaults to ``True``. :type allow_redirects: bool :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy. :param verify: (optional) Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use. Defaults to ``True``. :param stream: (optional) if ``False``, the response content will be immediately downloaded. :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair. :return: :class:`Response ` object :rtype: requests.Response Usage:: >>> import requests >>> req = requests.request('GET', 'http://httpbin.org/get') tmethodturlN(RtSessiontrequest(RRtkwargstsession((s</usr/lib/python2.7/site-packages/pip/_vendor/requests/api.pyRs)cKs&|jdttd|d||S(sOSends a GET request. :param url: URL for the new :class:`Request` object. :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response ` object :rtype: requests.Response tallow_redirectstgettparams(t setdefaulttTrueR(RR R((s</usr/lib/python2.7/site-packages/pip/_vendor/requests/api.pyR=s cKs |jdttd||S(sSends an OPTIONS request. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response ` object :rtype: requests.Response Rtoptions(R R R(RR((s</usr/lib/python2.7/site-packages/pip/_vendor/requests/api.pyR Ks cKs |jdttd||S(sSends a HEAD request. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response ` object :rtype: requests.Response Rthead(R tFalseR(RR((s</usr/lib/python2.7/site-packages/pip/_vendor/requests/api.pyR Xs cKstd|d|d||S(sSends a POST request. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json data to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response ` object :rtype: requests.Response tposttdatatjson(R(RRRR((s</usr/lib/python2.7/site-packages/pip/_vendor/requests/api.pyRes cKstd|d||S(sSends a PUT request. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json data to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response ` object :rtype: requests.Response tputR(R(RRR((s</usr/lib/python2.7/site-packages/pip/_vendor/requests/api.pyRss cKstd|d||S(sSends a PATCH request. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json data to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response ` object :rtype: requests.Response tpatchR(R(RRR((s</usr/lib/python2.7/site-packages/pip/_vendor/requests/api.pyRs cKstd||S(sSends a DELETE request. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response ` object :rtype: requests.Response tdelete(R(RR((s</usr/lib/python2.7/site-packages/pip/_vendor/requests/api.pyRs N( t__doc__tRRtNoneRR R RRRR(((s</usr/lib/python2.7/site-packages/pip/_vendor/requests/api.pyt s -    api.pyo000064400000015624147205436720006070 0ustar00 abc@sqdZddlmZdZd dZdZdZd d dZd dZ d d Z d Z d S( s requests.api ~~~~~~~~~~~~ This module implements the Requests API. :copyright: (c) 2012 by Kenneth Reitz. :license: Apache2, see LICENSE for more details. i(tsessionsc Ks2tj }|jd|d||SWdQXdS(s Constructs and sends a :class:`Request `. :param method: method for the new :class:`Request` object. :param url: URL for the new :class:`Request` object. :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`. :param data: (optional) Dictionary or list of tuples ``[(key, value)]`` (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json data to send in the body of the :class:`Request`. :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`. :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`. :param files: (optional) Dictionary of ``'name': file-like-objects`` (or ``{'name': file-tuple}``) for multipart encoding upload. ``file-tuple`` can be a 2-tuple ``('filename', fileobj)``, 3-tuple ``('filename', fileobj, 'content_type')`` or a 4-tuple ``('filename', fileobj, 'content_type', custom_headers)``, where ``'content-type'`` is a string defining the content type of the given file and ``custom_headers`` a dict-like object containing additional headers to add for the file. :param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth. :param timeout: (optional) How many seconds to wait for the server to send data before giving up, as a float, or a :ref:`(connect timeout, read timeout) ` tuple. :type timeout: float or tuple :param allow_redirects: (optional) Boolean. Enable/disable GET/OPTIONS/POST/PUT/PATCH/DELETE/HEAD redirection. Defaults to ``True``. :type allow_redirects: bool :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy. :param verify: (optional) Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use. Defaults to ``True``. :param stream: (optional) if ``False``, the response content will be immediately downloaded. :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair. :return: :class:`Response ` object :rtype: requests.Response Usage:: >>> import requests >>> req = requests.request('GET', 'http://httpbin.org/get') tmethodturlN(RtSessiontrequest(RRtkwargstsession((s</usr/lib/python2.7/site-packages/pip/_vendor/requests/api.pyRs)cKs&|jdttd|d||S(sOSends a GET request. :param url: URL for the new :class:`Request` object. :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response ` object :rtype: requests.Response tallow_redirectstgettparams(t setdefaulttTrueR(RR R((s</usr/lib/python2.7/site-packages/pip/_vendor/requests/api.pyR=s cKs |jdttd||S(sSends an OPTIONS request. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response ` object :rtype: requests.Response Rtoptions(R R R(RR((s</usr/lib/python2.7/site-packages/pip/_vendor/requests/api.pyR Ks cKs |jdttd||S(sSends a HEAD request. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response ` object :rtype: requests.Response Rthead(R tFalseR(RR((s</usr/lib/python2.7/site-packages/pip/_vendor/requests/api.pyR Xs cKstd|d|d||S(sSends a POST request. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json data to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response ` object :rtype: requests.Response tposttdatatjson(R(RRRR((s</usr/lib/python2.7/site-packages/pip/_vendor/requests/api.pyRes cKstd|d||S(sSends a PUT request. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json data to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response ` object :rtype: requests.Response tputR(R(RRR((s</usr/lib/python2.7/site-packages/pip/_vendor/requests/api.pyRss cKstd|d||S(sSends a PATCH request. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json data to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response ` object :rtype: requests.Response tpatchR(R(RRR((s</usr/lib/python2.7/site-packages/pip/_vendor/requests/api.pyRs cKstd||S(sSends a DELETE request. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response ` object :rtype: requests.Response tdelete(R(RR((s</usr/lib/python2.7/site-packages/pip/_vendor/requests/api.pyRs N( t__doc__tRRtNoneRR R RRRR(((s</usr/lib/python2.7/site-packages/pip/_vendor/requests/api.pyt s -    auth.py000064400000023000147205436720006064 0ustar00# -*- coding: utf-8 -*- """ requests.auth ~~~~~~~~~~~~~ This module contains the authentication handlers for Requests. """ import os import re import time import hashlib import threading import warnings from base64 import b64encode from .compat import urlparse, str, basestring from .cookies import extract_cookies_to_jar from ._internal_utils import to_native_string from .utils import parse_dict_header CONTENT_TYPE_FORM_URLENCODED = 'application/x-www-form-urlencoded' CONTENT_TYPE_MULTI_PART = 'multipart/form-data' def _basic_auth_str(username, password): """Returns a Basic Auth string.""" # "I want us to put a big-ol' comment on top of it that # says that this behaviour is dumb but we need to preserve # it because people are relying on it." # - Lukasa # # These are here solely to maintain backwards compatibility # for things like ints. This will be removed in 3.0.0. if not isinstance(username, basestring): warnings.warn( "Non-string usernames will no longer be supported in Requests " "3.0.0. Please convert the object you've passed in ({0!r}) to " "a string or bytes object in the near future to avoid " "problems.".format(username), category=DeprecationWarning, ) username = str(username) if not isinstance(password, basestring): warnings.warn( "Non-string passwords will no longer be supported in Requests " "3.0.0. Please convert the object you've passed in ({0!r}) to " "a string or bytes object in the near future to avoid " "problems.".format(password), category=DeprecationWarning, ) password = str(password) # -- End Removal -- if isinstance(username, str): username = username.encode('latin1') if isinstance(password, str): password = password.encode('latin1') authstr = 'Basic ' + to_native_string( b64encode(b':'.join((username, password))).strip() ) return authstr class AuthBase(object): """Base class that all auth implementations derive from""" def __call__(self, r): raise NotImplementedError('Auth hooks must be callable.') class HTTPBasicAuth(AuthBase): """Attaches HTTP Basic Authentication to the given Request object.""" def __init__(self, username, password): self.username = username self.password = password def __eq__(self, other): return all([ self.username == getattr(other, 'username', None), self.password == getattr(other, 'password', None) ]) def __ne__(self, other): return not self == other def __call__(self, r): r.headers['Authorization'] = _basic_auth_str(self.username, self.password) return r class HTTPProxyAuth(HTTPBasicAuth): """Attaches HTTP Proxy Authentication to a given Request object.""" def __call__(self, r): r.headers['Proxy-Authorization'] = _basic_auth_str(self.username, self.password) return r class HTTPDigestAuth(AuthBase): """Attaches HTTP Digest Authentication to the given Request object.""" def __init__(self, username, password): self.username = username self.password = password # Keep state in per-thread local storage self._thread_local = threading.local() def init_per_thread_state(self): # Ensure state is initialized just once per-thread if not hasattr(self._thread_local, 'init'): self._thread_local.init = True self._thread_local.last_nonce = '' self._thread_local.nonce_count = 0 self._thread_local.chal = {} self._thread_local.pos = None self._thread_local.num_401_calls = None def build_digest_header(self, method, url): """ :rtype: str """ realm = self._thread_local.chal['realm'] nonce = self._thread_local.chal['nonce'] qop = self._thread_local.chal.get('qop') algorithm = self._thread_local.chal.get('algorithm') opaque = self._thread_local.chal.get('opaque') hash_utf8 = None if algorithm is None: _algorithm = 'MD5' else: _algorithm = algorithm.upper() # lambdas assume digest modules are imported at the top level if _algorithm == 'MD5' or _algorithm == 'MD5-SESS': def md5_utf8(x): if isinstance(x, str): x = x.encode('utf-8') return hashlib.md5(x).hexdigest() hash_utf8 = md5_utf8 elif _algorithm == 'SHA': def sha_utf8(x): if isinstance(x, str): x = x.encode('utf-8') return hashlib.sha1(x).hexdigest() hash_utf8 = sha_utf8 KD = lambda s, d: hash_utf8("%s:%s" % (s, d)) if hash_utf8 is None: return None # XXX not implemented yet entdig = None p_parsed = urlparse(url) #: path is request-uri defined in RFC 2616 which should not be empty path = p_parsed.path or "/" if p_parsed.query: path += '?' + p_parsed.query A1 = '%s:%s:%s' % (self.username, realm, self.password) A2 = '%s:%s' % (method, path) HA1 = hash_utf8(A1) HA2 = hash_utf8(A2) if nonce == self._thread_local.last_nonce: self._thread_local.nonce_count += 1 else: self._thread_local.nonce_count = 1 ncvalue = '%08x' % self._thread_local.nonce_count s = str(self._thread_local.nonce_count).encode('utf-8') s += nonce.encode('utf-8') s += time.ctime().encode('utf-8') s += os.urandom(8) cnonce = (hashlib.sha1(s).hexdigest()[:16]) if _algorithm == 'MD5-SESS': HA1 = hash_utf8('%s:%s:%s' % (HA1, nonce, cnonce)) if not qop: respdig = KD(HA1, "%s:%s" % (nonce, HA2)) elif qop == 'auth' or 'auth' in qop.split(','): noncebit = "%s:%s:%s:%s:%s" % ( nonce, ncvalue, cnonce, 'auth', HA2 ) respdig = KD(HA1, noncebit) else: # XXX handle auth-int. return None self._thread_local.last_nonce = nonce # XXX should the partial digests be encoded too? base = 'username="%s", realm="%s", nonce="%s", uri="%s", ' \ 'response="%s"' % (self.username, realm, nonce, path, respdig) if opaque: base += ', opaque="%s"' % opaque if algorithm: base += ', algorithm="%s"' % algorithm if entdig: base += ', digest="%s"' % entdig if qop: base += ', qop="auth", nc=%s, cnonce="%s"' % (ncvalue, cnonce) return 'Digest %s' % (base) def handle_redirect(self, r, **kwargs): """Reset num_401_calls counter on redirects.""" if r.is_redirect: self._thread_local.num_401_calls = 1 def handle_401(self, r, **kwargs): """ Takes the given response and tries digest-auth, if needed. :rtype: requests.Response """ # If response is not 4xx, do not auth # See https://github.com/requests/requests/issues/3772 if not 400 <= r.status_code < 500: self._thread_local.num_401_calls = 1 return r if self._thread_local.pos is not None: # Rewind the file position indicator of the body to where # it was to resend the request. r.request.body.seek(self._thread_local.pos) s_auth = r.headers.get('www-authenticate', '') if 'digest' in s_auth.lower() and self._thread_local.num_401_calls < 2: self._thread_local.num_401_calls += 1 pat = re.compile(r'digest ', flags=re.IGNORECASE) self._thread_local.chal = parse_dict_header(pat.sub('', s_auth, count=1)) # Consume content and release the original connection # to allow our new request to reuse the same one. r.content r.close() prep = r.request.copy() extract_cookies_to_jar(prep._cookies, r.request, r.raw) prep.prepare_cookies(prep._cookies) prep.headers['Authorization'] = self.build_digest_header( prep.method, prep.url) _r = r.connection.send(prep, **kwargs) _r.history.append(r) _r.request = prep return _r self._thread_local.num_401_calls = 1 return r def __call__(self, r): # Initialize per-thread state, if needed self.init_per_thread_state() # If we have a saved nonce, skip the 401 if self._thread_local.last_nonce: r.headers['Authorization'] = self.build_digest_header(r.method, r.url) try: self._thread_local.pos = r.body.tell() except AttributeError: # In the case of HTTPDigestAuth being reused and the body of # the previous request was a file-like object, pos has the # file position of the previous body. Ensure it's set to # None. self._thread_local.pos = None r.register_hook('response', self.handle_401) r.register_hook('response', self.handle_redirect) self._thread_local.num_401_calls = 1 return r def __eq__(self, other): return all([ self.username == getattr(other, 'username', None), self.password == getattr(other, 'password', None) ]) def __ne__(self, other): return not self == other auth.pyc000064400000023304147205436720006236 0ustar00 abc@sdZddlZddlZddlZddlZddlZddlZddlmZddl m Z m Z m Z ddl mZddlmZddlmZd Zd Zd Zd efd YZdefdYZdefdYZdefdYZdS(s] requests.auth ~~~~~~~~~~~~~ This module contains the authentication handlers for Requests. iN(t b64encodei(turlparsetstrt basestring(textract_cookies_to_jar(tto_native_string(tparse_dict_headers!application/x-www-form-urlencodedsmultipart/form-datacCst|ts:tjdj|dtt|}nt|tsttjdj|dtt|}nt|tr|jd}nt|tr|jd}ndtt dj ||fj }|S(sReturns a Basic Auth string.sNon-string usernames will no longer be supported in Requests 3.0.0. Please convert the object you've passed in ({0!r}) to a string or bytes object in the near future to avoid problems.tcategorysNon-string passwords will no longer be supported in Requests 3.0.0. Please convert the object you've passed in ({0!r}) to a string or bytes object in the near future to avoid problems.tlatin1sBasic t:( t isinstanceRtwarningstwarntformattDeprecationWarningRtencodeRRtjointstrip(tusernametpasswordtauthstr((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pyt_basic_auth_strs&   %tAuthBasecBseZdZdZRS(s4Base class that all auth implementations derive fromcCstddS(NsAuth hooks must be callable.(tNotImplementedError(tselftr((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pyt__call__Ks(t__name__t __module__t__doc__R(((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pyRHst HTTPBasicAuthcBs2eZdZdZdZdZdZRS(s?Attaches HTTP Basic Authentication to the given Request object.cCs||_||_dS(N(RR(RRR((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pyt__init__Rs cCs:t|jt|ddk|jt|ddkgS(NRR(tallRtgetattrtNoneR(Rtother((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pyt__eq__VscCs ||k S(N((RR#((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pyt__ne__\scCs t|j|j|jd<|S(Nt Authorization(RRRtheaders(RR((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pyR_s(RRRRR$R%R(((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pyROs    t HTTPProxyAuthcBseZdZdZRS(s=Attaches HTTP Proxy Authentication to a given Request object.cCs t|j|j|jd<|S(NsProxy-Authorization(RRRR'(RR((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pyRgs(RRRR(((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pyR(dstHTTPDigestAuthcBsVeZdZdZdZdZdZdZdZdZ dZ RS( s@Attaches HTTP Digest Authentication to the given Request object.cCs%||_||_tj|_dS(N(RRt threadingtlocalt _thread_local(RRR((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pyRos  cCsat|jds]t|j_d|j_d|j_i|j_d|j_d|j_ ndS(Ntinitti( thasattrR,tTrueR-t last_noncet nonce_counttchalR"tpost num_401_calls(R((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pytinit_per_thread_stateus     csN|jjd}|jjd}|jjjd}|jjjd}|jjjd}d|dkrzd}n |j}|dks|dkrd} | n|d krd } | nfd } dkrdSd} t|} | jp d }| jr+|d | j7}nd|j||j f}d||f}|}|}||jj kr|jj d7_ n d|j_ d|jj }t |jj j d}||j d7}|tjj d7}|tjd7}tj|jd }|dkrJd|||f}n|sl| |d||f}nP|dksd|jdkrd|||d|f}| ||}ndS||j_ d|j||||f}|r|d|7}n|r|d|7}n| r)|d| 7}n|rF|d||f7}nd|S(s :rtype: str trealmtnoncetqopt algorithmtopaquetMD5sMD5-SESScSs4t|tr!|jd}ntj|jS(Nsutf-8(R RRthashlibtmd5t hexdigest(tx((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pytmd5_utf8stSHAcSs4t|tr!|jd}ntj|jS(Nsutf-8(R RRR=tsha1R?(R@((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pytsha_utf8scsd||fS(Ns%s:%s((tstd(t hash_utf8(s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pytR.t/t?s%s:%s:%ss%s:%sis%08xsutf-8iitautht,s%s:%s:%s:%s:%ss>username="%s", realm="%s", nonce="%s", uri="%s", response="%s"s , opaque="%s"s, algorithm="%s"s , digest="%s"s , qop="auth", nc=%s, cnonce="%s"s Digest %sN(R,R3tgetR"tupperRtpathtqueryRRR1R2RRttimetctimetosturandomR=RCR?tsplit(RtmethodturlR7R8R9R:R;t _algorithmRARDtKDtentdigtp_parsedROtA1tA2tHA1tHA2tncvalueREtcnoncetrespdigtnoncebittbase((RGs=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pytbuild_digest_headersr               ! cKs|jrd|j_ndS(s)Reset num_401_calls counter on redirects.iN(t is_redirectR,R5(RRtkwargs((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pythandle_redirects cKsd|jkodkns/d|j_|S|jjd k r]|jjj|jjn|jj dd}d|j kr~|jjdkr~|jjd7_t j dd t j }t|jd|d d|j_|j|j|jj}t|j|j|j|j|j|j|j|j|jd <|jj||}|jj|||_|Sd|j_|S( so Takes the given response and tries digest-auth, if needed. :rtype: requests.Response iiiswww-authenticateR.tdigestisdigest tflagstcountR&N(t status_codeR,R5R4R"trequesttbodytseekR'RMtlowertretcompilet IGNORECASERtsubR3tcontenttclosetcopyRt_cookiestrawtprepare_cookiesReRVRWt connectiontsendthistorytappend(RRRgts_authtpattprept_r((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pyt handle_401s.  $$   cCs|j|jjr8|j|j|j|jds$       ,auth.pyo000064400000023304147205436720006252 0ustar00 abc@sdZddlZddlZddlZddlZddlZddlZddlmZddl m Z m Z m Z ddl mZddlmZddlmZd Zd Zd Zd efd YZdefdYZdefdYZdefdYZdS(s] requests.auth ~~~~~~~~~~~~~ This module contains the authentication handlers for Requests. iN(t b64encodei(turlparsetstrt basestring(textract_cookies_to_jar(tto_native_string(tparse_dict_headers!application/x-www-form-urlencodedsmultipart/form-datacCst|ts:tjdj|dtt|}nt|tsttjdj|dtt|}nt|tr|jd}nt|tr|jd}ndtt dj ||fj }|S(sReturns a Basic Auth string.sNon-string usernames will no longer be supported in Requests 3.0.0. Please convert the object you've passed in ({0!r}) to a string or bytes object in the near future to avoid problems.tcategorysNon-string passwords will no longer be supported in Requests 3.0.0. Please convert the object you've passed in ({0!r}) to a string or bytes object in the near future to avoid problems.tlatin1sBasic t:( t isinstanceRtwarningstwarntformattDeprecationWarningRtencodeRRtjointstrip(tusernametpasswordtauthstr((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pyt_basic_auth_strs&   %tAuthBasecBseZdZdZRS(s4Base class that all auth implementations derive fromcCstddS(NsAuth hooks must be callable.(tNotImplementedError(tselftr((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pyt__call__Ks(t__name__t __module__t__doc__R(((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pyRHst HTTPBasicAuthcBs2eZdZdZdZdZdZRS(s?Attaches HTTP Basic Authentication to the given Request object.cCs||_||_dS(N(RR(RRR((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pyt__init__Rs cCs:t|jt|ddk|jt|ddkgS(NRR(tallRtgetattrtNoneR(Rtother((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pyt__eq__VscCs ||k S(N((RR#((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pyt__ne__\scCs t|j|j|jd<|S(Nt Authorization(RRRtheaders(RR((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pyR_s(RRRRR$R%R(((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pyROs    t HTTPProxyAuthcBseZdZdZRS(s=Attaches HTTP Proxy Authentication to a given Request object.cCs t|j|j|jd<|S(NsProxy-Authorization(RRRR'(RR((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pyRgs(RRRR(((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pyR(dstHTTPDigestAuthcBsVeZdZdZdZdZdZdZdZdZ dZ RS( s@Attaches HTTP Digest Authentication to the given Request object.cCs%||_||_tj|_dS(N(RRt threadingtlocalt _thread_local(RRR((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pyRos  cCsat|jds]t|j_d|j_d|j_i|j_d|j_d|j_ ndS(Ntinitti( thasattrR,tTrueR-t last_noncet nonce_counttchalR"tpost num_401_calls(R((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pytinit_per_thread_stateus     csN|jjd}|jjd}|jjjd}|jjjd}|jjjd}d|dkrzd}n |j}|dks|dkrd} | n|d krd } | nfd } dkrdSd} t|} | jp d }| jr+|d | j7}nd|j||j f}d||f}|}|}||jj kr|jj d7_ n d|j_ d|jj }t |jj j d}||j d7}|tjj d7}|tjd7}tj|jd }|dkrJd|||f}n|sl| |d||f}nP|dksd|jdkrd|||d|f}| ||}ndS||j_ d|j||||f}|r|d|7}n|r|d|7}n| r)|d| 7}n|rF|d||f7}nd|S(s :rtype: str trealmtnoncetqopt algorithmtopaquetMD5sMD5-SESScSs4t|tr!|jd}ntj|jS(Nsutf-8(R RRthashlibtmd5t hexdigest(tx((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pytmd5_utf8stSHAcSs4t|tr!|jd}ntj|jS(Nsutf-8(R RRR=tsha1R?(R@((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pytsha_utf8scsd||fS(Ns%s:%s((tstd(t hash_utf8(s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pytR.t/t?s%s:%s:%ss%s:%sis%08xsutf-8iitautht,s%s:%s:%s:%s:%ss>username="%s", realm="%s", nonce="%s", uri="%s", response="%s"s , opaque="%s"s, algorithm="%s"s , digest="%s"s , qop="auth", nc=%s, cnonce="%s"s Digest %sN(R,R3tgetR"tupperRtpathtqueryRRR1R2RRttimetctimetosturandomR=RCR?tsplit(RtmethodturlR7R8R9R:R;t _algorithmRARDtKDtentdigtp_parsedROtA1tA2tHA1tHA2tncvalueREtcnoncetrespdigtnoncebittbase((RGs=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pytbuild_digest_headersr               ! cKs|jrd|j_ndS(s)Reset num_401_calls counter on redirects.iN(t is_redirectR,R5(RRtkwargs((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pythandle_redirects cKsd|jkodkns/d|j_|S|jjd k r]|jjj|jjn|jj dd}d|j kr~|jjdkr~|jjd7_t j dd t j }t|jd|d d|j_|j|j|jj}t|j|j|j|j|j|j|j|j|jd <|jj||}|jj|||_|Sd|j_|S( so Takes the given response and tries digest-auth, if needed. :rtype: requests.Response iiiswww-authenticateR.tdigestisdigest tflagstcountR&N(t status_codeR,R5R4R"trequesttbodytseekR'RMtlowertretcompilet IGNORECASERtsubR3tcontenttclosetcopyRt_cookiestrawtprepare_cookiesReRVRWt connectiontsendthistorytappend(RRRgts_authtpattprept_r((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/auth.pyt handle_401s.  $$   cCs|j|jjr8|j|j|j|jds$       ,certs.py000064400000000721147205436720006250 0ustar00#!/usr/bin/env python # -*- coding: utf-8 -*- """ requests.certs ~~~~~~~~~~~~~~ This module returns the preferred default CA certificate bundle. There is only one — the one from the certifi package. If you are packaging Requests, e.g., for a Linux distribution or a managed environment, you can change the definition of where() to return a separately packaged CA bundle. """ from pip._vendor.certifi import where if __name__ == '__main__': print(where()) certs.pyc000064400000001152147205436720006412 0ustar00 abc@s1dZddlmZedkr-eGHndS(sF requests.certs ~~~~~~~~~~~~~~ This module returns the preferred default CA certificate bundle. There is only one — the one from the certifi package. If you are packaging Requests, e.g., for a Linux distribution or a managed environment, you can change the definition of where() to return a separately packaged CA bundle. i(twheret__main__N(t__doc__tpip._vendor.certifiRt__name__(((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/certs.pyts certs.pyo000064400000001152147205436720006426 0ustar00 abc@s1dZddlmZedkr-eGHndS(sF requests.certs ~~~~~~~~~~~~~~ This module returns the preferred default CA certificate bundle. There is only one — the one from the certifi package. If you are packaging Requests, e.g., for a Linux distribution or a managed environment, you can change the definition of where() to return a separately packaged CA bundle. i(twheret__main__N(t__doc__tpip._vendor.certifiRt__name__(((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/certs.pyts compat.py000064400000003132147205436720006412 0ustar00# -*- coding: utf-8 -*- """ requests.compat ~~~~~~~~~~~~~~~ This module handles import compatibility issues between Python 2 and Python 3. """ from pip._vendor import chardet import sys # ------- # Pythons # ------- # Syntax sugar. _ver = sys.version_info #: Python 2.x? is_py2 = (_ver[0] == 2) #: Python 3.x? is_py3 = (_ver[0] == 3) # try: # import simplejson as json # except ImportError: import json # --------- # Specifics # --------- if is_py2: from urllib import ( quote, unquote, quote_plus, unquote_plus, urlencode, getproxies, proxy_bypass, proxy_bypass_environment, getproxies_environment) from urlparse import urlparse, urlunparse, urljoin, urlsplit, urldefrag from urllib2 import parse_http_list import cookielib from Cookie import Morsel from StringIO import StringIO from pip._vendor.urllib3.packages.ordered_dict import OrderedDict builtin_str = str bytes = str str = unicode basestring = basestring numeric_types = (int, long, float) integer_types = (int, long) elif is_py3: from urllib.parse import urlparse, urlunparse, urljoin, urlsplit, urlencode, quote, unquote, quote_plus, unquote_plus, urldefrag from urllib.request import parse_http_list, getproxies, proxy_bypass, proxy_bypass_environment, getproxies_environment from http import cookiejar as cookielib from http.cookies import Morsel from io import StringIO from collections import OrderedDict builtin_str = str str = str bytes = bytes basestring = (str, bytes) numeric_types = (int, float) integer_types = (int,) compat.pyc000064400000003465147205436720006566 0ustar00 abc@s5dZddlmZddlZejZeddkZeddkZddlZerGddl m Z m Z m Z m Z mZmZmZmZmZddlmZmZmZmZmZdd lmZddlZdd lmZdd lmZdd lmZe Z!e Z"e#Z e$Z$e%e&e'fZ(e%e&fZ)ner1dd l*mZmZmZmZmZm Z m Z m Z m Z mZddl+mZmZmZmZmZddl,m-Zdd l.mZdd l/mZdd l0mZe Z!e Z e"Z"e e"fZ$e%e'fZ(e%fZ)ndS(sq requests.compat ~~~~~~~~~~~~~~~ This module handles import compatibility issues between Python 2 and Python 3. i(tchardetNiii( tquotetunquotet quote_plust unquote_plust urlencodet getproxiest proxy_bypasstproxy_bypass_environmenttgetproxies_environment(turlparset urlunparseturljointurlsplitt urldefrag(tparse_http_list(tMorsel(tStringIO(t OrderedDict( R R R R RRRRRR(RRRRR (t cookiejar(1t__doc__t pip._vendorRtsyst version_infot_vertis_py2tis_py3tjsonturllibRRRRRRRRR R R R R Rturllib2Rt cookielibtCookieRRt)pip._vendor.urllib3.packages.ordered_dictRtstrt builtin_strtbytestunicodet basestringtinttlongtfloatt numeric_typest integer_typest urllib.parseturllib.requestthttpRt http.cookiestiot collections(((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/compat.pyt sB   @( F(  compat.pyo000064400000003465147205436720006602 0ustar00 abc@s5dZddlmZddlZejZeddkZeddkZddlZerGddl m Z m Z m Z m Z mZmZmZmZmZddlmZmZmZmZmZdd lmZddlZdd lmZdd lmZdd lmZe Z!e Z"e#Z e$Z$e%e&e'fZ(e%e&fZ)ner1dd l*mZmZmZmZmZm Z m Z m Z m Z mZddl+mZmZmZmZmZddl,m-Zdd l.mZdd l/mZdd l0mZe Z!e Z e"Z"e e"fZ$e%e'fZ(e%fZ)ndS(sq requests.compat ~~~~~~~~~~~~~~~ This module handles import compatibility issues between Python 2 and Python 3. i(tchardetNiii( tquotetunquotet quote_plust unquote_plust urlencodet getproxiest proxy_bypasstproxy_bypass_environmenttgetproxies_environment(turlparset urlunparseturljointurlsplitt urldefrag(tparse_http_list(tMorsel(tStringIO(t OrderedDict( R R R R RRRRRR(RRRRR (t cookiejar(1t__doc__t pip._vendorRtsyst version_infot_vertis_py2tis_py3tjsonturllibRRRRRRRRR R R R R Rturllib2Rt cookielibtCookieRRt)pip._vendor.urllib3.packages.ordered_dictRtstrt builtin_strtbytestunicodet basestringtinttlongtfloatt numeric_typest integer_typest urllib.parseturllib.requestthttpRt http.cookiestiot collections(((s?/usr/lib/python2.7/site-packages/pip/_vendor/requests/compat.pyt sB   @( F(  cookies.py000064400000043440147205436720006571 0ustar00# -*- coding: utf-8 -*- """ requests.cookies ~~~~~~~~~~~~~~~~ Compatibility code to be able to use `cookielib.CookieJar` with requests. requests.utils imports from here, so be careful with imports. """ import copy import time import calendar import collections from ._internal_utils import to_native_string from .compat import cookielib, urlparse, urlunparse, Morsel try: import threading except ImportError: import dummy_threading as threading class MockRequest(object): """Wraps a `requests.Request` to mimic a `urllib2.Request`. The code in `cookielib.CookieJar` expects this interface in order to correctly manage cookie policies, i.e., determine whether a cookie can be set, given the domains of the request and the cookie. The original request object is read-only. The client is responsible for collecting the new headers via `get_new_headers()` and interpreting them appropriately. You probably want `get_cookie_header`, defined below. """ def __init__(self, request): self._r = request self._new_headers = {} self.type = urlparse(self._r.url).scheme def get_type(self): return self.type def get_host(self): return urlparse(self._r.url).netloc def get_origin_req_host(self): return self.get_host() def get_full_url(self): # Only return the response's URL if the user hadn't set the Host # header if not self._r.headers.get('Host'): return self._r.url # If they did set it, retrieve it and reconstruct the expected domain host = to_native_string(self._r.headers['Host'], encoding='utf-8') parsed = urlparse(self._r.url) # Reconstruct the URL as we expect it return urlunparse([ parsed.scheme, host, parsed.path, parsed.params, parsed.query, parsed.fragment ]) def is_unverifiable(self): return True def has_header(self, name): return name in self._r.headers or name in self._new_headers def get_header(self, name, default=None): return self._r.headers.get(name, self._new_headers.get(name, default)) def add_header(self, key, val): """cookielib has no legitimate use for this method; add it back if you find one.""" raise NotImplementedError("Cookie headers should be added with add_unredirected_header()") def add_unredirected_header(self, name, value): self._new_headers[name] = value def get_new_headers(self): return self._new_headers @property def unverifiable(self): return self.is_unverifiable() @property def origin_req_host(self): return self.get_origin_req_host() @property def host(self): return self.get_host() class MockResponse(object): """Wraps a `httplib.HTTPMessage` to mimic a `urllib.addinfourl`. ...what? Basically, expose the parsed HTTP headers from the server response the way `cookielib` expects to see them. """ def __init__(self, headers): """Make a MockResponse for `cookielib` to read. :param headers: a httplib.HTTPMessage or analogous carrying the headers """ self._headers = headers def info(self): return self._headers def getheaders(self, name): self._headers.getheaders(name) def extract_cookies_to_jar(jar, request, response): """Extract the cookies from the response into a CookieJar. :param jar: cookielib.CookieJar (not necessarily a RequestsCookieJar) :param request: our own requests.Request object :param response: urllib3.HTTPResponse object """ if not (hasattr(response, '_original_response') and response._original_response): return # the _original_response field is the wrapped httplib.HTTPResponse object, req = MockRequest(request) # pull out the HTTPMessage with the headers and put it in the mock: res = MockResponse(response._original_response.msg) jar.extract_cookies(res, req) def get_cookie_header(jar, request): """ Produce an appropriate Cookie header string to be sent with `request`, or None. :rtype: str """ r = MockRequest(request) jar.add_cookie_header(r) return r.get_new_headers().get('Cookie') def remove_cookie_by_name(cookiejar, name, domain=None, path=None): """Unsets a cookie by name, by default over all domains and paths. Wraps CookieJar.clear(), is O(n). """ clearables = [] for cookie in cookiejar: if cookie.name != name: continue if domain is not None and domain != cookie.domain: continue if path is not None and path != cookie.path: continue clearables.append((cookie.domain, cookie.path, cookie.name)) for domain, path, name in clearables: cookiejar.clear(domain, path, name) class CookieConflictError(RuntimeError): """There are two cookies that meet the criteria specified in the cookie jar. Use .get and .set and include domain and path args in order to be more specific. """ class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping): """Compatibility class; is a cookielib.CookieJar, but exposes a dict interface. This is the CookieJar we create by default for requests and sessions that don't specify one, since some clients may expect response.cookies and session.cookies to support dict operations. Requests does not use the dict interface internally; it's just for compatibility with external client code. All requests code should work out of the box with externally provided instances of ``CookieJar``, e.g. ``LWPCookieJar`` and ``FileCookieJar``. Unlike a regular CookieJar, this class is pickleable. .. warning:: dictionary operations that are normally O(1) may be O(n). """ def get(self, name, default=None, domain=None, path=None): """Dict-like get() that also supports optional domain and path args in order to resolve naming collisions from using one cookie jar over multiple domains. .. warning:: operation is O(n), not O(1). """ try: return self._find_no_duplicates(name, domain, path) except KeyError: return default def set(self, name, value, **kwargs): """Dict-like set() that also supports optional domain and path args in order to resolve naming collisions from using one cookie jar over multiple domains. """ # support client code that unsets cookies by assignment of a None value: if value is None: remove_cookie_by_name(self, name, domain=kwargs.get('domain'), path=kwargs.get('path')) return if isinstance(value, Morsel): c = morsel_to_cookie(value) else: c = create_cookie(name, value, **kwargs) self.set_cookie(c) return c def iterkeys(self): """Dict-like iterkeys() that returns an iterator of names of cookies from the jar. .. seealso:: itervalues() and iteritems(). """ for cookie in iter(self): yield cookie.name def keys(self): """Dict-like keys() that returns a list of names of cookies from the jar. .. seealso:: values() and items(). """ return list(self.iterkeys()) def itervalues(self): """Dict-like itervalues() that returns an iterator of values of cookies from the jar. .. seealso:: iterkeys() and iteritems(). """ for cookie in iter(self): yield cookie.value def values(self): """Dict-like values() that returns a list of values of cookies from the jar. .. seealso:: keys() and items(). """ return list(self.itervalues()) def iteritems(self): """Dict-like iteritems() that returns an iterator of name-value tuples from the jar. .. seealso:: iterkeys() and itervalues(). """ for cookie in iter(self): yield cookie.name, cookie.value def items(self): """Dict-like items() that returns a list of name-value tuples from the jar. Allows client-code to call ``dict(RequestsCookieJar)`` and get a vanilla python dict of key value pairs. .. seealso:: keys() and values(). """ return list(self.iteritems()) def list_domains(self): """Utility method to list all the domains in the jar.""" domains = [] for cookie in iter(self): if cookie.domain not in domains: domains.append(cookie.domain) return domains def list_paths(self): """Utility method to list all the paths in the jar.""" paths = [] for cookie in iter(self): if cookie.path not in paths: paths.append(cookie.path) return paths def multiple_domains(self): """Returns True if there are multiple domains in the jar. Returns False otherwise. :rtype: bool """ domains = [] for cookie in iter(self): if cookie.domain is not None and cookie.domain in domains: return True domains.append(cookie.domain) return False # there is only one domain in jar def get_dict(self, domain=None, path=None): """Takes as an argument an optional domain and path and returns a plain old Python dict of name-value pairs of cookies that meet the requirements. :rtype: dict """ dictionary = {} for cookie in iter(self): if ( (domain is None or cookie.domain == domain) and (path is None or cookie.path == path) ): dictionary[cookie.name] = cookie.value return dictionary def __contains__(self, name): try: return super(RequestsCookieJar, self).__contains__(name) except CookieConflictError: return True def __getitem__(self, name): """Dict-like __getitem__() for compatibility with client code. Throws exception if there are more than one cookie with name. In that case, use the more explicit get() method instead. .. warning:: operation is O(n), not O(1). """ return self._find_no_duplicates(name) def __setitem__(self, name, value): """Dict-like __setitem__ for compatibility with client code. Throws exception if there is already a cookie of that name in the jar. In that case, use the more explicit set() method instead. """ self.set(name, value) def __delitem__(self, name): """Deletes a cookie given a name. Wraps ``cookielib.CookieJar``'s ``remove_cookie_by_name()``. """ remove_cookie_by_name(self, name) def set_cookie(self, cookie, *args, **kwargs): if hasattr(cookie.value, 'startswith') and cookie.value.startswith('"') and cookie.value.endswith('"'): cookie.value = cookie.value.replace('\\"', '') return super(RequestsCookieJar, self).set_cookie(cookie, *args, **kwargs) def update(self, other): """Updates this jar with cookies from another CookieJar or dict-like""" if isinstance(other, cookielib.CookieJar): for cookie in other: self.set_cookie(copy.copy(cookie)) else: super(RequestsCookieJar, self).update(other) def _find(self, name, domain=None, path=None): """Requests uses this method internally to get cookie values. If there are conflicting cookies, _find arbitrarily chooses one. See _find_no_duplicates if you want an exception thrown if there are conflicting cookies. :param name: a string containing name of cookie :param domain: (optional) string containing domain of cookie :param path: (optional) string containing path of cookie :return: cookie.value """ for cookie in iter(self): if cookie.name == name: if domain is None or cookie.domain == domain: if path is None or cookie.path == path: return cookie.value raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path)) def _find_no_duplicates(self, name, domain=None, path=None): """Both ``__get_item__`` and ``get`` call this function: it's never used elsewhere in Requests. :param name: a string containing name of cookie :param domain: (optional) string containing domain of cookie :param path: (optional) string containing path of cookie :raises KeyError: if cookie is not found :raises CookieConflictError: if there are multiple cookies that match name and optionally domain and path :return: cookie.value """ toReturn = None for cookie in iter(self): if cookie.name == name: if domain is None or cookie.domain == domain: if path is None or cookie.path == path: if toReturn is not None: # if there are multiple cookies that meet passed in criteria raise CookieConflictError('There are multiple cookies with name, %r' % (name)) toReturn = cookie.value # we will eventually return this as long as no cookie conflict if toReturn: return toReturn raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path)) def __getstate__(self): """Unlike a normal CookieJar, this class is pickleable.""" state = self.__dict__.copy() # remove the unpickleable RLock object state.pop('_cookies_lock') return state def __setstate__(self, state): """Unlike a normal CookieJar, this class is pickleable.""" self.__dict__.update(state) if '_cookies_lock' not in self.__dict__: self._cookies_lock = threading.RLock() def copy(self): """Return a copy of this RequestsCookieJar.""" new_cj = RequestsCookieJar() new_cj.update(self) return new_cj def _copy_cookie_jar(jar): if jar is None: return None if hasattr(jar, 'copy'): # We're dealing with an instance of RequestsCookieJar return jar.copy() # We're dealing with a generic CookieJar instance new_jar = copy.copy(jar) new_jar.clear() for cookie in jar: new_jar.set_cookie(copy.copy(cookie)) return new_jar def create_cookie(name, value, **kwargs): """Make a cookie from underspecified parameters. By default, the pair of `name` and `value` will be set for the domain '' and sent on every request (this is sometimes called a "supercookie"). """ result = dict( version=0, name=name, value=value, port=None, domain='', path='/', secure=False, expires=None, discard=True, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False,) badargs = set(kwargs) - set(result) if badargs: err = 'create_cookie() got unexpected keyword arguments: %s' raise TypeError(err % list(badargs)) result.update(kwargs) result['port_specified'] = bool(result['port']) result['domain_specified'] = bool(result['domain']) result['domain_initial_dot'] = result['domain'].startswith('.') result['path_specified'] = bool(result['path']) return cookielib.Cookie(**result) def morsel_to_cookie(morsel): """Convert a Morsel object into a Cookie containing the one k/v pair.""" expires = None if morsel['max-age']: try: expires = int(time.time() + int(morsel['max-age'])) except ValueError: raise TypeError('max-age: %s must be integer' % morsel['max-age']) elif morsel['expires']: time_template = '%a, %d-%b-%Y %H:%M:%S GMT' expires = calendar.timegm( time.strptime(morsel['expires'], time_template) ) return create_cookie( comment=morsel['comment'], comment_url=bool(morsel['comment']), discard=False, domain=morsel['domain'], expires=expires, name=morsel.key, path=morsel['path'], port=None, rest={'HttpOnly': morsel['httponly']}, rfc2109=False, secure=bool(morsel['secure']), value=morsel.value, version=morsel['version'] or 0, ) def cookiejar_from_dict(cookie_dict, cookiejar=None, overwrite=True): """Returns a CookieJar from a key/value dictionary. :param cookie_dict: Dict of key/values to insert into CookieJar. :param cookiejar: (optional) A cookiejar to add the cookies to. :param overwrite: (optional) If False, will not replace cookies already in the jar with new ones. """ if cookiejar is None: cookiejar = RequestsCookieJar() if cookie_dict is not None: names_from_jar = [cookie.name for cookie in cookiejar] for name in cookie_dict: if overwrite or (name not in names_from_jar): cookiejar.set_cookie(create_cookie(name, cookie_dict[name])) return cookiejar def merge_cookies(cookiejar, cookies): """Add cookies to cookiejar and returns a merged CookieJar. :param cookiejar: CookieJar object to add the cookies to. :param cookies: Dictionary or CookieJar object to be added. """ if not isinstance(cookiejar, cookielib.CookieJar): raise ValueError('You can only merge into CookieJar') if isinstance(cookies, dict): cookiejar = cookiejar_from_dict( cookies, cookiejar=cookiejar, overwrite=False) elif isinstance(cookies, cookielib.CookieJar): try: cookiejar.update(cookies) except AttributeError: for cookie_in_jar in cookies: cookiejar.set_cookie(cookie_in_jar) return cookiejar cookies.pyc000064400000053604147205436720006737 0ustar00 abc@sQdZddlZddlZddlZddlZddlmZddlmZm Z m Z m Z yddl Z Wne k rddlZ nXdefdYZdefd YZd Zd Zddd Zd efdYZdejejfdYZdZdZdZdedZdZ dS(s requests.cookies ~~~~~~~~~~~~~~~~ Compatibility code to be able to use `cookielib.CookieJar` with requests. requests.utils imports from here, so be careful with imports. iNi(tto_native_string(t cookielibturlparset urlunparsetMorselt MockRequestcBseZdZdZdZdZdZdZdZdZ ddZ d Z d Z d Zed Zed ZedZRS(sWraps a `requests.Request` to mimic a `urllib2.Request`. The code in `cookielib.CookieJar` expects this interface in order to correctly manage cookie policies, i.e., determine whether a cookie can be set, given the domains of the request and the cookie. The original request object is read-only. The client is responsible for collecting the new headers via `get_new_headers()` and interpreting them appropriately. You probably want `get_cookie_header`, defined below. cCs.||_i|_t|jjj|_dS(N(t_rt _new_headersRturltschemettype(tselftrequest((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt__init__&s  cCs|jS(N(R (R ((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytget_type+scCst|jjjS(N(RRRtnetloc(R ((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytget_host.scCs |jS(N(R(R ((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytget_origin_req_host1scCsx|jjjds|jjSt|jjddd}t|jj}t|j||j|j |j |j gS(NtHosttencodingsutf-8( RtheaderstgetRRRRR tpathtparamstquerytfragment(R thosttparsed((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt get_full_url4s cCstS(N(tTrue(R ((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytis_unverifiableBscCs||jjkp||jkS(N(RRR(R tname((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt has_headerEscCs%|jjj||jj||S(N(RRRR(R Rtdefault((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt get_headerHscCstddS(sMcookielib has no legitimate use for this method; add it back if you find one.s=Cookie headers should be added with add_unredirected_header()N(tNotImplementedError(R tkeytval((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt add_headerKscCs||j|(RR'RQtresulttbadargsterr((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyROs0   cCs!d}|dr_y$ttjt|d}Wqtk r[td|dqXn2|drd}tjtj|d|}ntd|ddt |ddt d|dd|d |j d |d d dd i|d d6dt dt |dd|j d|dpd S(sBConvert a Morsel object into a Cookie containing the one k/v pair.smax-agesmax-age: %s must be integerRs%a, %d-%b-%Y %H:%M:%S GMTRRRRBRRRRthttponlyRRRR'RiN( R/tintttimet ValueErrorRtcalendarttimegmtstrptimeRORR`R$R'(tmorselRt time_template((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyRNs0 $       cCs|dkrt}n|dk rg|D]}|j^q+}x@|D]5}|s_||krG|jt|||qGqGWn|S(s-Returns a CookieJar from a key/value dictionary. :param cookie_dict: Dict of key/values to insert into CookieJar. :param cookiejar: (optional) A cookiejar to add the cookies to. :param overwrite: (optional) If False, will not replace cookies already in the jar with new ones. N(R/RJRRPRO(t cookie_dictREt overwriteRGtnames_from_jarR((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytcookiejar_from_dicts    $cCst|tjs!tdnt|trKt|d|dt}nXt|tjry|j|Wqtk rx|D]}|j |qWqXn|S(sAdd cookies to cookiejar and returns a merged CookieJar. :param cookiejar: CookieJar object to add the cookies to. :param cookies: Dictionary or CookieJar object to be added. s!You can only merge into CookieJarRER( RMRRoRRRR`RqtAttributeErrorRP(REtcookiest cookie_in_jar((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt merge_cookies s  (!R.RpRRt collectionst_internal_utilsRtcompatRRRRRzt ImportErrortdummy_threadingtobjectRR1R=RAR/RHt RuntimeErrorRIRotMutableMappingRJRRORNRRR(((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt s,    " H    # cookies.pyo000064400000053604147205436720006753 0ustar00 abc@sQdZddlZddlZddlZddlZddlmZddlmZm Z m Z m Z yddl Z Wne k rddlZ nXdefdYZdefd YZd Zd Zddd Zd efdYZdejejfdYZdZdZdZdedZdZ dS(s requests.cookies ~~~~~~~~~~~~~~~~ Compatibility code to be able to use `cookielib.CookieJar` with requests. requests.utils imports from here, so be careful with imports. iNi(tto_native_string(t cookielibturlparset urlunparsetMorselt MockRequestcBseZdZdZdZdZdZdZdZdZ ddZ d Z d Z d Zed Zed ZedZRS(sWraps a `requests.Request` to mimic a `urllib2.Request`. The code in `cookielib.CookieJar` expects this interface in order to correctly manage cookie policies, i.e., determine whether a cookie can be set, given the domains of the request and the cookie. The original request object is read-only. The client is responsible for collecting the new headers via `get_new_headers()` and interpreting them appropriately. You probably want `get_cookie_header`, defined below. cCs.||_i|_t|jjj|_dS(N(t_rt _new_headersRturltschemettype(tselftrequest((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt__init__&s  cCs|jS(N(R (R ((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytget_type+scCst|jjjS(N(RRRtnetloc(R ((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytget_host.scCs |jS(N(R(R ((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytget_origin_req_host1scCsx|jjjds|jjSt|jjddd}t|jj}t|j||j|j |j |j gS(NtHosttencodingsutf-8( RtheaderstgetRRRRR tpathtparamstquerytfragment(R thosttparsed((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt get_full_url4s cCstS(N(tTrue(R ((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytis_unverifiableBscCs||jjkp||jkS(N(RRR(R tname((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt has_headerEscCs%|jjj||jj||S(N(RRRR(R Rtdefault((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt get_headerHscCstddS(sMcookielib has no legitimate use for this method; add it back if you find one.s=Cookie headers should be added with add_unredirected_header()N(tNotImplementedError(R tkeytval((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt add_headerKscCs||j|(RR'RQtresulttbadargsterr((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyROs0   cCs!d}|dr_y$ttjt|d}Wqtk r[td|dqXn2|drd}tjtj|d|}ntd|ddt |ddt d|dd|d |j d |d d dd i|d d6dt dt |dd|j d|dpd S(sBConvert a Morsel object into a Cookie containing the one k/v pair.smax-agesmax-age: %s must be integerRs%a, %d-%b-%Y %H:%M:%S GMTRRRRBRRRRthttponlyRRRR'RiN( R/tintttimet ValueErrorRtcalendarttimegmtstrptimeRORR`R$R'(tmorselRt time_template((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyRNs0 $       cCs|dkrt}n|dk rg|D]}|j^q+}x@|D]5}|s_||krG|jt|||qGqGWn|S(s-Returns a CookieJar from a key/value dictionary. :param cookie_dict: Dict of key/values to insert into CookieJar. :param cookiejar: (optional) A cookiejar to add the cookies to. :param overwrite: (optional) If False, will not replace cookies already in the jar with new ones. N(R/RJRRPRO(t cookie_dictREt overwriteRGtnames_from_jarR((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pytcookiejar_from_dicts    $cCst|tjs!tdnt|trKt|d|dt}nXt|tjry|j|Wqtk rx|D]}|j |qWqXn|S(sAdd cookies to cookiejar and returns a merged CookieJar. :param cookiejar: CookieJar object to add the cookies to. :param cookies: Dictionary or CookieJar object to be added. s!You can only merge into CookieJarRER( RMRRoRRRR`RqtAttributeErrorRP(REtcookiest cookie_in_jar((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt merge_cookies s  (!R.RpRRt collectionst_internal_utilsRtcompatRRRRRzt ImportErrortdummy_threadingtobjectRR1R=RAR/RHt RuntimeErrorRIRotMutableMappingRJRRORNRRR(((s@/usr/lib/python2.7/site-packages/pip/_vendor/requests/cookies.pyt s,    " H    # exceptions.py000064400000006053147205436720007315 0ustar00# -*- coding: utf-8 -*- """ requests.exceptions ~~~~~~~~~~~~~~~~~~~ This module contains the set of Requests' exceptions. """ from pip._vendor.urllib3.exceptions import HTTPError as BaseHTTPError class RequestException(IOError): """There was an ambiguous exception that occurred while handling your request. """ def __init__(self, *args, **kwargs): """Initialize RequestException with `request` and `response` objects.""" response = kwargs.pop('response', None) self.response = response self.request = kwargs.pop('request', None) if (response is not None and not self.request and hasattr(response, 'request')): self.request = self.response.request super(RequestException, self).__init__(*args, **kwargs) class HTTPError(RequestException): """An HTTP error occurred.""" class ConnectionError(RequestException): """A Connection error occurred.""" class ProxyError(ConnectionError): """A proxy error occurred.""" class SSLError(ConnectionError): """An SSL error occurred.""" class Timeout(RequestException): """The request timed out. Catching this error will catch both :exc:`~requests.exceptions.ConnectTimeout` and :exc:`~requests.exceptions.ReadTimeout` errors. """ class ConnectTimeout(ConnectionError, Timeout): """The request timed out while trying to connect to the remote server. Requests that produced this error are safe to retry. """ class ReadTimeout(Timeout): """The server did not send any data in the allotted amount of time.""" class URLRequired(RequestException): """A valid URL is required to make a request.""" class TooManyRedirects(RequestException): """Too many redirects.""" class MissingSchema(RequestException, ValueError): """The URL schema (e.g. http or https) is missing.""" class InvalidSchema(RequestException, ValueError): """See defaults.py for valid schemas.""" class InvalidURL(RequestException, ValueError): """The URL provided was somehow invalid.""" class InvalidHeader(RequestException, ValueError): """The header value provided was somehow invalid.""" class ChunkedEncodingError(RequestException): """The server declared chunked encoding but sent an invalid chunk.""" class ContentDecodingError(RequestException, BaseHTTPError): """Failed to decode response content""" class StreamConsumedError(RequestException, TypeError): """The content for this response was already consumed""" class RetryError(RequestException): """Custom retries logic failed""" class UnrewindableBodyError(RequestException): """Requests encountered an error when trying to rewind a body""" # Warnings class RequestsWarning(Warning): """Base warning for Requests.""" pass class FileModeWarning(RequestsWarning, DeprecationWarning): """A file was opened in text mode, but Requests determined its binary length.""" pass class RequestsDependencyWarning(RequestsWarning): """An imported dependency doesn't match the expected version range.""" pass exceptions.pyc000064400000015406147205436720007462 0ustar00 abc@sdZddlmZdefdYZdefdYZdefdYZd efd YZd efd YZd efdYZ dee fdYZ de fdYZ defdYZ defdYZ deefdYZdeefdYZdeefdYZdeefdYZdefd YZd!eefd"YZd#eefd$YZd%efd&YZd'efd(YZd)efd*YZd+eefd,YZd-efd.YZd/S(0s` requests.exceptions ~~~~~~~~~~~~~~~~~~~ This module contains the set of Requests' exceptions. i(t HTTPErrortRequestExceptioncBseZdZdZRS(sTThere was an ambiguous exception that occurred while handling your request. cOs|jdd}||_|jdd|_|dk rg|j rgt|drg|jj|_ntt|j||dS(sBInitialize RequestException with `request` and `response` objects.tresponsetrequestN(tpoptNoneRRthasattrtsuperRt__init__(tselftargstkwargsR((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyRs (t__name__t __module__t__doc__R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR sRcBseZdZRS(sAn HTTP error occurred.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyRstConnectionErrorcBseZdZRS(sA Connection error occurred.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR st ProxyErrorcBseZdZRS(sA proxy error occurred.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR$stSSLErrorcBseZdZRS(sAn SSL error occurred.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR(stTimeoutcBseZdZRS(sThe request timed out. Catching this error will catch both :exc:`~requests.exceptions.ConnectTimeout` and :exc:`~requests.exceptions.ReadTimeout` errors. (R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR,stConnectTimeoutcBseZdZRS(sThe request timed out while trying to connect to the remote server. Requests that produced this error are safe to retry. (R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR5st ReadTimeoutcBseZdZRS(s@The server did not send any data in the allotted amount of time.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR<st URLRequiredcBseZdZRS(s*A valid URL is required to make a request.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR@stTooManyRedirectscBseZdZRS(sToo many redirects.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyRDst MissingSchemacBseZdZRS(s/The URL schema (e.g. http or https) is missing.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyRHst InvalidSchemacBseZdZRS(s"See defaults.py for valid schemas.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyRLst InvalidURLcBseZdZRS(s%The URL provided was somehow invalid.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyRPst InvalidHeadercBseZdZRS(s.The header value provided was somehow invalid.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyRTstChunkedEncodingErrorcBseZdZRS(s?The server declared chunked encoding but sent an invalid chunk.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyRXstContentDecodingErrorcBseZdZRS(s!Failed to decode response content(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR\stStreamConsumedErrorcBseZdZRS(s2The content for this response was already consumed(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR`st RetryErrorcBseZdZRS(sCustom retries logic failed(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyRdstUnrewindableBodyErrorcBseZdZRS(s:Requests encountered an error when trying to rewind a body(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyRhstRequestsWarningcBseZdZRS(sBase warning for Requests.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR nstFileModeWarningcBseZdZRS(sJA file was opened in text mode, but Requests determined its binary length.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR!sstRequestsDependencyWarningcBseZdZRS(s@An imported dependency doesn't match the expected version range.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR"xsN(Rtpip._vendor.urllib3.exceptionsRt BaseHTTPErrortIOErrorRRRRRRRRRt ValueErrorRRRRRRt TypeErrorRRRtWarningR tDeprecationWarningR!R"(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyts. exceptions.pyo000064400000015406147205436720007476 0ustar00 abc@sdZddlmZdefdYZdefdYZdefdYZd efd YZd efd YZd efdYZ dee fdYZ de fdYZ defdYZ defdYZ deefdYZdeefdYZdeefdYZdeefdYZdefd YZd!eefd"YZd#eefd$YZd%efd&YZd'efd(YZd)efd*YZd+eefd,YZd-efd.YZd/S(0s` requests.exceptions ~~~~~~~~~~~~~~~~~~~ This module contains the set of Requests' exceptions. i(t HTTPErrortRequestExceptioncBseZdZdZRS(sTThere was an ambiguous exception that occurred while handling your request. cOs|jdd}||_|jdd|_|dk rg|j rgt|drg|jj|_ntt|j||dS(sBInitialize RequestException with `request` and `response` objects.tresponsetrequestN(tpoptNoneRRthasattrtsuperRt__init__(tselftargstkwargsR((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyRs (t__name__t __module__t__doc__R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR sRcBseZdZRS(sAn HTTP error occurred.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyRstConnectionErrorcBseZdZRS(sA Connection error occurred.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR st ProxyErrorcBseZdZRS(sA proxy error occurred.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR$stSSLErrorcBseZdZRS(sAn SSL error occurred.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR(stTimeoutcBseZdZRS(sThe request timed out. Catching this error will catch both :exc:`~requests.exceptions.ConnectTimeout` and :exc:`~requests.exceptions.ReadTimeout` errors. (R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR,stConnectTimeoutcBseZdZRS(sThe request timed out while trying to connect to the remote server. Requests that produced this error are safe to retry. (R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR5st ReadTimeoutcBseZdZRS(s@The server did not send any data in the allotted amount of time.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR<st URLRequiredcBseZdZRS(s*A valid URL is required to make a request.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR@stTooManyRedirectscBseZdZRS(sToo many redirects.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyRDst MissingSchemacBseZdZRS(s/The URL schema (e.g. http or https) is missing.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyRHst InvalidSchemacBseZdZRS(s"See defaults.py for valid schemas.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyRLst InvalidURLcBseZdZRS(s%The URL provided was somehow invalid.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyRPst InvalidHeadercBseZdZRS(s.The header value provided was somehow invalid.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyRTstChunkedEncodingErrorcBseZdZRS(s?The server declared chunked encoding but sent an invalid chunk.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyRXstContentDecodingErrorcBseZdZRS(s!Failed to decode response content(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR\stStreamConsumedErrorcBseZdZRS(s2The content for this response was already consumed(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR`st RetryErrorcBseZdZRS(sCustom retries logic failed(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyRdstUnrewindableBodyErrorcBseZdZRS(s:Requests encountered an error when trying to rewind a body(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyRhstRequestsWarningcBseZdZRS(sBase warning for Requests.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR nstFileModeWarningcBseZdZRS(sJA file was opened in text mode, but Requests determined its binary length.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR!sstRequestsDependencyWarningcBseZdZRS(s@An imported dependency doesn't match the expected version range.(R R R(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyR"xsN(Rtpip._vendor.urllib3.exceptionsRt BaseHTTPErrortIOErrorRRRRRRRRRt ValueErrorRRRRRRt TypeErrorRRRtWarningR tDeprecationWarningR!R"(((sC/usr/lib/python2.7/site-packages/pip/_vendor/requests/exceptions.pyts. help.py000064400000007123147205436720006063 0ustar00"""Module containing bug report helper(s).""" from __future__ import print_function import json import platform import sys import ssl from pip._vendor import idna from pip._vendor import urllib3 from pip._vendor import chardet from . import __version__ as requests_version try: from .packages.urllib3.contrib import pyopenssl except ImportError: pyopenssl = None OpenSSL = None cryptography = None else: import OpenSSL import cryptography def _implementation(): """Return a dict with the Python implementation and version. Provide both the name and the version of the Python implementation currently running. For example, on CPython 2.7.5 it will return {'name': 'CPython', 'version': '2.7.5'}. This function works best on CPython and PyPy: in particular, it probably doesn't work for Jython or IronPython. Future investigation should be done to work out the correct shape of the code for those platforms. """ implementation = platform.python_implementation() if implementation == 'CPython': implementation_version = platform.python_version() elif implementation == 'PyPy': implementation_version = '%s.%s.%s' % (sys.pypy_version_info.major, sys.pypy_version_info.minor, sys.pypy_version_info.micro) if sys.pypy_version_info.releaselevel != 'final': implementation_version = ''.join([ implementation_version, sys.pypy_version_info.releaselevel ]) elif implementation == 'Jython': implementation_version = platform.python_version() # Complete Guess elif implementation == 'IronPython': implementation_version = platform.python_version() # Complete Guess else: implementation_version = 'Unknown' return {'name': implementation, 'version': implementation_version} def info(): """Generate information for a bug report.""" try: platform_info = { 'system': platform.system(), 'release': platform.release(), } except IOError: platform_info = { 'system': 'Unknown', 'release': 'Unknown', } implementation_info = _implementation() urllib3_info = {'version': urllib3.__version__} chardet_info = {'version': chardet.__version__} pyopenssl_info = { 'version': None, 'openssl_version': '', } if OpenSSL: pyopenssl_info = { 'version': OpenSSL.__version__, 'openssl_version': '%x' % OpenSSL.SSL.OPENSSL_VERSION_NUMBER, } cryptography_info = { 'version': getattr(cryptography, '__version__', ''), } idna_info = { 'version': getattr(idna, '__version__', ''), } # OPENSSL_VERSION_NUMBER doesn't exist in the Python 2.6 ssl module. system_ssl = getattr(ssl, 'OPENSSL_VERSION_NUMBER', None) system_ssl_info = { 'version': '%x' % system_ssl if system_ssl is not None else '' } return { 'platform': platform_info, 'implementation': implementation_info, 'system_ssl': system_ssl_info, 'using_pyopenssl': pyopenssl is not None, 'pyOpenSSL': pyopenssl_info, 'urllib3': urllib3_info, 'chardet': chardet_info, 'cryptography': cryptography_info, 'idna': idna_info, 'requests': { 'version': requests_version, }, } def main(): """Pretty-print the bug information as JSON.""" print(json.dumps(info(), sort_keys=True, indent=2)) if __name__ == '__main__': main() help.pyc000064400000006503147205436720006227 0ustar00 abc@s dZddlmZddlZddlZddlZddlZddlmZddlm Z ddlm Z ddl m Z ydd lmZWn#ek rdZdZdZnXddlZddlZd Zd Zd Zed kr endS(s'Module containing bug report helper(s).i(tprint_functionN(tidna(turllib3(tchardeti(t __version__(t pyopensslcCstj}|dkr'tj}n|dkrdtjjtjjtjjf}tjjdkrdj |tjjg}qn<|dkrtj}n!|dkrtj}nd}i|d 6|d 6S( sReturn a dict with the Python implementation and version. Provide both the name and the version of the Python implementation currently running. For example, on CPython 2.7.5 it will return {'name': 'CPython', 'version': '2.7.5'}. This function works best on CPython and PyPy: in particular, it probably doesn't work for Jython or IronPython. Future investigation should be done to work out the correct shape of the code for those platforms. tCPythontPyPys%s.%s.%stfinalttJythont IronPythontUnknowntnametversion( tplatformtpython_implementationtpython_versiontsystpypy_version_infotmajortminortmicrot releaseleveltjoin(timplementationtimplementation_version((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/help.pyt_implementations       c Csqy$itjd6tjd6}Wn%tk rKidd6dd6}nXt}itjd6}itjd6}idd6dd6}t rit jd6dt j j d6}nit t ddd6}it tddd6}t td d}i|dk rd|ndd6}i |d 6|d 6|d 6tdk d 6|d6|d6|d6|d6|d6itd6d6S(s&Generate information for a bug report.tsystemtreleaseR RR topenssl_versions%xRtOPENSSL_VERSION_NUMBERRRt system_ssltusing_pyopensslt pyOpenSSLRRt cryptographyRtrequestsN(RRRtIOErrorRRRRtNonetOpenSSLtSSLRtgetattrR#RtsslRtrequests_version( t platform_infotimplementation_infot urllib3_infot chardet_infotpyopenssl_infotcryptography_infot idna_infoR tsystem_ssl_info((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/help.pytinfo;sJ       cCs&ttjtdtdddS(s)Pretty-print the bug information as JSON.t sort_keystindentiN(tprinttjsontdumpsR4tTrue(((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/help.pytmainrst__main__(t__doc__t __future__RR8RRR*t pip._vendorRRRR RR+tpackages.urllib3.contribRt ImportErrorR&R'R#RR4R;t__name__(((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/help.pyts,         ! 7  help.pyo000064400000006503147205436720006243 0ustar00 abc@s dZddlmZddlZddlZddlZddlZddlmZddlm Z ddlm Z ddl m Z ydd lmZWn#ek rdZdZdZnXddlZddlZd Zd Zd Zed kr endS(s'Module containing bug report helper(s).i(tprint_functionN(tidna(turllib3(tchardeti(t __version__(t pyopensslcCstj}|dkr'tj}n|dkrdtjjtjjtjjf}tjjdkrdj |tjjg}qn<|dkrtj}n!|dkrtj}nd}i|d 6|d 6S( sReturn a dict with the Python implementation and version. Provide both the name and the version of the Python implementation currently running. For example, on CPython 2.7.5 it will return {'name': 'CPython', 'version': '2.7.5'}. This function works best on CPython and PyPy: in particular, it probably doesn't work for Jython or IronPython. Future investigation should be done to work out the correct shape of the code for those platforms. tCPythontPyPys%s.%s.%stfinalttJythont IronPythontUnknowntnametversion( tplatformtpython_implementationtpython_versiontsystpypy_version_infotmajortminortmicrot releaseleveltjoin(timplementationtimplementation_version((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/help.pyt_implementations       c Csqy$itjd6tjd6}Wn%tk rKidd6dd6}nXt}itjd6}itjd6}idd6dd6}t rit jd6dt j j d6}nit t ddd6}it tddd6}t td d}i|dk rd|ndd6}i |d 6|d 6|d 6tdk d 6|d6|d6|d6|d6|d6itd6d6S(s&Generate information for a bug report.tsystemtreleaseR RR topenssl_versions%xRtOPENSSL_VERSION_NUMBERRRt system_ssltusing_pyopensslt pyOpenSSLRRt cryptographyRtrequestsN(RRRtIOErrorRRRRtNonetOpenSSLtSSLRtgetattrR#RtsslRtrequests_version( t platform_infotimplementation_infot urllib3_infot chardet_infotpyopenssl_infotcryptography_infot idna_infoR tsystem_ssl_info((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/help.pytinfo;sJ       cCs&ttjtdtdddS(s)Pretty-print the bug information as JSON.t sort_keystindentiN(tprinttjsontdumpsR4tTrue(((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/help.pytmainrst__main__(t__doc__t __future__RR8RRR*t pip._vendorRRRR RR+tpackages.urllib3.contribRt ImportErrorR&R'R#RR4R;t__name__(((s=/usr/lib/python2.7/site-packages/pip/_vendor/requests/help.pyts,         ! 7  hooks.py000064400000001377147205436720006263 0ustar00# -*- coding: utf-8 -*- """ requests.hooks ~~~~~~~~~~~~~~ This module provides the capabilities for the Requests hooks system. Available hooks: ``response``: The response generated from a Request. """ HOOKS = ['response'] def default_hooks(): return dict((event, []) for event in HOOKS) # TODO: response is the only one def dispatch_hook(key, hooks, hook_data, **kwargs): """Dispatches a hook dictionary on a given piece of data.""" hooks = hooks or dict() hooks = hooks.get(key) if hooks: if hasattr(hooks, '__call__'): hooks = [hooks] for hook in hooks: _hook_data = hook(hook_data, **kwargs) if _hook_data is not None: hook_data = _hook_data return hook_data hooks.pyc000064400000002323147205436720006416 0ustar00 abc@s%dZdgZdZdZdS(s requests.hooks ~~~~~~~~~~~~~~ This module provides the capabilities for the Requests hooks system. Available hooks: ``response``: The response generated from a Request. tresponsecCstdtDS(Ncss|]}|gfVqdS(N((t.0tevent((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/hooks.pys s(tdicttHOOKS(((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/hooks.pyt default_hooksscKs{|p t}|j|}|rwt|dr?|g}nx5|D]*}|||}|dk rF|}qFqFWn|S(s6Dispatches a hook dictionary on a given piece of data.t__call__N(RtgetthasattrtNone(tkeythookst hook_datatkwargsthookt _hook_data((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/hooks.pyt dispatch_hooks   N(t__doc__RRR(((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/hooks.pyt s  hooks.pyo000064400000002323147205436720006432 0ustar00 abc@s%dZdgZdZdZdS(s requests.hooks ~~~~~~~~~~~~~~ This module provides the capabilities for the Requests hooks system. Available hooks: ``response``: The response generated from a Request. tresponsecCstdtDS(Ncss|]}|gfVqdS(N((t.0tevent((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/hooks.pys s(tdicttHOOKS(((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/hooks.pyt default_hooksscKs{|p t}|j|}|rwt|dr?|g}nx5|D]*}|||}|dk rF|}qFqFWn|S(s6Dispatches a hook dictionary on a given piece of data.t__call__N(RtgetthasattrtNone(tkeythookst hook_datatkwargsthookt _hook_data((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/hooks.pyt dispatch_hooks   N(t__doc__RRR(((s>/usr/lib/python2.7/site-packages/pip/_vendor/requests/hooks.pyt s  models.py000064400000102403147205436720006413 0ustar00# -*- coding: utf-8 -*- """ requests.models ~~~~~~~~~~~~~~~ This module contains the primary objects that power Requests. """ import collections import datetime import sys # Import encoding now, to avoid implicit import later. # Implicit import within threads may cause LookupError when standard library is in a ZIP, # such as in Embedded Python. See https://github.com/requests/requests/issues/3578. import encodings.idna from pip._vendor.urllib3.fields import RequestField from pip._vendor.urllib3.filepost import encode_multipart_formdata from pip._vendor.urllib3.util import parse_url from pip._vendor.urllib3.exceptions import ( DecodeError, ReadTimeoutError, ProtocolError, LocationParseError) from io import UnsupportedOperation from .hooks import default_hooks from .structures import CaseInsensitiveDict from .auth import HTTPBasicAuth from .cookies import cookiejar_from_dict, get_cookie_header, _copy_cookie_jar from .exceptions import ( HTTPError, MissingSchema, InvalidURL, ChunkedEncodingError, ContentDecodingError, ConnectionError, StreamConsumedError) from ._internal_utils import to_native_string, unicode_is_ascii from .utils import ( guess_filename, get_auth_from_url, requote_uri, stream_decode_response_unicode, to_key_val_list, parse_header_links, iter_slices, guess_json_utf, super_len, check_header_validity) from .compat import ( cookielib, urlunparse, urlsplit, urlencode, str, bytes, is_py2, chardet, builtin_str, basestring) from .compat import json as complexjson from .status_codes import codes #: The set of HTTP status codes that indicate an automatically #: processable redirect. REDIRECT_STATI = ( codes.moved, # 301 codes.found, # 302 codes.other, # 303 codes.temporary_redirect, # 307 codes.permanent_redirect, # 308 ) DEFAULT_REDIRECT_LIMIT = 30 CONTENT_CHUNK_SIZE = 10 * 1024 ITER_CHUNK_SIZE = 512 class RequestEncodingMixin(object): @property def path_url(self): """Build the path URL to use.""" url = [] p = urlsplit(self.url) path = p.path if not path: path = '/' url.append(path) query = p.query if query: url.append('?') url.append(query) return ''.join(url) @staticmethod def _encode_params(data): """Encode parameters in a piece of data. Will successfully encode parameters when passed as a dict or a list of 2-tuples. Order is retained if data is a list of 2-tuples but arbitrary if parameters are supplied as a dict. """ if isinstance(data, (str, bytes)): return data elif hasattr(data, 'read'): return data elif hasattr(data, '__iter__'): result = [] for k, vs in to_key_val_list(data): if isinstance(vs, basestring) or not hasattr(vs, '__iter__'): vs = [vs] for v in vs: if v is not None: result.append( (k.encode('utf-8') if isinstance(k, str) else k, v.encode('utf-8') if isinstance(v, str) else v)) return urlencode(result, doseq=True) else: return data @staticmethod def _encode_files(files, data): """Build the body for a multipart/form-data request. Will successfully encode files when passed as a dict or a list of tuples. Order is retained if data is a list of tuples but arbitrary if parameters are supplied as a dict. The tuples may be 2-tuples (filename, fileobj), 3-tuples (filename, fileobj, contentype) or 4-tuples (filename, fileobj, contentype, custom_headers). """ if (not files): raise ValueError("Files must be provided.") elif isinstance(data, basestring): raise ValueError("Data must not be a string.") new_fields = [] fields = to_key_val_list(data or {}) files = to_key_val_list(files or {}) for field, val in fields: if isinstance(val, basestring) or not hasattr(val, '__iter__'): val = [val] for v in val: if v is not None: # Don't call str() on bytestrings: in Py3 it all goes wrong. if not isinstance(v, bytes): v = str(v) new_fields.append( (field.decode('utf-8') if isinstance(field, bytes) else field, v.encode('utf-8') if isinstance(v, str) else v)) for (k, v) in files: # support for explicit filename ft = None fh = None if isinstance(v, (tuple, list)): if len(v) == 2: fn, fp = v elif len(v) == 3: fn, fp, ft = v else: fn, fp, ft, fh = v else: fn = guess_filename(v) or k fp = v if isinstance(fp, (str, bytes, bytearray)): fdata = fp else: fdata = fp.read() rf = RequestField(name=k, data=fdata, filename=fn, headers=fh) rf.make_multipart(content_type=ft) new_fields.append(rf) body, content_type = encode_multipart_formdata(new_fields) return body, content_type class RequestHooksMixin(object): def register_hook(self, event, hook): """Properly register a hook.""" if event not in self.hooks: raise ValueError('Unsupported event specified, with event name "%s"' % (event)) if isinstance(hook, collections.Callable): self.hooks[event].append(hook) elif hasattr(hook, '__iter__'): self.hooks[event].extend(h for h in hook if isinstance(h, collections.Callable)) def deregister_hook(self, event, hook): """Deregister a previously registered hook. Returns True if the hook existed, False if not. """ try: self.hooks[event].remove(hook) return True except ValueError: return False class Request(RequestHooksMixin): """A user-created :class:`Request ` object. Used to prepare a :class:`PreparedRequest `, which is sent to the server. :param method: HTTP method to use. :param url: URL to send. :param headers: dictionary of headers to send. :param files: dictionary of {filename: fileobject} files to multipart upload. :param data: the body to attach to the request. If a dictionary is provided, form-encoding will take place. :param json: json for the body to attach to the request (if files or data is not specified). :param params: dictionary of URL parameters to append to the URL. :param auth: Auth handler or (user, pass) tuple. :param cookies: dictionary or CookieJar of cookies to attach to this request. :param hooks: dictionary of callback hooks, for internal usage. Usage:: >>> import requests >>> req = requests.Request('GET', 'http://httpbin.org/get') >>> req.prepare() """ def __init__(self, method=None, url=None, headers=None, files=None, data=None, params=None, auth=None, cookies=None, hooks=None, json=None): # Default empty dicts for dict params. data = [] if data is None else data files = [] if files is None else files headers = {} if headers is None else headers params = {} if params is None else params hooks = {} if hooks is None else hooks self.hooks = default_hooks() for (k, v) in list(hooks.items()): self.register_hook(event=k, hook=v) self.method = method self.url = url self.headers = headers self.files = files self.data = data self.json = json self.params = params self.auth = auth self.cookies = cookies def __repr__(self): return '' % (self.method) def prepare(self): """Constructs a :class:`PreparedRequest ` for transmission and returns it.""" p = PreparedRequest() p.prepare( method=self.method, url=self.url, headers=self.headers, files=self.files, data=self.data, json=self.json, params=self.params, auth=self.auth, cookies=self.cookies, hooks=self.hooks, ) return p class PreparedRequest(RequestEncodingMixin, RequestHooksMixin): """The fully mutable :class:`PreparedRequest ` object, containing the exact bytes that will be sent to the server. Generated from either a :class:`Request ` object or manually. Usage:: >>> import requests >>> req = requests.Request('GET', 'http://httpbin.org/get') >>> r = req.prepare() >>> s = requests.Session() >>> s.send(r) """ def __init__(self): #: HTTP verb to send to the server. self.method = None #: HTTP URL to send the request to. self.url = None #: dictionary of HTTP headers. self.headers = None # The `CookieJar` used to create the Cookie header will be stored here # after prepare_cookies is called self._cookies = None #: request body to send to the server. self.body = None #: dictionary of callback hooks, for internal usage. self.hooks = default_hooks() #: integer denoting starting position of a readable file-like body. self._body_position = None def prepare(self, method=None, url=None, headers=None, files=None, data=None, params=None, auth=None, cookies=None, hooks=None, json=None): """Prepares the entire request with the given parameters.""" self.prepare_method(method) self.prepare_url(url, params) self.prepare_headers(headers) self.prepare_cookies(cookies) self.prepare_body(data, files, json) self.prepare_auth(auth, url) # Note that prepare_auth must be last to enable authentication schemes # such as OAuth to work on a fully prepared request. # This MUST go after prepare_auth. Authenticators could add a hook self.prepare_hooks(hooks) def __repr__(self): return '' % (self.method) def copy(self): p = PreparedRequest() p.method = self.method p.url = self.url p.headers = self.headers.copy() if self.headers is not None else None p._cookies = _copy_cookie_jar(self._cookies) p.body = self.body p.hooks = self.hooks p._body_position = self._body_position return p def prepare_method(self, method): """Prepares the given HTTP method.""" self.method = method if self.method is not None: self.method = to_native_string(self.method.upper()) @staticmethod def _get_idna_encoded_host(host): import idna try: host = idna.encode(host, uts46=True).decode('utf-8') except idna.IDNAError: raise UnicodeError return host def prepare_url(self, url, params): """Prepares the given HTTP URL.""" #: Accept objects that have string representations. #: We're unable to blindly call unicode/str functions #: as this will include the bytestring indicator (b'') #: on python 3.x. #: https://github.com/requests/requests/pull/2238 if isinstance(url, bytes): url = url.decode('utf8') else: url = unicode(url) if is_py2 else str(url) # Remove leading whitespaces from url url = url.lstrip() # Don't do any URL preparation for non-HTTP schemes like `mailto`, # `data` etc to work around exceptions from `url_parse`, which # handles RFC 3986 only. if ':' in url and not url.lower().startswith('http'): self.url = url return # Support for unicode domain names and paths. try: scheme, auth, host, port, path, query, fragment = parse_url(url) except LocationParseError as e: raise InvalidURL(*e.args) if not scheme: error = ("Invalid URL {0!r}: No schema supplied. Perhaps you meant http://{0}?") error = error.format(to_native_string(url, 'utf8')) raise MissingSchema(error) if not host: raise InvalidURL("Invalid URL %r: No host supplied" % url) # In general, we want to try IDNA encoding the hostname if the string contains # non-ASCII characters. This allows users to automatically get the correct IDNA # behaviour. For strings containing only ASCII characters, we need to also verify # it doesn't start with a wildcard (*), before allowing the unencoded hostname. if not unicode_is_ascii(host): try: host = self._get_idna_encoded_host(host) except UnicodeError: raise InvalidURL('URL has an invalid label.') elif host.startswith(u'*'): raise InvalidURL('URL has an invalid label.') # Carefully reconstruct the network location netloc = auth or '' if netloc: netloc += '@' netloc += host if port: netloc += ':' + str(port) # Bare domains aren't valid URLs. if not path: path = '/' if is_py2: if isinstance(scheme, str): scheme = scheme.encode('utf-8') if isinstance(netloc, str): netloc = netloc.encode('utf-8') if isinstance(path, str): path = path.encode('utf-8') if isinstance(query, str): query = query.encode('utf-8') if isinstance(fragment, str): fragment = fragment.encode('utf-8') if isinstance(params, (str, bytes)): params = to_native_string(params) enc_params = self._encode_params(params) if enc_params: if query: query = '%s&%s' % (query, enc_params) else: query = enc_params url = requote_uri(urlunparse([scheme, netloc, path, None, query, fragment])) self.url = url def prepare_headers(self, headers): """Prepares the given HTTP headers.""" self.headers = CaseInsensitiveDict() if headers: for header in headers.items(): # Raise exception on invalid header value. check_header_validity(header) name, value = header self.headers[to_native_string(name)] = value def prepare_body(self, data, files, json=None): """Prepares the given HTTP body data.""" # Check if file, fo, generator, iterator. # If not, run through normal process. # Nottin' on you. body = None content_type = None if not data and json is not None: # urllib3 requires a bytes-like body. Python 2's json.dumps # provides this natively, but Python 3 gives a Unicode string. content_type = 'application/json' body = complexjson.dumps(json) if not isinstance(body, bytes): body = body.encode('utf-8') is_stream = all([ hasattr(data, '__iter__'), not isinstance(data, (basestring, list, tuple, collections.Mapping)) ]) try: length = super_len(data) except (TypeError, AttributeError, UnsupportedOperation): length = None if is_stream: body = data if getattr(body, 'tell', None) is not None: # Record the current file position before reading. # This will allow us to rewind a file in the event # of a redirect. try: self._body_position = body.tell() except (IOError, OSError): # This differentiates from None, allowing us to catch # a failed `tell()` later when trying to rewind the body self._body_position = object() if files: raise NotImplementedError('Streamed bodies and files are mutually exclusive.') if length: self.headers['Content-Length'] = builtin_str(length) else: self.headers['Transfer-Encoding'] = 'chunked' else: # Multi-part file uploads. if files: (body, content_type) = self._encode_files(files, data) else: if data: body = self._encode_params(data) if isinstance(data, basestring) or hasattr(data, 'read'): content_type = None else: content_type = 'application/x-www-form-urlencoded' self.prepare_content_length(body) # Add content-type if it wasn't explicitly provided. if content_type and ('content-type' not in self.headers): self.headers['Content-Type'] = content_type self.body = body def prepare_content_length(self, body): """Prepare Content-Length header based on request method and body""" if body is not None: length = super_len(body) if length: # If length exists, set it. Otherwise, we fallback # to Transfer-Encoding: chunked. self.headers['Content-Length'] = builtin_str(length) elif self.method not in ('GET', 'HEAD') and self.headers.get('Content-Length') is None: # Set Content-Length to 0 for methods that can have a body # but don't provide one. (i.e. not GET or HEAD) self.headers['Content-Length'] = '0' def prepare_auth(self, auth, url=''): """Prepares the given HTTP auth data.""" # If no Auth is explicitly provided, extract it from the URL first. if auth is None: url_auth = get_auth_from_url(self.url) auth = url_auth if any(url_auth) else None if auth: if isinstance(auth, tuple) and len(auth) == 2: # special-case basic HTTP auth auth = HTTPBasicAuth(*auth) # Allow auth to make its changes. r = auth(self) # Update self to reflect the auth changes. self.__dict__.update(r.__dict__) # Recompute Content-Length self.prepare_content_length(self.body) def prepare_cookies(self, cookies): """Prepares the given HTTP cookie data. This function eventually generates a ``Cookie`` header from the given cookies using cookielib. Due to cookielib's design, the header will not be regenerated if it already exists, meaning this function can only be called once for the life of the :class:`PreparedRequest ` object. Any subsequent calls to ``prepare_cookies`` will have no actual effect, unless the "Cookie" header is removed beforehand. """ if isinstance(cookies, cookielib.CookieJar): self._cookies = cookies else: self._cookies = cookiejar_from_dict(cookies) cookie_header = get_cookie_header(self._cookies, self) if cookie_header is not None: self.headers['Cookie'] = cookie_header def prepare_hooks(self, hooks): """Prepares the given hooks.""" # hooks can be passed as None to the prepare method and to this # method. To prevent iterating over None, simply use an empty list # if hooks is False-y hooks = hooks or [] for event in hooks: self.register_hook(event, hooks[event]) class Response(object): """The :class:`Response ` object, which contains a server's response to an HTTP request. """ __attrs__ = [ '_content', 'status_code', 'headers', 'url', 'history', 'encoding', 'reason', 'cookies', 'elapsed', 'request' ] def __init__(self): self._content = False self._content_consumed = False self._next = None #: Integer Code of responded HTTP Status, e.g. 404 or 200. self.status_code = None #: Case-insensitive Dictionary of Response Headers. #: For example, ``headers['content-encoding']`` will return the #: value of a ``'Content-Encoding'`` response header. self.headers = CaseInsensitiveDict() #: File-like object representation of response (for advanced usage). #: Use of ``raw`` requires that ``stream=True`` be set on the request. # This requirement does not apply for use internally to Requests. self.raw = None #: Final URL location of Response. self.url = None #: Encoding to decode with when accessing r.text. self.encoding = None #: A list of :class:`Response ` objects from #: the history of the Request. Any redirect responses will end #: up here. The list is sorted from the oldest to the most recent request. self.history = [] #: Textual reason of responded HTTP Status, e.g. "Not Found" or "OK". self.reason = None #: A CookieJar of Cookies the server sent back. self.cookies = cookiejar_from_dict({}) #: The amount of time elapsed between sending the request #: and the arrival of the response (as a timedelta). #: This property specifically measures the time taken between sending #: the first byte of the request and finishing parsing the headers. It #: is therefore unaffected by consuming the response content or the #: value of the ``stream`` keyword argument. self.elapsed = datetime.timedelta(0) #: The :class:`PreparedRequest ` object to which this #: is a response. self.request = None def __enter__(self): return self def __exit__(self, *args): self.close() def __getstate__(self): # Consume everything; accessing the content attribute makes # sure the content has been fully read. if not self._content_consumed: self.content return dict( (attr, getattr(self, attr, None)) for attr in self.__attrs__ ) def __setstate__(self, state): for name, value in state.items(): setattr(self, name, value) # pickled objects do not have .raw setattr(self, '_content_consumed', True) setattr(self, 'raw', None) def __repr__(self): return '' % (self.status_code) def __bool__(self): """Returns True if :attr:`status_code` is less than 400. This attribute checks if the status code of the response is between 400 and 600 to see if there was a client error or a server error. If the status code, is between 200 and 400, this will return True. This is **not** a check to see if the response code is ``200 OK``. """ return self.ok def __nonzero__(self): """Returns True if :attr:`status_code` is less than 400. This attribute checks if the status code of the response is between 400 and 600 to see if there was a client error or a server error. If the status code, is between 200 and 400, this will return True. This is **not** a check to see if the response code is ``200 OK``. """ return self.ok def __iter__(self): """Allows you to use a response as an iterator.""" return self.iter_content(128) @property def ok(self): """Returns True if :attr:`status_code` is less than 400. This attribute checks if the status code of the response is between 400 and 600 to see if there was a client error or a server error. If the status code, is between 200 and 400, this will return True. This is **not** a check to see if the response code is ``200 OK``. """ try: self.raise_for_status() except HTTPError: return False return True @property def is_redirect(self): """True if this Response is a well-formed HTTP redirect that could have been processed automatically (by :meth:`Session.resolve_redirects`). """ return ('location' in self.headers and self.status_code in REDIRECT_STATI) @property def is_permanent_redirect(self): """True if this Response one of the permanent versions of redirect.""" return ('location' in self.headers and self.status_code in (codes.moved_permanently, codes.permanent_redirect)) @property def next(self): """Returns a PreparedRequest for the next request in a redirect chain, if there is one.""" return self._next @property def apparent_encoding(self): """The apparent encoding, provided by the chardet library.""" return chardet.detect(self.content)['encoding'] def iter_content(self, chunk_size=1, decode_unicode=False): """Iterates over the response data. When stream=True is set on the request, this avoids reading the content at once into memory for large responses. The chunk size is the number of bytes it should read into memory. This is not necessarily the length of each item returned as decoding can take place. chunk_size must be of type int or None. A value of None will function differently depending on the value of `stream`. stream=True will read data as it arrives in whatever size the chunks are received. If stream=False, data is returned as a single chunk. If decode_unicode is True, content will be decoded using the best available encoding based on the response. """ def generate(): # Special case for urllib3. if hasattr(self.raw, 'stream'): try: for chunk in self.raw.stream(chunk_size, decode_content=True): yield chunk except ProtocolError as e: raise ChunkedEncodingError(e) except DecodeError as e: raise ContentDecodingError(e) except ReadTimeoutError as e: raise ConnectionError(e) else: # Standard file-like object. while True: chunk = self.raw.read(chunk_size) if not chunk: break yield chunk self._content_consumed = True if self._content_consumed and isinstance(self._content, bool): raise StreamConsumedError() elif chunk_size is not None and not isinstance(chunk_size, int): raise TypeError("chunk_size must be an int, it is instead a %s." % type(chunk_size)) # simulate reading small chunks of the content reused_chunks = iter_slices(self._content, chunk_size) stream_chunks = generate() chunks = reused_chunks if self._content_consumed else stream_chunks if decode_unicode: chunks = stream_decode_response_unicode(chunks, self) return chunks def iter_lines(self, chunk_size=ITER_CHUNK_SIZE, decode_unicode=None, delimiter=None): """Iterates over the response data, one line at a time. When stream=True is set on the request, this avoids reading the content at once into memory for large responses. .. note:: This method is not reentrant safe. """ pending = None for chunk in self.iter_content(chunk_size=chunk_size, decode_unicode=decode_unicode): if pending is not None: chunk = pending + chunk if delimiter: lines = chunk.split(delimiter) else: lines = chunk.splitlines() if lines and lines[-1] and chunk and lines[-1][-1] == chunk[-1]: pending = lines.pop() else: pending = None for line in lines: yield line if pending is not None: yield pending @property def content(self): """Content of the response, in bytes.""" if self._content is False: # Read the contents. if self._content_consumed: raise RuntimeError( 'The content for this response was already consumed') if self.status_code == 0 or self.raw is None: self._content = None else: self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes() self._content_consumed = True # don't need to release the connection; that's been handled by urllib3 # since we exhausted the data. return self._content @property def text(self): """Content of the response, in unicode. If Response.encoding is None, encoding will be guessed using ``chardet``. The encoding of the response content is determined based solely on HTTP headers, following RFC 2616 to the letter. If you can take advantage of non-HTTP knowledge to make a better guess at the encoding, you should set ``r.encoding`` appropriately before accessing this property. """ # Try charset from content-type content = None encoding = self.encoding if not self.content: return str('') # Fallback to auto-detected encoding. if self.encoding is None: encoding = self.apparent_encoding # Decode unicode from given encoding. try: content = str(self.content, encoding, errors='replace') except (LookupError, TypeError): # A LookupError is raised if the encoding was not found which could # indicate a misspelling or similar mistake. # # A TypeError can be raised if encoding is None # # So we try blindly encoding. content = str(self.content, errors='replace') return content def json(self, **kwargs): r"""Returns the json-encoded content of a response, if any. :param \*\*kwargs: Optional arguments that ``json.loads`` takes. :raises ValueError: If the response body does not contain valid json. """ if not self.encoding and self.content and len(self.content) > 3: # No encoding set. JSON RFC 4627 section 3 states we should expect # UTF-8, -16 or -32. Detect which one to use; If the detection or # decoding fails, fall back to `self.text` (using chardet to make # a best guess). encoding = guess_json_utf(self.content) if encoding is not None: try: return complexjson.loads( self.content.decode(encoding), **kwargs ) except UnicodeDecodeError: # Wrong UTF codec detected; usually because it's not UTF-8 # but some other 8-bit codec. This is an RFC violation, # and the server didn't bother to tell us what codec *was* # used. pass return complexjson.loads(self.text, **kwargs) @property def links(self): """Returns the parsed header links of the response, if any.""" header = self.headers.get('link') # l = MultiDict() l = {} if header: links = parse_header_links(header) for link in links: key = link.get('rel') or link.get('url') l[key] = link return l def raise_for_status(self): """Raises stored :class:`HTTPError`, if one occurred.""" http_error_msg = '' if isinstance(self.reason, bytes): # We attempt to decode utf-8 first because some servers # choose to localize their reason strings. If the string # isn't utf-8, we fall back to iso-8859-1 for all other # encodings. (See PR #3538) try: reason = self.reason.decode('utf-8') except UnicodeDecodeError: reason = self.reason.decode('iso-8859-1') else: reason = self.reason if 400 <= self.status_code < 500: http_error_msg = u'%s Client Error: %s for url: %s' % (self.status_code, reason, self.url) elif 500 <= self.status_code < 600: http_error_msg = u'%s Server Error: %s for url: %s' % (self.status_code, reason, self.url) if http_error_msg: raise HTTPError(http_error_msg, response=self) def close(self): """Releases the connection back to the pool. Once this method has been called the underlying ``raw`` object must not be accessed again. *Note: Should not normally need to be called explicitly.* """ if not self._content_consumed: self.raw.close() release_conn = getattr(self.raw, 'release_conn', None) if release_conn is not None: release_conn()