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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
U
Þ=®dÂIã@sÊddlmZddlZddlZddlZddlmZddlm    Z    ddl
m Z ddl m Z dd    l mZGd
d „d ƒZd d dœdd„Zdd dœdd„Ze d¡Zdd dœdd„ZGdd„de eƒZddlmZdS)é)Ú annotationsNé)Ú_missing)ÚBadRequestKeyErroré)ÚImmutableHeadersMixin)Úiter_multi_items)Ú    MultiDictc@s eZdZdZdCdd„ZdDdd„Zdd    „ZdZdEd
d „ZdFd d „Z    dd„Z
dGdd„Z dHdd„Z dd„Z dd„ZdIdd„Zdd„Zdefdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„Zd3d4„Zd5d6„Zd7d8„Zd9d:„Z d;d<„Z!d=d>„Z"d?d@„Z#dAdB„Z$dS)JÚHeadersaCAn object that stores some headers. It has a dict-like interface,
    but is ordered, can store the same key multiple times, and iterating
    yields ``(key, value)`` pairs instead of only keys.
 
    This data structure is useful if you want a nicer way to handle WSGI
    headers which are stored as tuples in a list.
 
    From Werkzeug 0.3 onwards, the :exc:`KeyError` raised by this class is
    also a subclass of the :class:`~exceptions.BadRequest` HTTP exception
    and will render a page for a ``400 BAD REQUEST`` if caught in a
    catch-all for HTTP exceptions.
 
    Headers is mostly compatible with the Python :class:`wsgiref.headers.Headers`
    class, with the exception of `__getitem__`.  :mod:`wsgiref` will return
    `None` for ``headers['missing']``, whereas :class:`Headers` will raise
    a :class:`KeyError`.
 
    To create a new ``Headers`` object, pass it a list, dict, or
    other ``Headers`` object with default values. These values are
    validated the same way values added later are.
 
    :param defaults: The list of default values for the :class:`Headers`.
 
    .. versionchanged:: 2.1.0
        Default values are validated the same as values added later.
 
    .. versionchanged:: 0.9
       This data structure now stores unicode values similar to how the
       multi dicts do it.  The main difference is that bytes can be set as
       well which will automatically be latin1 decoded.
 
    .. versionchanged:: 0.9
       The :meth:`linked` function was removed without replacement as it
       was an API that does not support the changes to the encoding model.
    NcCsg|_|dk    r| |¡dS©N)Ú_listÚextend)ÚselfÚdefaults©rúVd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\werkzeug/datastructures/headers.pyÚ__init__3szHeaders.__init__FcCs†|s2t|tƒr|j|St|tƒr2| |j|¡St|tƒsDt|ƒ‚| ¡}|jD]\}}| ¡|krR|SqR|rztƒ‚t|ƒ‚dSr )    Ú
isinstanceÚintr ÚsliceÚ    __class__ÚstrrÚlowerÚKeyError)rÚkeyÚ    _get_modeÚikeyÚkÚvrrrÚ __getitem__8s
 
 
 
 
zHeaders.__getitem__cCs4dd„}|j|jko2tt||jƒƒtt||jƒƒkS)NcSs|d ¡f|dd…S)Nrr©r)ÚitemrrrÚloweredLszHeaders.__eq__.<locals>.lowered)rÚsetÚmapr )rÚotherr"rrrÚ__eq__Ks 
ÿþzHeaders.__eq__cCs†|dk    rtjdtddz|j|dd}Wntk
rB|YSX|rR| d¡}|dkr^|Sz
||ƒWStk
r€|YSXdS)a=Return the default value if the requested data doesn't exist.
        If `type` is provided and is a callable it should convert the value,
        return it or raise a :exc:`ValueError` if that is not possible.  In
        this case the function will return the default as if the value was not
        found:
 
        >>> d = Headers([('Content-Length', '42')])
        >>> d.get('Content-Length', type=int)
        42
 
        :param key: The key to be looked up.
        :param default: The default value to be returned if the key can't
                        be looked up.  If not further specified `None` is
                        returned.
        :param type: A callable that is used to cast the value in the
                     :class:`Headers`.  If a :exc:`ValueError` is raised
                     by this callable the default value is returned.
 
        .. versionchanged:: 2.3
            The ``as_bytes`` parameter is deprecated and will be removed
            in Werkzeug 3.0.
 
        .. versionchanged:: 0.9
            The ``as_bytes`` parameter was added.
        NúKThe 'as_bytes' parameter is deprecated and will be removed in Werkzeug 3.0.r©Ú
