zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
U
 ý°dÉ<ã@s4ddlmZddlZddlmZddlmZmZddlm    Z    ej
r^ddl m Z Gdd„de ƒZ d    d
gZe d ¡Ze d ¡Ze d ¡Zejd
ejeefejejeefdfZGdd„deƒZdddœdd„ZGdd    „d    ejeefejeefƒZGdd„dejejeefƒZGdd
„d
ejeefƒZ dS)é)Ú annotationsN)Ú OrderedDict)ÚEnumÚauto)ÚRLock)ÚProtocolc@s*eZdZddœdd„Zdddœdd„Zd    S)
ÚHasGettableStringKeysútyping.Iterator[str]©ÚreturncCsdS©N©©Úselfr r úKd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\urllib3/_collections.pyÚkeysszHasGettableStringKeys.keysÚstr©Úkeyr cCsdSr r ©rrr r rÚ __getitem__sz!HasGettableStringKeys.__getitem__N)Ú__name__Ú
__module__Ú __qualname__rrr r r rr srÚRecentlyUsedContainerÚHTTPHeaderDictÚ_KTÚ_VTÚ_DTc@seZdZeƒZdS)Ú    _SentinelN)rrrrÚ
not_passedr r r rr'srÚobjectúValidHTTPHeaderSource | None)Ú    potentialr cCs€t|tƒr|St|tjƒr0t tjttf|¡St|tjƒrXt tjtjttf|¡St|dƒrxt|dƒrxt d|¡SdSdS)Nrrr)    Ú
isinstancerÚtypingÚMappingÚcastrÚIterableÚTupleÚhasattr)r#r r rÚ%ensure_can_construct_http_header_dict+s
   r+cs¸eZdZUdZded<ded<ded<ded    <d%ddd d œ‡fdd„ Zdddœdd„Zddd dœdd„Zdd dœdd„Zddœdd„Z    ddœdd„Z
d dœd d!„Z d"dœd#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]Ú
_containerÚintÚ_maxsizez#typing.Callable[[_VT], None] | NoneÚ dispose_funcrÚlocké
NÚNone)Úmaxsizer/r cs*tƒ ¡||_||_tƒ|_tƒ|_dSr )ÚsuperÚ__init__r.r/rr,rr0)rr3r/©Ú    __class__r rr5Rs
 
zRecentlyUsedContainer.__init__rrrc
Cs8|j(|j |¡}||j|<|W5QR£SQRXdSr )r0r,Úpop)rrÚitemr r rr]s 
z!RecentlyUsedContainer.__getitem__)rÚvaluer c    Cs–d}|jbz||j |¡f}||j|<Wn<tk
rf||j|<t|jƒ|jkrb|jjdd}YnXW5QRX|dk    r’|jr’|\}}| |¡dS)NF)Úlast)r0r,r8ÚKeyErrorÚlenr.Úpopitemr/)rrr:Z evicted_itemÚ_Ú evicted_valuer r rÚ __setitem__ds
z!RecentlyUsedContainer.__setitem__c    Cs2|j|j |¡}W5QRX|jr.| |¡dSr )r0r,r8r/)rrr:r r rÚ __delitem__}sz!RecentlyUsedContainer.__delitem__r
c
Cs(|jt|jƒW5QR£SQRXdSr )r0r=r,rr r rÚ__len__„szRecentlyUsedContainer.__len__ztyping.NoReturncCs tdƒ‚dS)Nz7Iteration over this class is unlikely to be threadsafe.)ÚNotImplementedErrorrr r rÚ__iter__ˆsÿzRecentlyUsedContainer.__iter__c    CsH|jt|j ¡ƒ}|j ¡W5QRX|jrD|D]}| |¡q4dSr )r0Úlistr,ÚvaluesÚclearr/)rrGr:r r rrHs zRecentlyUsedContainer.clearzset[_KT]c
Cs,|jt|j ¡ƒW5QR£SQRXdSr )r0Úsetr,rrr r rr—szRecentlyUsedContainer.keys)r1N)rrrÚ__doc__Ú__annotations__r5rrArBrCrErHrÚ __classcell__r r r6rr?s
 ý 
c@sVeZdZUdZded<dddœdd„Zdd    œd
d „Zd d    œd d„Zdddœdd„ZdS)Ú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Ú_headersr2)Úheadersr cCs
||_dSr )rN)rrOr r rr5»szHTTPHeaderDictItemView.__init__r-r
cCstt|j ¡ƒƒSr )r=rFrNÚ    iteritemsrr r rrC¾szHTTPHeaderDictItemView.__len__ú typing.Iterator[tuple[str, str]]cCs
|j ¡Sr )rNrPrr r rrEÁszHTTPHeaderDictItemView.__iter__r!Úbool)r9r cCsDt|tƒr@t|ƒdkr@|\}}t|tƒr@t|tƒr@|j ||¡SdS)NéF)r$Útupler=rrNÚ_has_value_for_header)rr9Z
passed_keyZ
passed_valr r rÚ __contains__Äs
z#HTTPHeaderDictItemView.__contains__N)    rrrrJrKr5rCrErVr r r rrMœs
rMcsÄeZdZUdZded<dKdddœ‡fdd    „ Zddd
d œd d „Zdddœdd„Zdd
dœdd„Zdddœdd„Z    dLddddœ‡fdd„ Z
dddœdd„Z dddœdd„Z d d!œd"d#„Z d$d!œd%d&„Zdd
dœd'd(„Zd)d*œdddd
d+œd,d-„Zd.dd
d/œd0d1„Zejdd2dœd3d4„ƒZejdd5d6dœd7d4„ƒZejfdd8d6dœd9d4„ZeZeZeZeZdd!œd:d;„Zdd
dœd<d=„Zdd!œd>d?„Zd@d!œdAdB„Zd@d!œdCdD„ZdEd!œdFdG„Z ddddHœdIdJ„Z!‡Z"S)Mrap
    :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)rOÚkwargsc sJtƒ ¡i|_|dk    r8t|tƒr.| |¡n
