3

Z'íc;*ã@sàddlmZyddlmZmZWn$ek
rDddlmZmZYnXyddlmZWn"ek
rxGdd„dƒZYnXddlm	Z	ddl
mZdd	lm
Z
dd
lmZmZddgZeƒZGd
d„deƒZGdd„deƒZdS)é)Úabsolute_import)ÚMappingÚMutableMapping)ÚRLockc@seZdZdd„Zdd„ZdS)rcCsdS)N©)Úselfrrú7/tmp/pip-build-gk9425m9/urllib3/urllib3/_collections.pyÚ	__enter__szRLock.__enter__cCsdS)Nr)rÚexc_typeÚ	exc_valueÚ	tracebackrrrÚ__exit__szRLock.__exit__N)Ú__name__Ú
__module__Ú__qualname__r	r
rrrrrsr)ÚOrderedDicté)Ú
InvalidHeader)Úsix)ÚiterkeysÚ
itervaluesÚRecentlyUsedContainerÚHTTPHeaderDictc@sVeZdZdZeZddd„Zdd„Zdd	„Zd
d„Z	dd
„Z
dd„Zdd„Zdd„Z
dS)ra‘
    Provides a thread-safe dict-like container which maintains up to
    ``maxsize`` keys while throwing away the least-recently-used keys beyond
    ``maxsize``.

    :param maxsize:
        Maximum number of recent elements to retain.

    :param dispose_func:
        Every time an item is evicted from the container,
        ``dispose_func(value)`` is called.  Callback which will get called
    é
NcCs"||_||_|jƒ|_tƒ|_dS)N)Ú_maxsizeÚdispose_funcÚContainerClsÚ
_containerrÚlock)rÚmaxsizerrrrÚ__init__/s
zRecentlyUsedContainer.__init__c
Cs,|j|jj|ƒ}||j|<|SQRXdS)N)rrÚpop)rÚkeyÚitemrrrÚ__getitem__6s
z!RecentlyUsedContainer.__getitem__c
Cslt}|j@|jj|tƒ}||j|<t|jƒ|jkrF|jjdd\}}WdQRX|jrh|tk	rh|j|ƒdS)NF)Úlast)Ú_NullrrÚgetÚlenrÚpopitemr)rr"ÚvalueÚ
evicted_valueÚ_keyrrrÚ__setitem__=s
z!RecentlyUsedContainer.__setitem__c	Cs2|j|jj|ƒ}WdQRX|jr.|j|ƒdS)N)rrr!r)rr"r*rrrÚ__delitem__Lsz!RecentlyUsedContainer.__delitem__c	Cs|jt|jƒSQRXdS)N)rr(r)rrrrÚ__len__SszRecentlyUsedContainer.__len__cCstdƒ‚dS)Nz7Iteration over this class is unlikely to be threadsafe.)ÚNotImplementedError)rrrrÚ__iter__WszRecentlyUsedContainer.__iter__c
CsL|jtt|jƒƒ}|jjƒWdQRX|jrHx|D]}|j|ƒq6WdS)N)rÚlistrrÚclearr)rÚvaluesr*rrrr3\s
zRecentlyUsedContainer.clearc
Cs |jtt|jƒƒSQRXdS)N)rr2rr)rrrrÚkeysfszRecentlyUsedContainer.keys)rN)rrrÚ__doc__rrr r$r-r.r/r1r3r5rrrrrs

csöeZdZdZd-‡fdd„	Zdd„Zdd„Zd	d
„Zdd„Zd
d„Z	dd„Z
ejr\e
jZe
jZeƒZdd„Zdd„Zefdd„Zdd„Zdd„Zdd„Zefdd„ZeZeZeZeZdd „Zd!d"„Zd#d$„Zd%d&„Z d'd(„Z!d)d*„Z"e#d+d,„ƒZ$‡Z%S).rap
    :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'
    NcsPtt|ƒjƒtƒ|_|dk	r>t|tƒr4|j|ƒn
|j|ƒ|rL|j|ƒdS)N)Úsuperrr rrÚ
isinstanceÚ
_copy_fromÚextend)rÚheadersÚkwargs)Ú	__class__rrr s