stacklevelT©rÚlatin1)ÚwarningsÚwarnÚDeprecationWarningrrÚencodeÚ
ValueError)rrÚdefaultÚtypeÚas_bytesÚrvrrrÚgetUs$ü
 
 
z Headers.getc    Csˆ|dk    rtjdtdd| ¡}g}|D]Z\}}| ¡|kr(|rJ| d¡}|dk    rxz ||ƒ}Wntk
rvYq(YnX| |¡q(|S)aFReturn the list of items for a given key. If that key is not in the
        :class:`Headers`, the return value will be an empty list.  Just like
        :meth:`get`, :meth:`getlist` accepts a `type` parameter.  All items will
        be converted with the callable defined there.
 
        :param key: The key to be looked up.
        :param type: A callable that is used to cast the value in the
                     :class:`Headers`.  If a :exc:`ValueError` is raised
                     by this callable the value will be removed from the list.
        :return: a :class:`list` of all the values for the key.
 
        .. versionchanged:: 2.3
            The ``as_bytes`` parameter is deprecated and will be removed
            in Werkzeug 3.0.
 
        .. versionchanged:: 0.9
            The ``as_bytes`` parameter was added.
        Nr'rr(r+)r,r-r.rr/r0Úappend)rrr2r3rÚresultrrrrrÚgetlist„s&ü  
 
 zHeaders.getlistcCs
| |¡S)z±Return a list of all the values for the named field.
 
        This method is compatible with the :mod:`wsgiref`
        :meth:`~wsgiref.headers.Headers.get_all` method.
        )r8)rÚnamerrrÚget_all­szHeaders.get_allccs(|D]\}}|r| ¡}||fVqdSr r )rrrÚvaluerrrÚitemsµs z Headers.itemsccs| |¡D]\}}|Vq
dSr ©r<)rrrÚ_rrrÚkeys»sz Headers.keysccs| ¡D]\}}|VqdSr r=)rr>r;rrrÚvalues¿szHeaders.valuescOsft|ƒdkrtdt|ƒ›ƒ‚|rDt|dƒD]\}}| ||¡q.t|ƒD]\}}| ||¡qLdS)aÞExtend headers in this object with items from another object
        containing header items as well as keyword arguments.
 
        To replace existing keys instead of extending, use
        :meth:`update` instead.
 
        If provided, the first argument can be another :class:`Headers`
        object, a :class:`MultiDict`, :class:`dict`, or iterable of
        pairs.
 
        .. versionchanged:: 1.0
            Support :class:`MultiDict`. Allow passing ``kwargs``.
        rú)update expected at most 1 arguments, got rN)ÚlenÚ    TypeErrorrÚadd)rÚargsÚkwargsrr;rrrr Ãs zHeaders.extendTcCsf|rt|ttfƒr|j|=dS| ¡}g}|jD]"\}}| ¡|kr0| ||f¡q0||jdd…<dSr )rrrr rr6)rrÚ_index_operationÚnewrrrrrÚ __delitem__Ûs zHeaders.__delitem__cCs|j|ddS)zBRemove a key.
 
        :param key: The key to be removed.
        F)rG)rI©rrrrrÚremoveæszHeaders.removecCsj|dkr|j ¡St|tƒr(|j |¡Sz||}| |¡Wn&tk
rd|tk    r^|YS‚YnX|S)aQRemoves and returns a key or index.
 
        :param key: The key to be popped.  If this is an integer the item at
                    that position is removed, if it's a string the value for
                    that key is.  If the key is omitted or `None` the last
                    item is removed.
        :return: an item.
        N)r ÚpoprrrKrr)rrr1r4rrrrLís    
 
 z Headers.popcCs| ¡S)z7Removes a key or index and returns a (key, value) item.)rL©rrrrÚpopitemszHeaders.popitemcCs.z|j|ddWntk
r(YdSXdS)zCheck if a key is present.Tr*F)rrrJrrrÚ __contains__s
zHeaders.__contains__cCs
t|jƒS)zYield ``(key, value)`` tuples.)Úiterr rMrrrÚ__iter__szHeaders.__iter__cCs
t|jƒSr )rBr rMrrrÚ__len__szHeaders.__len__cKs2|rt||ƒ}t|ƒ}t|ƒ}|j ||f¡dS)aAdd a new header tuple to the list.
 
        Keyword arguments can specify additional parameters for the header
        value, with underscores converted to dashes::
 
        >>> d = Headers()
        >>> d.add('Content-Type', 'text/plain')
        >>> d.add('Content-Disposition', 'attachment', filename='foo.png')
 
        The keyword argument dumping uses :func:`dump_options_header`
        behind the scenes.
 
        .. versionadded:: 0.4.1
            keyword arguments were added for :mod:`wsgiref` compatibility.
        N)Ú_options_header_vkwÚ_str_header_keyÚ_str_header_valuer r6)rÚ_keyÚ_valueÚkwrrrrDs
 
