3 {^(*@sddlmZyddlmZmZWn$ek rDddlmZmZYnXyddlmZWn"ek rxGdddZYnXddlm Z ddl m Z dd l m Z mZmZd d gZeZGd d d eZGd d d eZdS))absolute_import)MappingMutableMapping)RLockc@seZdZddZddZdS)rcCsdS)N)selfrrj/home/sumanth/workspace/ghrepos/quickstart-citrix-adc-appfw/functions/source/appfw/urllib3/_collections.py __enter__ szRLock.__enter__cCsdS)Nr)rexc_type exc_value tracebackrrr__exit__szRLock.__exit__N)__name__ __module__ __qualname__r r rrrrr sr) OrderedDict) InvalidHeader)iterkeys itervaluesPY3RecentlyUsedContainerHTTPHeaderDictc@sVeZdZdZeZdddZddZdd Zd d Z d d Z ddZ ddZ ddZ 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 _containerrlock)rmaxsizerrrr__init__.s zRecentlyUsedContainer.__init__c Cs,|j|jj|}||j|<|SQRXdS)N)rrpop)rkeyitemrrr __getitem__5s  z!RecentlyUsedContainer.__getitem__c Cslt}|j@|jj|t}||j|<t|j|jkrF|jjdd\}}WdQRX|jrh|tk rh|j|dS)NF)last)_Nullrrgetlenrpopitemr)rr"valueZ evicted_valueZ_keyrrr __setitem__<s z!RecentlyUsedContainer.__setitem__c Cs2|j|jj|}WdQRX|jr.|j|dS)N)rrr!r)rr"r*rrr __delitem__Ksz!RecentlyUsedContainer.__delitem__c Cs|j t|jSQRXdS)N)rr(r)rrrr__len__RszRecentlyUsedContainer.__len__cCs tddS)Nz7Iteration over this class is unlikely to be threadsafe.)NotImplementedError)rrrr__iter__VszRecentlyUsedContainer.__iter__c CsL|jtt|j}|jjWdQRX|jrHx|D]}|j|q6WdS)N)rlistrrclearr)rvaluesr*rrrr1[s  zRecentlyUsedContainer.clearc Cs |jtt|jSQRXdS)N)rr0rr)rrrrkeyseszRecentlyUsedContainer.keys)rN)rrr__doc__rrr r$r+r,r-r/r1r3rrrrrs   cseZdZdZd-fdd ZddZddZd d Zd d Zd dZ ddZ e sZe j Z e jZeZddZddZefddZddZddZddZefddZeZeZeZeZdd Zd!d"Zd#d$Zd%d&Zd'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' Nc sPtt|jt|_|dk r>t|tr4|j|n |j||rL|j|dS)N)superrr rr isinstance _copy_fromextend)rheaderskwargs) __class__rrr s   zHTTPHeaderDict.__init__cCs ||g|j|j<|j|jS)N)rlower)rr"valrrrr+szHTTPHeaderDict.__setitem__cCs |j|j}dj|ddS)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|jDtdd|jDkS)Nr3Fcss|]\}}|j|fVqdS)N)r<).0kvrrr sz(HTTPHeaderDict.__eq__..css|]\}}|j|fVqdS)N)r<)r@rArBrrrrCs)r6rhasattrtypedict itermerged)rotherrrr__eq__s  zHTTPHeaderDict.__eq__cCs |j| S)N)rI)rrHrrr__ne__szHTTPHeaderDict.__ne__cCs t|jS)N)r(r)rrrrr-szHTTPHeaderDict.__len__ccs"x|jjD]}|dVq WdS)Nr)rr2)rvalsrrrr/szHTTPHeaderDict.__iter__c Cs<y ||}Wn tk r,||jkr(|SX||=|SdS)zD.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.popc Cs$y ||=Wntk rYnXdS)N)rL)rr"rrrdiscards zHTTPHeaderDict.discardcCs4|j}||g}|jj||}||k r0|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' N)r<r setdefaultappend)rr"r=Z key_lowerZnew_valsrKrrradds 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__ rz9extend() takes at most 1 positional arguments ({0} given)rr3N) r( TypeErrorformatr6r iteritemsrRrrDr3items)rargsr:rHr"r=r*rrrr8s$      zHTTPHeaderDict.extendc CsFy|j|j}Wn"tk r4||jkr0gS|SX|ddSdS)zmReturns a list of all the values for the named field. Returns an empty list if the key doesn't exist.rN)rr<rLrM)rr"rNrKrrrgetlists zHTTPHeaderDict.getlistcCsdt|jt|jfS)Nz%s(%s))rErrFrG)rrrr__repr__szHTTPHeaderDict.__repr__cCsBx<|D]4}|j|}t|tr&t|}|g||j|j<qWdS)N)rXr6r0rr<)rrHr"r=rrrr7s    zHTTPHeaderDict._copy_fromcCst|}|j||S)N)rEr7)rclonerrrcopy!s  zHTTPHeaderDict.copyccsDx>|D]6}|j|j}x"|ddD]}|d|fVq&WqWdS)z8Iterate over all header lines, including duplicate ones.rNr)rr<)rr"rKr=rrrrU&s zHTTPHeaderDict.iteritemsccs<x6|D].}|j|j}|ddj|ddfVqWdS)z:Iterate over all headers, merging duplicate ones together.rz, rN)rr<r>)rr"r=rrrrG-s zHTTPHeaderDict.itermergedcCs t|jS)N)r0rU)rrrrrV3szHTTPHeaderDict.itemscCsd}g}xr|jD]h}|j|rV|s0td|n&|d\}}||d|jf|d<q|jdd\}}|j||jfqW||S) z4Read headers from a Python 2 httplib message object.  z/Header continuation with no previous header: %sr:)r\r]r_)r9 startswithrstripsplitrQ)clsmessageZobs_fold_continued_leadersr9liner"r*rrr from_httplib6s    zHTTPHeaderDict.from_httplib)N)%rrrr4r r+r$r,r?rIrJrrrrobjectrMr-r/r!rOrRr8rX getheadersgetallmatchingheadersZigetget_allrYr7r[rUrGrV classmethodrf __classcell__rr)r;rrjs<     N) __future__rcollections.abcrr ImportError collections threadingrr exceptionsrZ packages.sixrrr__all__rgr&rrrrrrs   L