zHTTPHeaderDict.__init__cCs ||g|j|jƒ<|j|jƒS)N)rÚlower)rr"Úvalrrrr-˜szHTTPHeaderDict.__setitem__cCs |j|jƒ}dj|dd…ƒS)Nz, r)rr>Újoin)rr"r?rrrr$œszHTTPHeaderDict.__getitem__cCs|j|jƒ=dS)N)rr>)rr"rrrr. szHTTPHeaderDict.__delitem__cCs|jƒ|jkS)N)r>r)rr"rrrÚ__contains__£szHTTPHeaderDict.__contains__cCsbt|tƒrt|dƒrdSt|t|ƒƒs6t|ƒ|ƒ}tdd„|jƒDƒƒtdd„|jƒDƒƒkS)Nr5Fcss|]\}}|jƒ|fVqdS)N)r>)Ú.0ÚkÚvrrrú	<genexpr>«sz(HTTPHeaderDict.__eq__.<locals>.<genexpr>css|]\}}|jƒ|fVqdS)N)r>)rBrCrDrrrrE¬s)r8rÚhasattrÚtypeÚdictÚ
itermerged)rÚotherrrrÚ__eq__¦szHTTPHeaderDict.__eq__cCs|j|ƒS)N)rK)rrJrrrÚ__ne__¯szHTTPHeaderDict.__ne__cCs
t|jƒS)N)r(r)rrrrr/¸szHTTPHeaderDict.__len__ccs"x|jjƒD]}|dVqWdS)Nr)rr4)rÚvalsrrrr1»szHTTPHeaderDict.__iter__cCs<y||}Wn tk
r,||jkr(‚|SX||=|SdS)z§D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
        If key is not found, d is returned if given, otherwise KeyError is raised.
        N)ÚKeyErrorÚ_HTTPHeaderDict__marker)rr"Údefaultr*rrrr!Às
zHTTPHeaderDict.popcCs$y
||=Wntk
rYnXdS)N)rN)rr"rrrÚdiscardÑs
zHTTPHeaderDict.discardcCs4|jƒ}||g}|jj||ƒ}||k	r0|j|ƒdS)zâAdds 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'
        N)r>rÚ
setdefaultÚappend)rr"r?Ú	key_lowerÚnew_valsrMrrrÚadd×s
	zHTTPHeaderDict.addcOst|ƒdkrtdjt|ƒƒƒ‚t|ƒdkr2|dnf}t|tƒrdx˜|jƒD]\}}|j||ƒqJWnvt|tƒrŽxj|D]}|j|||ƒqtWnLt|dƒr¼x@|j	ƒD]}|j|||ƒq¢Wnx|D]\}}|j||ƒqÂWx |j
ƒD]\}}|j||ƒqäWdS)zÀGeneric 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__
        rz9extend() takes at most 1 positional arguments ({0} given)rr5N)r(Ú	TypeErrorÚformatr8rÚ	iteritemsrVrrFr5Úitems)rÚargsr<rJr"r?r*rrrr:çs$



zHTTPHeaderDict.extendcCsFy|j|jƒ}Wn"tk
r4||jkr0gS|SX|dd…SdS)zmReturns a list of all the values for the named field. Returns an
        empty list if the key doesn't exist.rN)rr>rNrO)rr"rPrMrrrÚgetlists
zHTTPHeaderDict.getlistcCsdt|ƒjt|jƒƒfS)Nz%s(%s))rGrrHrI)rrrrÚ__repr__szHTTPHeaderDict.__repr__cCsBx<|D]4}|j|ƒ}t|tƒr&t|ƒ}|g||j|jƒ<qWdS)N)r\r8r2rr>)rrJr"r?rrrr9s



zHTTPHeaderDict._copy_fromcCst|ƒƒ}|j|ƒ|S)N)rGr9)rÚclonerrrÚcopy"s

zHTTPHeaderDict.copyccsDx>|D]6}|j|jƒ}x"|dd…D]}|d|fVq&WqWdS)z8Iterate over all header lines, including duplicate ones.rNr)rr>)rr"rMr?rrrrY's
zHTTPHeaderDict.iteritemsccs<x6|D].}|j|jƒ}|ddj|dd…ƒfVqWdS)z:Iterate over all headers, merging duplicate ones together.rz, rN)rr>r@)rr"r?rrrrI.s
zHTTPHeaderDict.itermergedcCst|jƒƒS)N)r2rY)rrrrrZ4szHTTPHeaderDict.itemscCs„d}g}xr|jD]h}|j|ƒrV|s0td|ƒ‚n&|d\}}||d|jƒf|d<q|jddƒ\}}|j||jƒfƒqW||ƒS)	z4Read headers from a Python 2 httplib message object.ú ú	z/Header continuation with no previous header: %srú:)r`raéÿÿÿÿrc)r;Ú
startswithrÚstripÚsplitrS)ÚclsÚmessageZobs_fold_continued_leadersr;Úliner"r*rrrÚfrom_httplib7s
zHTTPHeaderDict.from_httplib)N)&rrrr6r r-r$r.rArKrLrÚPY2rrrÚobjectrOr/r1r!rQrVr:r\Ú
getheadersÚgetallmatchingheadersÚigetÚget_allr]r9r_rYrIrZÚclassmethodrjÚ
__classcell__rr)r=rrks< 	
N)Ú
__future__rÚcollections.abcrrÚImportErrorÚcollectionsÚ	threadingrrÚ
exceptionsrÚpackagesrZpackages.sixrrÚ__all__rlr&rrrrrrÚ<module>s L