U eC@s@ddlmZddlZddlmZddlmZmZddlm Z ej rjddlm Z ddl m Z Gdd d e Zd d gZed Zed ZedZejd ejeefejejeefd fZGdddeZdddddZGdd d ejeefejeefZGdddejejeefZ Gdd d ejeefZ!dS)) annotationsN) OrderedDict)Enumauto)RLock)Protocol)Selfc@s*eZdZddddZdddddZd S) HasGettableStringKeystyping.Iterator[str]returncCsdSNselfrrB/opt/hc_python/lib/python3.8/site-packages/urllib3/_collections.pykeysszHasGettableStringKeys.keysstrkeyr cCsdSr rrrrrr __getitem__sz!HasGettableStringKeys.__getitem__N)__name__ __module__ __qualname__rrrrrrr sr RecentlyUsedContainerHTTPHeaderDict_KT_VT_DTc@seZdZeZdS) _SentinelN)rrrr not_passedrrrrr )sr objectValidHTTPHeaderSource | None) potentialr cCst|tr|St|tjr0ttjttf|St|tjrXttjtjttf|St|drxt|drxtd|SdSdS)Nrrr ) isinstancertypingMappingcastrIterableTuplehasattr)r$rrr%ensure_can_construct_http_header_dict-s    r,cseZdZUdZded<ded<ded<ded <d%ddd d fdd ZdddddZddd dddZdd dddZddddZ ddddZ d dd d!Z d"dd#d$Z Z S)&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 ztyping.OrderedDict[_KT, _VT] _containerint_maxsizez#typing.Callable[[_VT], None] | None dispose_funcrlock NNone)maxsizer0r cs*t||_||_t|_t|_dSr )super__init__r/r0rr-rr1)rr4r0 __class__rrr6Ts  zRecentlyUsedContainer.__init__rrrc Cs8|j(|j|}||j|<|W5QRSQRXdSr )r1r-pop)rritemrrrr_s  z!RecentlyUsedContainer.__getitem__)rvaluer c Csd}|jbz||j|f}||j|<Wn<tk rf||j|<t|j|jkrb|jjdd}YnXW5QRX|dk r|jr|\}}||dS)NF)last)r1r-r9KeyErrorlenr/popitemr0)rrr;Z evicted_item_ evicted_valuerrr __setitem__fs z!RecentlyUsedContainer.__setitem__c Cs2|j|j|}W5QRX|jr.||dSr )r1r-r9r0)rrr;rrr __delitem__sz!RecentlyUsedContainer.__delitem__r c Cs(|jt|jW5QRSQRXdSr )r1r>r-rrrr__len__szRecentlyUsedContainer.__len__ztyping.NoReturncCs tddS)Nz7Iteration over this class is unlikely to be threadsafe.)NotImplementedErrorrrrr__iter__szRecentlyUsedContainer.__iter__c CsH|jt|j}|jW5QRX|jrD|D]}||q4dSr )r1listr-valuesclearr0)rrHr;rrrrIs zRecentlyUsedContainer.clearzset[_KT]c Cs,|jt|jW5QRSQRXdSr )r1setr-rrrrrrszRecentlyUsedContainer.keys)r2N)rrr__doc____annotations__r6rrBrCrDrFrIr __classcell__rrr7rrAs    c@sVeZdZUdZded<dddddZdd d d Zd d d dZdddddZdS)HTTPHeaderDictItemViewa HTTPHeaderDict is unusual for a Mapping[str, str] in that it has two modes of address. If we directly try to get an item with a particular name, we will get a string back that is the concatenated version of all the values: >>> d['X-Header-Name'] 'Value1, Value2, Value3' However, if we iterate over an HTTPHeaderDict's items, we will optionally combine these values based on whether combine=True was called when building up the dictionary >>> d = HTTPHeaderDict({"A": "1", "B": "foo"}) >>> d.add("A", "2", combine=True) >>> d.add("B", "bar") >>> list(d.items()) [ ('A', '1, 2'), ('B', 'foo'), ('B', 'bar'), ] This class conforms to the interface required by the MutableMapping ABC while also giving us the nonstandard iteration behavior we want; items with duplicate keys, ordered by time of first insertion. r_headersr3)headersr cCs ||_dSr )rO)rrPrrrr6szHTTPHeaderDictItemView.__init__r.r cCstt|jSr )r>rGrO iteritemsrrrrrDszHTTPHeaderDictItemView.__len__ typing.Iterator[tuple[str, str]]cCs |jSr )rOrQrrrrrFszHTTPHeaderDictItemView.__iter__r"bool)r:r cCsDt|tr@t|dkr@|\}}t|tr@t|tr@|j||SdS)NF)r%tupler>rrO_has_value_for_header)rr:Z passed_keyZ passed_valrrr __contains__s z#HTTPHeaderDictItemView.__contains__N) rrrrKrLr6rDrFrWrrrrrNs rNcseZdZUdZded<dTdddfdd Zddd d d d ZdddddZdd dddZdddddZ dUddddfdd Z dddddZ dddddZ d d!d"d#Z d$d!d%d&Zdd dd'd(Zd)d*dddd d+d,d-Zd.dd d/d0d1Zejdd2dd3d4Zejdd5d6dd7d4Zejfdd8d6dd9d4Zd:d!d;d<ZeZeZeZeZdd!d=d>Zdd dd?d@Zdd!dAdBZdCd!dDdEZdCd!dFdGZ dHd!dIdJZ!ddddKdLdMZ"ddddNdOZ#ddddPdQZ$ddddRdSZ%Z&S)Vrap :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' z%typing.MutableMapping[str, list[str]]r-Nr#r)rPkwargsc sJti|_|dk r8t|tr.||n |||rF||dSr )r5r6r-r%r _copy_fromextend)rrPrXr7rrr6s    zHTTPHeaderDict.__init__r3)rvalr cCs*t|tr|d}||g|j|<dS)Nlatin-1)r%bytesdecoder-lowerrrr[rrrrBs  zHTTPHeaderDict.__setitem__rcCs |j|}d|ddS)N, r-r_joinr`rrrrszHTTPHeaderDict.__getitem__cCs|j|=dSr r-r_rrrrrCszHTTPHeaderDict.__delitem__r"rScCst|tr||jkSdS)NF)r%rr_r-rrrrrW s zHTTPHeaderDict.__contains__)rdefaultr cst||Sr )r5 setdefaultrrrgr7rrrhszHTTPHeaderDict.setdefault)otherr cCsDt|}|dkrdSt||}dd|Ddd|DkS)NFcSsi|]\}}||qSr)r_).0kvrrr sz)HTTPHeaderDict.__eq__..)r,type itermerged)rrjmaybe_constructableZother_as_http_header_dictrrr__eq__s zHTTPHeaderDict.__eq__cCs || Sr )rr)rrjrrr__ne__szHTTPHeaderDict.__ne__r.r cCs t|jSr )r>r-rrrrrD szHTTPHeaderDict.__len__r ccs|jD]}|dVq dS)Nr)r-rH)rvalsrrrrF#szHTTPHeaderDict.__iter__cCs$z ||=Wntk rYnXdSr )r=rrrrdiscard(s zHTTPHeaderDict.discardF)combine)rr[rvr cCsrt|tr|d}|}||g}|j||}||k rnt|dksJt|rd|dd||d<n ||dS)aAdds a (name, value) pair, doesn't overwrite the value if it already exists. If this is called with combine=True, instead of adding a new header value as a distinct item during iteration, this will instead append the value to any existing header value with a comma. If no existing header value exists for the key, then the value will simply be added, ignoring the combine parameter. >>> headers = HTTPHeaderDict(foo='bar') >>> headers.add('Foo', 'baz') >>> headers['foo'] 'bar, baz' >>> list(headers.items()) [('foo', 'bar'), ('foo', 'baz')] >>> headers.add('foo', 'quz', combine=True) >>> list(headers.items()) [('foo', 'bar, baz, quz')] r\rTraN) r%r]r^r_r-rhr>AssertionErrorappend)rrr[rv key_lowernew_valsrtrrradd.s  zHTTPHeaderDict.addValidHTTPHeaderSource)argsrXr cOs,t|dkr tdt|dt|dkr4|dnd}t|trb|D]\}}|||qJnt|tjr|D]\}}|||qvnzt|tj rt tj tj t t f|}|D]\}}|||qn6t |drt |dr|D]}||||q|D]\}}|||qdS) 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__ rbz/extend() takes at most 1 positional arguments (z given)rrrrN)r> TypeErrorr%rrQr|r&r'itemsr)r(r*rr+r)rr~rXrjrr[r;rrrrZQs(      zHTTPHeaderDict.extendz list[str]cCsdSr rrrrrgetlistrszHTTPHeaderDict.getlistrzlist[str] | _DTcCsdSr rrirrrrvsz_Sentinel | _DTcCsNz|j|}Wn*tk r<|tjkr4gYS|YSX|ddSdS)zmReturns a list of all the values for the named field. Returns an empty list if the key doesn't exist.rbN)r-r_r=r r!)rrrgrtrrrrzs  rcCs*dddddddg}|D]}||q|S)z Remove content-specific header fields before changing the request method to GET or HEAD according to RFC 9110, Section 15.4. zContent-EncodingzContent-LanguagezContent-Locationz Content-TypezContent-LengthZDigestz Last-Modified)ru)rZcontent_specific_headersheaderrrr_prepare_for_method_changes  z)HTTPHeaderDict._prepare_for_method_changecCst|jdt|dS)N())rordictrprrrr__repr__szHTTPHeaderDict.__repr__cCs,|D]"}||}|f||j|<qdSr )rr-r_)rrjrr[rrrrYs zHTTPHeaderDict._copy_fromcCst|}|||Sr )rorY)rclonerrrcopys  zHTTPHeaderDict.copyrRccs<|D]2}|j|}|ddD]}|d|fVq"qdS)z8Iterate over all header lines, including duplicate ones.rbNrre)rrrtr[rrrrQszHTTPHeaderDict.iteritemsccs8|D].}|j|}|dd|ddfVqdS)z:Iterate over all headers, merging duplicate ones together.rrarbNrcr`rrrrpszHTTPHeaderDict.itermergedrNcCst|Sr )rNrrrrrszHTTPHeaderDict.items) header_namepotential_valuer cCs&||kr"||j|ddkSdS)NrbFre)rrrrrrrVsz$HTTPHeaderDict._has_value_for_headercCs"t|}|dkrtS|||Sr )r,NotImplementedrZ)rrjrqrrr__ior__s  zHTTPHeaderDict.__ior__cCs*t|}|dkrtS|}|||Sr )r,rrrZrrjrqresultrrr__or__s  zHTTPHeaderDict.__or__cCs.t|}|dkrtSt||}|||Sr )r,rrorZrrrr__ror__s   zHTTPHeaderDict.__ror__)N)rf)'rrrrKrLr6rBrrCrWrhrrrsrDrFrur|rZr&overloadrr r!r getheadersgetallmatchingheadersigetget_allrrYrrQrprrVrrrrMrrr7rrsH !  #!  )" __future__rr& collectionsrenumrr threadingr TYPE_CHECKINGrZtyping_extensionsrr __all__TypeVarrrrUnionr'rr)r*r}r r,GenericMutableMappingrSetrNrrrrrs0         &] 0