3 P\&H@s|dZddlZddlZy(ddlmZddlmZddlmZWn8ek rtddlmZddlmZddlmZYnXyddl m Z ddlm Z WnNek ryddl m Z ddlm Z Wnek rdZ dZ YnXYnXej dkrdZn4ydd lmZWn"ek r$dd lmZYnXej d kr8dZn4ydd lmZWn"ek rjdd lmZYnXej d kr~dZnTydd lmZWnBek rydd lmZWnek rdZYnXYnXejd kZer ddlmZmZddlZddlmZm Z n0ddl!mZmZddl"Zddl#mZddl$m Z ye%Z%Wne&k rbe'e(fZ%YnXGdddeZ)d!Z*dS)"zPrivate module full of compatibility hacks. Primarily this is for downstream redistributions of requests that unvendor urllib3 without providing a shim. .. warning:: This module is private. If you use it, and something breaks, you were warned N)fields)filepost) poolmanager)HTTPConnection) connectioni)timeouti) appenginei)PyOpenSSLContext)MappingMutableMapping) urlencodeurljoin)r )rcseZdZdZd-fdd ZddZddZd d Zd d Zd dZ ddZ e sZe j Z e jZeZddZddZefddZddZddZddZddZeZeZeZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Z e!d+d,Z"Z#S).HTTPHeaderDictap :param headers: An iterable of field-value pairs. Must not contain multiple field names when compared case-insensitively. :param kwargs: Additional field-value pairs to pass in to ``dict.update``. A ``dict`` like container for storing HTTP Headers. Field names are stored and compared case-insensitively in compliance with RFC 7230. Iteration provides the first case-sensitive key seen for each case-insensitive pair. Using ``__setitem__`` syntax overwrites fields that compare equal case-insensitively in order to maintain ``dict``'s api. For fields that compare equal, instead create a new ``HTTPHeaderDict`` and use ``.add`` in a loop. If multiple fields that are equal case-insensitively are passed to the constructor or ``.update``, the behavior is undefined and some will be lost. >>> headers = HTTPHeaderDict() >>> headers.add('Set-Cookie', 'foo=bar') >>> headers.add('set-cookie', 'baz=quxx') >>> headers['content-length'] = '7' >>> headers['SET-cookie'] 'foo=bar, baz=quxx' >>> headers['Content-Length'] '7' Nc sNtt|ji|_|dk rsz(HTTPHeaderDict.__eq__..css|]\}}|j|fVqdS)N)r)r&r'r(rrrr)s)rr hasattrtypedict itermerged)rotherrrr__eq__s  zHTTPHeaderDict.__eq__cCs |j| S)N)r/)rr.rrr__ne__szHTTPHeaderDict.__ne__cCs t|jS)N)lenr)rrrr__len__szHTTPHeaderDict.__len__ccs"x|jjD]}|dVq WdS)Nr)rvalues)rvalsrrr__iter__szHTTPHeaderDict.__iter__c Cs<y ||}Wn tk r,||jkr(|SX||=|SdS)zD.pop(k[,d]) -> v, remove specified key and return its value. If key is not found, d is returned if given, otherwise KeyError is raised. N)KeyError_HTTPHeaderDict__marker)rrdefaultvaluerrrpops   zHTTPHeaderDict.popc Cs$y ||=Wntk rYnXdS)N)r6)rrrrrdiscards zHTTPHeaderDict.discardcCsX|j}||f}|jj||}||k rTt|tr<|j|n|d|d|g|j|<dS)zAdds a (name, value) pair, doesn't overwrite the value if it already exists. >>> headers = HTTPHeaderDict(foo='bar') >>> headers.add('Foo', 'baz') >>> headers['foo'] 'bar, baz' rr N)rr setdefaultrlistappend)rrrZ key_lowerZnew_valsr4rrradds   zHTTPHeaderDict.addcOst|dkrtdjt|t|dkr2|dnf}t|trdx|jD]\}}|j||qJWnvt|trxj|D]}|j|||qtWnLt|drx@|j D]}|j|||qWnx|D]\}}|j||qWx |j D]\}}|j||qWdS)zGeneric import function for any type of header-like object. Adapted version of MutableMapping.update in order to insert items with self.add instead of self.__setitem__ r z8extend() takes at most 1 positional arguments ({} given)rr%N) r1 TypeErrorformatrr iteritemsr?r r*r%items)rargsrr.rrr9rrrrs"      zHTTPHeaderDict.extendc CsLy|j|j}Wntk r&gSXt|tr<|dgS|ddSdS)zmReturns a list of all the values for the named field. Returns an empty list if the key doesn't exist.r N)rrr6rtuple)rrr4rrrgetlists  zHTTPHeaderDict.getlistcCsdt|jt|jfS)Nz%s(%s))r+__name__r,r-)rrrr__repr__szHTTPHeaderDict.__repr__cCsBx<|D]4}|j|}t|tr&t|}|g||j|j<qWdS)N)rFrr=rr)rr.rrrrrrs    zHTTPHeaderDict._copy_fromcCst|}|j||S)N)r+r)rZclonerrrcopys  zHTTPHeaderDict.copyccsDx>|D]6}|j|j}x"|ddD]}|d|fVq&WqWdS)z8Iterate over all header lines, including duplicate ones.r Nr)rr)rrr4rrrrrBs zHTTPHeaderDict.iteritemsccs<x6|D].}|j|j}|ddj|ddfVqWdS)z:Iterate over all headers, merging duplicate ones together.rz, r N)rrr!)rrrrrrr-s zHTTPHeaderDict.itermergedcCs t|jS)N)r=rB)rrrrrC szHTTPHeaderDict.itemscCsng}x`|jD]V}|jdr@|d\}}||d|jf|d<q |jdd\}}|j||jfq W||S) z4Read headers from a Python 2 httplib message object.  r z :)rJrKrM)r startswithrstripsplitr>strip)clsmessagerlinerr9rrr from_httplib#s   zHTTPHeaderDict.from_httplib)N)$rG __module__ __qualname____doc__rrr"r#r$r/r0PY3r ZiterkeysZ itervaluesobjectr7r2r5r:r;r?rrFZ getheadersZgetallmatchingheadersZigetrHrrIrBr-rC classmethodrU __classcell__rr)rrrRs:   r basestringrrrrrqueuer gaecontribrr )r r) r]rrrrrrr^r r_rr )+rXsysZrequestsZrequests.packages.urllib3rrr ImportErrorZurllib3Z$requests.packages.urllib3.connectionrrZurllib3.connectionZ __build__rZrequests.packages.urllib3.utilZ urllib3.utilr_Z!requests.packages.urllib3.contribrZurllib3.contribr Z+requests.packages.urllib3.contrib.pyopensslZurllib3.contrib.pyopenssl version_inforYcollections.abcr r r^Z urllib.parser r collectionsZQueueZurllibZurlparser] NameErrorstrbytesr__all__rrrr s            g