z Headers.addcKs|j||f|ŽdS)z´Add a new header tuple to the list.
 
        An alias for :meth:`add` for compatibility with the :mod:`wsgiref`
        :meth:`~wsgiref.headers.Headers.add_header` method.
        N)rD)rrVrWZ_kwrrrÚ
add_header,szHeaders.add_headercCs|jdd…=dS)zClears all headers.N)r rMrrrÚclear4sz Headers.clearc s¶|rt||ƒ}t|ƒ}t|ƒ}|js8|j ||f¡dSt|jƒ}| ¡‰t|ƒD]*\}\}}| ¡ˆkrR||f|j|<q’qR|j ||f¡dS‡fdd„|Dƒ|j|dd…<dS)a0Remove all header tuples for `key` and add a new one.  The newly
        added key either appears at the end of the list if there was no
        entry or replaces the first one.
 
        Keyword arguments can specify additional parameters for the header
        value, with underscores converted to dashes.  See :meth:`add` for
        more information.
 
        .. versionchanged:: 0.6.1
           :meth:`set` now accepts the same arguments as :meth:`add`.
 
        :param key: The key to be inserted.
        :param value: The value to be inserted.
        Ncs g|]}|d ¡ˆkr|‘qS)rr )Ú.0Út©rrrÚ
<listcomp>XszHeaders.set.<locals>.<listcomp>r)rSrTrUr r6rPrÚ    enumerate)rrVrWrXÚlistiterÚidxZold_keyZ
_old_valuerr]rr#8s 
 
 z Headers.setcCsB|r4t|ƒ}| |t|ƒ¡|D]}| ||¡q n
| |¡dS)zÎRemove any existing values for a header and add new ones.
 
        :param key: The header key to set.
        :param values: An iterable of values to set for the key.
 
        .. versionadded:: 1.0
        N)rPr#ÚnextrDrK)rrr@Z values_iterr;rrrÚsetlistZs zHeaders.setlistcCs ||kr||S| ||¡|S)a*Return the first value for the key if it is in the headers,
        otherwise set the header to the value given by ``default`` and
        return that.
 
        :param key: The header key to get.
        :param default: The value to set for the key if it is not in the
            headers.
        )r#©rrr1rrrÚ