| |¡|rF| |¡dSr )r4r5r,r$rÚ
_copy_fromÚextend)rrOrWr6r rr5ðs
 
 
zHTTPHeaderDict.__init__r2)rÚvalr cCs*t|tƒr| d¡}||g|j| ¡<dS)Núlatin-1)r$ÚbytesÚdecoder,Úlower©rrrZr r rrAûs
 
zHTTPHeaderDict.__setitem__rcCs |j| ¡}d |dd…¡S)Nú, é©r,r^Újoinr_r r rrszHTTPHeaderDict.__getitem__cCs|j| ¡=dSr ©r,r^rr r rrBszHTTPHeaderDict.__delitem__r!rRcCst|tƒr| ¡|jkSdS)NF)r$rr^r,rr r rrVs
zHTTPHeaderDict.__contains__Ú)rÚdefaultr cstƒ ||¡Sr )r4Ú
setdefault©rrrfr6r rrg szHTTPHeaderDict.setdefault)Úotherr cCsDt|ƒ}|dkrdSt|ƒ|ƒ}dd„| ¡Dƒdd„| ¡DƒkS)NFcSsi|]\}}| ¡|“qSr )r^)Ú.0ÚkÚvr r rÚ
<dictcomp>sz)HTTPHeaderDict.__eq__.<locals>.<dictcomp>)r+ÚtypeÚ
itermerged)rriZmaybe_constructableZother_as_http_header_dictr r rÚ__eq__s ÿzHTTPHeaderDict.__eq__cCs | |¡ Sr )rp)rrir r rÚ__ne__szHTTPHeaderDict.__ne__r-r
cCs
t|jƒSr )r=r,rr r rrCszHTTPHeaderDict.__len__r    ccs|j ¡D]}|dVq
dS)Nr)r,rG)rÚvalsr r rrE!szHTTPHeaderDict.__iter__cCs$z
||=Wntk
rYnXdSr )r<rr r rÚdiscard&s
zHTTPHeaderDict.discardF)Úcombine)rrZrtr cCsrt|tƒr| d¡}| ¡}||g}|j ||¡}||k    rnt|ƒdksJt‚|rd|dd||d<n
| |¡dS)aùAdds 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[rSéÿÿÿÿr`N)    r$r\r]r^r,rgr=ÚAssertionErrorÚappend)rrrZrtÚ    key_lowerÚnew_valsrrr r rÚadd,s
 
zHTTPHeaderDict.addÚValidHTTPHeaderSource)ÚargsrWr cOs,t|ƒdkr tdt|ƒ›dƒ‚t|ƒdkr4|dnd}t|tƒrb| ¡D]\}}| ||¡qJn¦t|tjƒrŽ| ¡D]\}}| ||¡qvnzt|tj    ƒrÒt 
tj    tj t t f|¡}|D]\}}| ||¡qºn6t |dƒrt |dƒr| ¡D]}| |||¡qò| ¡D]\}}| ||¡qdS)    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__
        raz/extend() takes at most 1 positional arguments (z given)rr rrN)r=Ú    TypeErrorr$rrPrzr%r&Úitemsr(r'r)rr*r)rr|rWrirrZr:r r rrYOs( ÿ
    zHTTPHeaderDict.extendz    list[str]cCsdSr r rr r rÚgetlistpszHTTPHeaderDict.getlistrzlist[str] | _DTcCsdSr r rhr r rrtsz_Sentinel | _DTcCsNz|j| ¡}Wn*tk
r<|tjkr4gYS|YSX|dd…SdS)zmReturns a list of all the values for the named field. Returns an
        empty list if the key doesn't exist.raN)r,r^r<rr )rrrfrrr r rrxs
 
cCst|ƒj›dt| ¡ƒ›dS)Nú(ú))rnrÚdictrorr r rÚ__repr__’szHTTPHeaderDict.__repr__cCs,|D]"}| |¡}|f|•|j| ¡<qdSr )rr,r^)rrirrZr r rrX•s
zHTTPHeaderDict._copy_fromcCst|ƒƒ}| |¡|Sr )rnrX)rÚcloner r rÚcopyšs
 
zHTTPHeaderDict.copyrQccs<|D]2}|j| ¡}|dd…D]}|d|fVq"qdS)z8Iterate over all header lines, including duplicate ones.raNrrd)rrrrrZr r rrPŸszHTTPHeaderDict.iteritemsccs8|D].}|j| ¡}|dd |dd…¡fVqdS)z:Iterate over all headers, merging duplicate ones together.rr`raNrbr_r r rro¦szHTTPHeaderDict.itermergedrMcCst|ƒSr )rMrr r rr~¬szHTTPHeaderDict.items)Ú header_nameÚpotential_valuer cCs&||kr"||j| ¡dd…kSdS)NraFrd)rr†r‡r r rrU¯sz$HTTPHeaderDict._has_value_for_header)N)re)#rrrrJrKr5rArrBrVrgrprqrCrErsrzrYr%Úoverloadrrr Ú
getheadersÚgetallmatchingheadersÚigetÚget_allrƒrXr…rPror~rUrLr r r6rrÌs@
!  #!ÿ)!Ú
__future__rr%Ú collectionsrÚenumrrÚ    threadingrÚ TYPE_CHECKINGZtyping_extensionsrrÚ__all__ÚTypeVarrrrÚUnionr&rr(r)r{rr+ÚGenericÚMutableMappingrÚSetrMrr r r rÚ<module>s.    
 
 
 ýÿ&] 0