CYhCjddlmZddlZddlmZddlmZmZddlm Z ejrddl m Z m Z Gdde Zd d gZej d Zej d Zej d Zej(d ej*eefej.ej0eefdfZGddeZ ddZGdd ej8eefej:eefZGddej>ej0eefZ Gdd ej:eefZ!y)) annotationsN) OrderedDict)Enumauto)RLock)ProtocolSelfceZdZddZddZy)HasGettableStringKeyscyNselfs 6/usr/lib/python3/dist-packages/urllib3/_collections.pykeyszHasGettableStringKeys.keys cyr rrkeys r __getitem__z!HasGettableStringKeys.__getitem__rrNreturnztyping.Iterator[str]rstrrr)__name__ __module__ __qualname__rrrrrr r s   rr RecentlyUsedContainerHTTPHeaderDict_KT_VT_DTceZdZeZy) _SentinelN)rrrr not_passedrrrr&r&'s Jrr&ct|tr|St|tjr1tjtjt t f|St|tj rBtjtj tjt t f|St|dr"t|drtjd|Sy)Nrrr ) isinstancer!typingMappingcastrIterableTuplehasattr) potentials r%ensure_can_construct_http_header_dictr1+s)^, Iv~~ .{{6>>#s(3Y?? Iv /{{6??6<<S+ABINN F # =(I{{2I>>rceZdZUdZded<ded<ded<ded < d dfd Zdd Zdd Zdd ZddZ ddZ ddZ ddZ xZ S)r a 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_maxsize#typing.Callable[[_VT], None] | None dispose_funcrlockczt|||_||_t |_t |_yr )super__init__r5r7rr3rr8)rmaxsizer7 __class__s rr;zRecentlyUsedContainer.__init__Rs1  (%-G rc|j5|jj|}||j|<|cdddS#1swYyxYwr )r8r3pop)rritems rrz!RecentlyUsedContainer.__getitem__]sC YY ??&&s+D#'DOOC    s ,AA cd}|j5 ||jj|f}||j|<ddd|$|jr|\}}|j|yyy#t$rP||j|<t |j|j kDr|jj d}YwxYw#1swYxYw)NF)last)r8r3r?KeyErrorlenr5popitemr7)rrvalue evicted_item_ evicted_values r __setitem__z!RecentlyUsedContainer.__setitem__ds YY G G #DOO$7$7$<< ',$ G&  #(9(9+ A}   m ,): # G(-$t'$--7$(??#:#:#:#FL G G Gs)C,A,,ACCCCCc|j5|jj|}ddd|jr|jyy#1swY(xYwr )r8r3r?r7)rrrFs r __delitem__z!RecentlyUsedContainer.__delitem__}sP YY -OO'',E -      e $  - -s AAcp|j5t|jcdddS#1swYyxYwr )r8rDr3rs r__len__zRecentlyUsedContainer.__len__s* YY (t' ( ( (s,5ctd)Nz7Iteration over this class is unlikely to be threadsafe.)NotImplementedErrorrs r__iter__zRecentlyUsedContainer.__iter__s! E  rc |j5t|jj}|jj ddd|j rD]}|j |yy#1swY/xYwr )r8listr3valuesclearr7)rrTrFs rrUzRecentlyUsedContainer.clearsr YY $$//0023F OO ! ! # $    )!!%( )   $ $s >A99Bc|j5t|jjcdddS#1swYyxYwr )r8setr3rrs rrzRecentlyUsedContainer.keyss3 YY /t++-. / / /s #:A) N)r<r4r7r6rNone)rr"rr#)rr"rFr#rrY)rr"rrYrr4)rztyping.NoReturn)rrY)rzset[_KT])rrr__doc____annotations__r;rrJrLrNrQrUr __classcell__r=s@rr r ?sl -,M55 K<@  :   -2%( )/rc<eZdZUdZded<d dZd dZd dZd dZy) 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!_headersc||_yr )ra)rheaderss rr;zHTTPHeaderDictItemView.__init__s  rcZtt|jjSr )rDrSra iteritemsrs rrNzHTTPHeaderDictItemView.__len__s4 //1233rc6|jjSr )rarers rrQzHTTPHeaderDictItemView.__iter__s}}&&((rct|trOt|dk(rA|\}}t|tr,t|tr|jj ||Sy)NF)r)tuplerDrra_has_value_for_header)rr@ passed_key passed_vals r __contains__z#HTTPHeaderDictItemView.__contains__sM dE "s4yA~%) "J *c*z*c/J}}:::zRRrN)rcr!rrYrZrz typing.Iterator[tuple[str, str]])r@objectrbool) rrrr[r\r;rNrQrmrrrr`r`s#8 4)rr`c|eZdZUdZded<d!d"fd Zd#dZd$dZd%dZd&dZ d'd(fd Z d)d Z d)d Z d*d Z d+d Zd%dZddd,dZd-dZej&d.dZej&d/dZej,f d0dZd1dZeZeZeZeZd2dZd3dZd4dZd5dZd5dZ d6dZ!d7dZ"d8dZ#d8dZ$d8d Z%xZ&S)9r!ap :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]]r3c t|i|_|3t|tr|j |n|j ||r|j |yyr )r:r;r3r)r! _copy_fromextend)rrckwargsr=s rr;zHTTPHeaderDict.__init__sQ   '>2( G$  KK  rct|tr|jd}||g|j|j <y)Nlatin-1)r)bytesdecoder3lowerrrvals rrJzHTTPHeaderDict.__setitem__s2 c5 !**Y'C(+Sz $rcd|j|j}dj|ddS)N, r3rzjoinr{s rrzHTTPHeaderDict.__getitem__s+oociik*yyQR!!rc:|j|j=yr r3rzrs rrLzHTTPHeaderDict.__delitem__s OOCIIK (rc\t|tr|j|jvSyNF)r)rrzr3rs rrmzHTTPHeaderDict.__contains__s$ c3 99;$//1 1rc$t|||Sr )r: setdefault)rrdefaultr=s rrzHTTPHeaderDict.setdefault sw!#w//rc"t|}|yt||}|jDcic]\}}|j|c}}|jDcic]\}}|j|c}}k(Scc}}wcc}}wr)r1type itermergedrz)rothermaybe_constructableother_as_http_header_dictkvs r__eq__zHTTPHeaderDict.__eq__sCEJ  &(2T 3F(G %)-):;A 1 ;%>%I%I%K@ !QAGGIqL@   ;@ s B$B c&|j| Sr )r)rrs r__ne__zHTTPHeaderDict.__ne__s;;u%%%rc,t|jSr )rDr3rs rrNzHTTPHeaderDict.__len__s4??##rc#XK|jjD] }|d yw)Nr)r3rT)rvalss rrQzHTTPHeaderDict.__iter__!s+OO**, Dq'M s(*c* ||=y#t$rYywxYwr )rCrs rdiscardzHTTPHeaderDict.discard&s  S    s  F)combinect|tr|jd}|j}||g}|jj ||}||ur3t |dk\sJ|r|ddz|z|d<y|j|yy)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')] rwrhr~N)r)rxryrzr3rrDappend)rrr|r key_lowernew_valsrs raddzHTTPHeaderDict.add,s( c5 !**Y'CIIK :)))X> 4 t9> !>8d?S0R C  rcFt|dkDrtdt|dt|dk\r|dnd}t|tr,|j D]\}}|j ||nt|t jr+|jD]\}}|j ||nt|t jr_t jt jt jttf|}|D]\}}|j ||nBt|dr6t|dr*|jD]}|j ||||jD]\}}|j ||y) 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__ rz/extend() takes at most 1 positional arguments (z given)rrrrN)rD TypeErrorr)r!rerr*r+itemsr-r,r.rr/r)rargsrurrr|rFs rrtzHTTPHeaderDict.extendOsd t9q=A#d)GT t9>Qr e^ ,!OO- #Sc" # v~~ .!KKM #Sc" # v /KK S#X0F GOE# % Ue$ % UF #}(E zz| *eCj) *!,,. !JC HHS%  !rcyr rrs rgetlistzHTTPHeaderDict.getlistp rcyr r)rrrs rrzHTTPHeaderDict.getlisttrrc |j|j}|ddS#t$r|tjurgcYS|cYSwxYw)zmReturns a list of all the values for the named field. Returns an empty list if the key doesn't exist.rN)r3rzrCr&r')rrrrs rrzHTTPHeaderDict.getlistxsQ ??399;/D8O )... N  s$AAAc>gd}|D]}|j||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-LengthDigestz Last-Modified)r)rcontent_specific_headersheaders r_prepare_for_method_changez)HTTPHeaderDict._prepare_for_method_changes, $  / !F LL  ! rcft|jdt|jdS)N())rrdictrrs r__repr__zHTTPHeaderDict.__repr__s-t*%%&aT__->(?'@BBrct|D]3}|j|}|g||j|j<5yr )rr3rz)rrrr|s rrszHTTPHeaderDict._copy_froms9 7C--$C,/;#;DOOCIIK ( 7rcHt|}|j||Sr )rrs)rclones rcopyzHTTPHeaderDict.copys"T   rc#zK|D]2}|j|j}|ddD] }|d|f 4yw)z8Iterate over all header lines, including duplicate ones.rNrr)rrrr|s rrezHTTPHeaderDict.iteritemssL #C??399;/DABx #1gsl" # #s9;c#K|D]:}|j|j}|ddj|ddf<yw)z:Iterate over all headers, merging duplicate ones together.rr~rNrr{s rrzHTTPHeaderDict.itermergedsG -C//#))+.Ca&$))CG,, , -sAAct|Sr )r`rs rrzHTTPHeaderDict.itemss %d++rcP||vr"||j|jddvSy)NrFr)r header_namepotential_values rrjz$HTTPHeaderDict._has_value_for_headers1 $ "dook6G6G6I&J12&NN NrcNt|}|tS|j||Sr )r1NotImplementedrt)rrrs r__ior__zHTTPHeaderDict.__ior__s.DEJ  &! ! '( rcnt|}|tS|j}|j||Sr )r1rrrtrrrresults r__or__zHTTPHeaderDict.__or__s9DEJ  &! ! )* rcpt|}|tSt||}|j||Sr )r1rrrtrs r__ror__zHTTPHeaderDict.__ror__s>DEJ  &! !d/0 d rr )rcValidHTTPHeaderSource | Nonerur)rrr|rrrYr)rrrrY)rrorrp))rrrrrr)rrorrprZr)rrr|rrrprrY)rValidHTTPHeaderSourcerurrrY)rrrz list[str])rrrr$rlist[str] | _DT)rrrz_Sentinel | _DTrr)rr )rr)rr!rrY)rr!rn)rr`)rrrrrrp)rrorr!)'rrrr[r\r;rJrrLrmrrrrNrQrrrtr*overloadrr&r'r getheadersgetallmatchingheadersigetget_allrrsrrerrrjrrrr]r^s@rr!r!sB65  2 ") 0  &$  :?!!F!B __   __  4=3G3G!0 $&J# DGC7  #- , r)r0rorr)" __future__rr* collectionsrenumrr threadingr TYPE_CHECKINGtyping_extensionsrr r __all__TypeVarr"r#r$Unionr+rr-r.rr&r1GenericMutableMappingr Setr`r!rrrrs?" # 1 #$4 5fnnUfnnUfnnU  NN38 OOFLLc*+!(Z/FNN384f6K6KCQTH6UZ/z-VZZ S#X(>?-`UV**384Ur