4V=j$T ddlmZddlmZddlZddlZddlm Z ddl m Z ddl m Z ddlmZdd lmZejr ddlZdd lmZejd ZGd d ZddZejdZddZGdde eZddlmZdS)) annotationsN)_missing)BadRequestKeyError)ImmutableHeadersMixin)iter_multi_items) MultiDict)WSGIEnvironmentTceZdZdZ dkdldZejdmd Zejdnd ZejdodZdpdZdmdZdqdZ dZ ejdrdZ ejdsdZ ejdtdZ ejdud#Z ejdvd$Z dwdxd'Z ejdyd)Z ejdzd+Z dkd{d-Z d|d/Z d}d~d3Zd}dd5Zdd6Z dkdd9Zdd:Zdd;Zdd<Zejdd=Zejdmd>ZejdddAZejdsdBZejdtdCZdefddFZddGZddHZddJZddKZddNZddOZddPZddQZddTZddUZ ddVZ!ejddWZ"ejddYZ"ejdd[Z"dd]Z" dkdd`Z#ddbZ$dddZ%ddfZ&ddgZ'ddhZ(ddiZ)ddjZ*dS)HeadersaAn 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:: 3.1 Implement ``|`` and ``|=`` operators. .. 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. NdefaultsHeaders | MultiDict[str, t.Any] | cabc.Mapping[str, t.Any | list[t.Any] | tuple[t.Any, ...] | set[t.Any]] | cabc.Iterable[tuple[str, t.Any]] | NonereturnNonecFg|_|||dSdSN)_listextend)selfrs MC:\PYTHON\_runtimes\venv\Lib\site-packages\werkzeug/datastructures/headers.py__init__zHeaders.__init__<s1-/   KK ! ! ! ! ! keystrcdSrrrs r __getitem__zHeaders.__getitem__Ks,/Crinttuple[str, str]cdSrrrs rr zHeaders.__getitem__Ms8;rslicete.SelfcdSrrrs rr zHeaders.__getitem__O25#rstr | int | slicestr | tuple[str, str] | te.Selfct|tr||St|tr |j|S||j|Sr) isinstancer_get_keyr!r __class__rs rr zHeaders.__getitem__Qs\ c3   &==%% % c3   #:c? "~~djo...rc|}|jD]!\}}||kr|cS"t|r)lowerrr)rrikeykvs rr,zHeaders._get_keyZsUyy{{J  DAqwwyyD  !!%%%rotherobjectboolc|j|jurtSdd}tt||jtt||jkS)Nitemtuple[str, ...]rcN|dg|ddRS)Nrrr/)r7s rloweredzHeaders.__eq__..loweredgs'7==??-T!""X-- -r)r7r8rr8)r-NotImplementedsetmapr)rr3r;s r__eq__zHeaders.__eq__cs` ?$. 0 0! ! . . . .3w ,,--S$*5M5M1N1NNNr str | NonecdSrrrs rgetz Headers.getns+.3rdefaultcdSrrrrrCs rrBz Headers.getpr'rr str | TcdSrrrEs rrBz Headers.getr47Crtypecabc.Callable[[str], T]T | NonecdSrrrrrIs rrBz Headers.gettsHKrcdSrr)rrrCrIs rrBz Headers.getvsMPSrstr | T | Nonecabc.Callable[[str], T] | Nonec ||}n#t$r|cYSwxYw||S ||S#t$r|cYSwxYw)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:: 3.0 The ``as_bytes`` parameter was removed. .. versionchanged:: 0.9 The ``as_bytes`` parameter was added. )r,KeyError ValueError)rrrCrIrvs rrBz Headers.getxs< s##BB   NNN  <I 488O   NNN s '' : A A  list[str]cdSrrrs rgetlistzHeaders.getlists.1crlist[T]cdSrrrMs rrWzHeaders.getlistsKN3rlist[str] | list[T]c||Tg}|D]M\}}|kr0 |||=#t$rYIwxYwN|Sfd|DS)aReturn 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:: 3.0 The ``as_bytes`` parameter was removed. .. versionchanged:: 0.9 The ``as_bytes`` parameter was added. NcJg|]\}}|k| Srr:).0r1r2r0s r z#Headers.getlist..s/888daaggii4&7&7&7&7&7r)r/appendrS)rrrIresultr1r2r0s @rrWzHeaders.getlists(yy{{  F ! !17799$$! dd1gg....%!!! !% M8888d8888sA A&%A&namec,||S)zReturn 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. )rW)rras rget_allzHeaders.get_alls ||D!!!rFr/t.Iterable[tuple[str, str]]c#RK|D]!\}}|r|}||fV"dSrr:)rr/rvalues ritemsz Headers.itemssK  JC "iikku*      rt.Iterable[str]c#HK||D] \}}|V dSrrg)rr/r_s rkeysz Headers.keyss:jj''  FCIIII  rc#FK|D] \}}|V dSrrj)rrkrfs rvalueszHeaders.valuess6   HAuKKKK  rargkwargsc |+t|D]\}}|||t|D]\}}|||dS)aExtend 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``. N)r addrrorprrfs rrzHeaders.extendsw2 ?.s33 % % Ue$$$$*622 ! !JC HHS%  ! !rcnt|tr||dS|j|=dSr)r+r_del_keyrrs r __delitem__zHeaders.__delitem__s8 c3    MM#    F JsOOOrc|}g}|jD]4\}}||kr|||f5||jdd<dSr)r/rr_)rrnewr1r2s rruzHeaders._del_keysfiikkJ # #DAqwwyyC Aq6""" 111 rc,||S)zBRemove a key. :param key: The key to be removed. )rurs rremovezHeaders.removes }}S!!!rcdSrrrs rpopz Headers.pops&)crcdSrrrs rr}z Headers.pops$'Cr. int | NonecdSrrrs rr}z Headers.pops=@SrcdSrrrEs rr}z Headers.popr'rcdSrrrEs rr}z Headers.pop!rHrstr | int | Nonestr | tuple[str, str] | Tc*||jSt|tr|j|S ||}n#t $r|t ur|cYSwxYw|||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. )rr}r+r!r,rRrrz)rrrCrTs rr}z Headers.pop#s ;:>>## # c3   ':>>#&& & s##BB   h&&    C s A""A;9A;c4|jS)z7Removes a key or index and returns a (key, value) item.)rr}r|s rpopitemzHeaders.popitemAsz~~rcV ||n#t$rYdSwxYwdS)zCheck if a key is present.FT)r,rRrs r __contains__zHeaders.__contains__EsE  MM#       55 ts  &&t.Iterator[tuple[str, str]]c*t|jS)zYield ``(key, value)`` tuples.)iterrr|s r__iter__zHeaders.__iter__NsDJrc*t|jSr)lenrr|s r__len__zHeaders.__len__Rs4:rrft.Anyc |rt||}t|}|j||fdS)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. .. versionchanged:: 0.4.1 keyword arguments were added for :mod:`wsgiref` compatibility. N)_options_header_vkw_str_header_valuerr_)rrrfrp value_strs rrrz Headers.addUsI  7'v66E%e,,  3 *+++++rc $|j||fi|dS)zAdd 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)rr)rrrfrps r add_headerzHeaders.add_headerks& e&&v&&&&&rc8|jdS)zClears all headers.N)rclearr|s rrz Headers.clearss rc  |rt||}t|}|js|j||fdSt |j}| t |D].\}\}}| kr||f|j|<n/|j||fdS fd|D|j|dzd<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. NcPg|]"}|dk |#S)rr:)r]tr0s rr^zHeaders.set..s/ N N Nq19M9M9M9M9Mrr)rrrr_rr/ enumerate) rrrfrpr iter_listidxold_keyrkr0s @rr=z Headers.setws  7'v66E%e,, z  J  sI. / / / F$$ yy{{!*9!5!5   C'1}}$&&#& "2 3' J  sI. / / / F!O N N NI N N N 3799rrncabc.Iterable[t.Any]c|rOt|}||t||D]}|||dS||dS)zRemove 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)rr=nextrrrz)rrrn values_iterrfs rsetlistzHeaders.setlists}  v,,K HHS${++ , , ,$ % %e$$$$ % % KK     rc ||S#t$rYnwxYw|||||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,rRr=rEs r setdefaultzHeaders.setdefaultsa ==%% %    D  g}}S!!!s  $$c`||vr|||||S)aReturn 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 )rrWrEs rsetlistdefaultzHeaders.setlistdefaults3 d?? LLg & & &||C   rcdSrrrrrfs r __setitem__zHeaders.__setitem__s;>3rtuple[str, t.Any]cdSrrrs rrzHeaders.__setitem__sGJsr cabc.Iterable[tuple[str, t.Any]]cdSrrrs rrzHeaders.__setitem__s sr.s*KKKTQ#4Q#7#78KKKrN)r+rr=r!rrrs rrzHeaders.__setitem__s c3   L HHS% S ! ! L#Ah(9%((C(CCDJsOOOKKUKKKDJsOOOrHeaders | MultiDict[str, t.Any] | cabc.Mapping[str, t.Any | list[t.Any] | tuple[t.Any, ...] | cabc.Set[t.Any]] | cabc.Iterable[tuple[str, t.Any]] | None9t.Any | list[t.Any] | tuple[t.Any, ...] | cabc.Set[t.Any]c |t|ttfrA|D]+}||||,nt|t jrj|D]T\}}t|tttfr|||>| ||Un|D]\}}| |||D]T\}}t|tttfr|||>| ||UdS)aReplace 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 N) r+rr rlrrWcabcMappingrglisttupler=rss rupdatezHeaders.updatesr4 ?#344 )88::88CLLckk#&6&677778C.. )"%))++--JC!%$s);<<- S%0000e,,,, - #&))JCHHS%(((( ,,.. % %JC%$s!344 % S%((((e$$$$  % %rLcabc.Mapping[str, t.Any | list[t.Any] | tuple[t.Any, ...] | cabc.Set[t.Any]]ct|tjstS|}|||Sr)r+rrr<copyr)rr3rTs r__or__zHeaders.__or__sB %.. "! ! YY[[ % rocabc.Mapping[str, t.Any | list[t.Any] | tuple[t.Any, ...] | cabc.Set[t.Any]] | cabc.Iterable[tuple[str, t.Any]]ct|tjtjfstS|||Sr)r+rrIterabler<rrr3s r__ior__zHeaders.__ior__$s<%$, !>?? "! ! E rlist[tuple[str, str]]c t|S)zRConvert the headers into a list suitable for WSGI. :return: list )rr|s r to_wsgi_listzHeaders.to_wsgi_list1s Dzzrc6||jSr)r-rr|s rrz Headers.copy8s~~dj)))rc*|Sr)rr|s r__copy__zHeaders.__copy__;syy{{rcg}|D]\}}||d| |dd|S)z9Returns formatted headers suitable for HTTP transmission.z: z )rr_join)rstrsrrfs r__str__zHeaders.__str__>sm++-- + +JC KK3))%)) * * * * F{{4   rcPt|jdt|dS)N())rI__name__rr|s r__repr__zHeaders.__repr__Fs(t**%77T 7777rr)rrrrrrrr)rr!rr")rr$rr%)rr(rr)r3r4rr5)rrrr@)rrrCrrr)rrrCr rrF)rrrIrJrrK)rrrCr rIrJrr )NN)rrrCrOrIrPrrO)rrrrU)rrrIrJrrX)rrrIrPrrZ)rarrrU)F)r/r5rrd)r/r5rrh)rrh)rorrprrr)rr(rr)rrrr)rr").)rrrr")rrrCrFrr)rrrr5)rrrr!)rrrfrrprrr)rr)rrrnrrr)rrrCrrr)rrrCrrrU)rrrfrrr)rr!rfrrr)rr$rfrrr)rr(rfrrr)rorrprrr)r3rrr%)r3rrr%)rr)rr%)rr)+r __module__ __qualname____doc__rroverloadr r,r?__hash__rBrWrcrgrlrnrrvrurzr}rrrrrrrrrr=rrrrrrrrrrrrrrrrrs%%^  " " " " "Z///Z/Z;;;Z;Z555Z5////&&&&OOOOHZ...Z.Z555Z5Z777Z7ZKKKZKZPPPZP#'/3 )))))VZ111Z1ZNNNZN?C"9"9"9"9"9H""""  !!!!!@""""Z)))Z)Z'''Z'Z@@@@Z@Z555Z5Z777Z7!%#<        ,,,,,''''&O&O&O&OP""""""!!!!&Z>>>Z>ZJJJZJZZ L L L L. ,%,%,%,%,%\        ****!!!!888888rrrfrkwdict[str, t.Any]rcdtj|d|DS)NcBi|]\}}|dd|S)rk-)replacers r z'_options_header_vkw..Ls,>>>41a #s##Q>>>r)httpdump_options_headerrg)rfrs rrrJs3  # >>288::>>>  rz[\r\n]rct|tst|}t|t d|S)Nz2Header values must not contain newline characters.)r+r _newline_researchrS)rfs rrrSsG eS ! !E %  ,MNNN Lrc`eZdZdZdfd Zdd Zd ZddZddZddZ ddZ ddZ ddZ xZ S)EnvironHeadersaRead 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. environr rrcVt||_dSr)superrr)rrr-s rrzEnvironHeaders.__init__gs$  rr3r4r5cVt|tstS|j|juSr)r+rr<rrs rr?zEnvironHeaders.__eq__ks)%00 "! !|u},,rNrrc,||Sr)r,rs rr zEnvironHeaders.__getitem__ss}}S!!!rct|tst||dd}|dvr |j|S|jd|S)Nrrk CONTENT_TYPECONTENT_LENGTHHTTP_)r+rrupperrrrs rr,zEnvironHeaders._get_keyvsk#s## *$S)) )iikk!!#s++ 4 4 4<$ $|MCMM**rr!c4td|DS)Nc3K|]}dVdS)rNr)r]rks r z)EnvironHeaders.__len__..s"##1######r)sumr|s rrzEnvironHeaders.__len__s##d######rcabc.Iterator[tuple[str, str]]c#HK|jD]\}}|dr9|dvr5|dddd|fVS|dvr.|r,|dd|fVdS)Nr>HTTP_CONTENT_TYPEHTTP_CONTENT_LENGTHrkrr)rrg startswithrtitlers rrzEnvironHeaders.__iter__s,,,.. ; ;JC~~g&& ;37,,!""gooc3//5577>>>>>:::u:kk#s++1133U:::: ; ;r t.NoReturncLtdt|jdNzcannot create z copies TypeErrorrIrr|s rrzEnvironHeaders.copy%Gd)<GGGHHHrrcLtdt|jdrrrs rrzEnvironHeaders.__or__rr)rr rrrrr)rr)rr)r3rrr)rrrrrr?rr r,rrrr __classcell__)r-s@rrr]s---- H"""" + + + +$$$$;;;;IIIIIIIIIIIIrr)r)rfrrrrr)rfrrr) __future__rcollections.abcabcrretypingr _internalr exceptionsrmixinsr structuresr r TYPE_CHECKINGtyping_extensionste_typeshed.wsgir TypeVarr rrcompilerrrrrrrrs""""""  ++++++))))))((((((!!!!!!?/""""...... AIcNNs8s8s8s8s8s8s8s8l bj## 5I5I5I5I5I*G5I5I5Irr