setdefaultks     zHeaders.setdefaultcCs||kr| ||¡| |¡S)aÔReturn the list of values for the key if it is in the
        headers, otherwise set the header to the list of values given
        by ``default`` and return that.
 
        Unlike :meth:`MultiDict.setlistdefault`, modifying the returned
        list will not affect the headers.
 
        :param key: The header key to get.
        :param default: An iterable of values to set for the key if it
            is not in the headers.
 
        .. versionadded:: 1.0
        )rcr8rdrrrÚsetlistdefaultzs zHeaders.setlistdefaultcCsbt|ttfƒrRt|tƒr|g}dd„|Dƒ}t|tƒrF|d|j|<q^||j|<n | ||¡dS)z=Like :meth:`set` but also supports index/slice based setting.cSs g|]\}}t|ƒt|ƒf‘qSr)rTrU©r[rrrrrr^’sz'Headers.__setitem__.<locals>.<listcomp>rN)rrrr r#©rrr;rrrÚ __setitem__s
 
 zHeaders.__setitem__cOsøt|ƒdkrtdt|ƒ›ƒ‚|rº|d}t|ttfƒrZ| ¡D]}| || |¡¡q@n`t|tƒr |     ¡D]0\}}t|t
t fƒr| ||¡ql|  ||¡qln|D]\}}|  ||¡q¤|     ¡D]0\}}t|t
t fƒræ| ||¡qÂ|  ||¡qÂdS)aƒReplace headers in this object with items from another
        headers object and keyword arguments.
 
        To extend existing keys instead of replacing, use :meth:`extend`
        instead.
 
        If provided, the first argument can be another :class:`Headers`
        object, a :class:`MultiDict`, :class:`dict`, or iterable of
        pairs.
 
        .. versionadded:: 1.0
        rrArN) rBrCrr
r    r?rcr8Údictr<ÚlistÚtupler#)rrErFÚmappingrr;rrrÚupdatešs$  
 zHeaders.updatecCst|ƒS)zRConvert the headers into a list suitable for WSGI.
 
        :return: list
        )rkrMrrrÚ to_wsgi_listÀszHeaders.to_wsgi_listcCs | |j¡Sr )rr rMrrrÚcopyÇsz Headers.copycCs| ¡Sr )rprMrrrÚ__copy__ÊszHeaders.__copy__cCs>g}| ¡D]\}}| |›d|›¡q | d¡d |¡S)z9Returns formatted headers suitable for HTTP transmission.z: z
)ror6Újoin)rÚstrsrr;rrrÚ__str__Ís
 
zHeaders.__str__cCst|ƒj›dt|ƒ›dS)Nú(ú))r2Ú__name__rkrMrrrÚ__repr__ÕszHeaders.__repr__)N)F)NNN)NN)F)F)T)%rwÚ
__module__Ú __qualname__Ú__doc__rrr&Ú__hash__r5r8r:r<r?r@r rIrKrrLrNrOrQrRrDrYrZr#rcrerfrirnrorprqrtrxrrrrr
sB$
 
 
/
)
 
 
" &r
rzdict[str, t.Any]©r;rXcCst |dd„| ¡Dƒ¡S)NcSsi|]\}}| dd¡|“qS)r>ú-)ÚreplacergrrrÚ
<dictcomp>Ûs
z'_options_header_vkw.<locals>.<dictcomp>)ÚhttpZdump_options_headerr<r}rrrrSÙsÿrSzt.Any)rÚreturncCs<t|tƒs8tjdtddt|tƒr0| d¡}nt|ƒ}|S)NziHeader keys must be strings. Passing other types is deprecated and will not be supported in Werkzeug 3.0.rr(úlatin-1)rrr,r-r.ÚbytesÚdecode)rrrrrTßs
ü
 rTz[\r\n])r;r‚cCsPt|tƒr$tjdtdd| d¡}t|tƒs6t|ƒ}t |¡dk    rLt    dƒ‚|S)NzXPassing bytes as a header value is deprecated and will not be supported in Werkzeug 3.0.rr(rƒz2Header values must not contain newline characters.)
rr„r,r-r.r…rÚ _newline_reÚsearchr0)r;rrrrUós
ü
 
rUc@sFeZdZdZdd„Zdd„ZdZddd    „Zd
d „Zd d „Z    dd„Z
dS)ÚEnvironHeadersa–Read only version of the headers from a WSGI environment.  This
    provides the same interface as `Headers` and is constructed from
    a WSGI environment.
    From Werkzeug 0.3 onwards, the `KeyError` raised by this class is also a
    subclass of the :exc:`~exceptions.BadRequest` HTTP exception and will
    render a page for a ``400 BAD REQUEST`` if caught in a catch-all for
    HTTP exceptions.
    cCs
||_dSr ©Úenviron)rrŠrrrrszEnvironHeaders.__init__cCs |j|jkSr r‰)rr%rrrr&szEnvironHeaders.__eq__NFcCsDt|tƒst|ƒ‚| ¡ dd¡}|dkr4|j|S|jd|›S)Nr~r>>Ú CONTENT_TYPEÚCONTENT_LENGTHÚHTTP_)rrrÚupperrrŠ)rrrrrrrs 
 
zEnvironHeaders.__getitem__cCsttt|ƒƒƒSr )rBrkrPrMrrrrR"szEnvironHeaders.__len__ccsl|j ¡D]\\}}| d¡rD|dkrD|dd… dd¡ ¡|fVq
|dkr
|r
| dd¡ ¡|fVq
dS)Nr>ÚHTTP_CONTENT_TYPEÚHTTP_CONTENT_LENGTHér>r~>r‹rŒ)rŠr<Ú
startswithrÚtitlerhrrrrQ's
  zEnvironHeaders.__iter__cCstdt|ƒj›dƒ‚dS)Nzcannot create z copies)rCr2rwrMrrrrp1szEnvironHeaders.copy)F) rwryrzr{rr&r|rrRrQrprrrrrˆs    
 
 
rˆ)r)Ú
__future__rÚreÚtypingr\r,Ú    _internalrÚ
exceptionsrZmixinsrÚ
structuresrr    r
rSrTÚcompiler†rUrˆÚrrrrrÚ<module>s$      N
0