U a^~@shddlZddlZddlZddlZddlZddlmZddlmZddlm Z ddl m Z ddl m Z ddlmZdd lmZdd lmZdd lmZdd lmZd dZddZGdddZGdddeeZGdddZGdddeZddZGdddeZ GdddeZ!Gdd d ee!Z"Gd!d"d"e!Z#Gd#d$d$Z$Gd%d&d&e#Z%d'd(Z&d)d*Z'Gd+d,d,Z(Gd-d.d.Z)Gd/d0d0e)e(Z*Gd1d2d2ee#Z+Gd3d4d4e#Z,Gd5d6d6eeZ-Gd7d8d8ee#Z.Gd9d:d:ee%Z/Gd;d<dd?Z3Gd@dAdAe0Z4e1dBZ5dCdDZ6GdEdFdFe0Z7GdGdHdHe0Z8dIdJZ9dKdLZ:GdMdNdNe eZ;GdOdPdPee;ZGdUdVdVe eZ?GdWdXdXe eZ@GdYdZdZeZAGd[d\d\eZBGd]d^d^ZCGd_d`d`ZDdadbZEGdcddddZFGdedfdfeeZGdpdgdhZHdqdidjZIGdkdldle eZJGdmdndnZKddolmLZLdS)rN) Collection) MutableSetdeepcopy)BytesIO)repeat)fspath) exceptions)_make_encode_wrapper)_missing)get_filesystem_encodingcCstt|jddS)Nz objects are immutable TypeErrortype__name__selfrXC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-1tps7o9u\werkzeug\datastructures.py is_immutablesrccsxt|tr|jddEdHnVt|trj|D]6\}}t|ttfr\|D]}||fVqJq0||fVq0n |EdHdS)zyIterates over the items of a mapping yielding keys and values without dropping any from more complex structures. TmultiN) isinstance MultiDictitemsdicttuplelist)mappingkeyvaluevrrriter_multi_itemss  r#c@seZdZdZdZddZddZddZd d Zd d Z d dZ ddZ ddZ ddZ ddZdddZddZd ddZdS)!ImmutableListMixinzOMakes a :class:`list` immutable. .. versionadded:: 0.5 :private: NcCs&|jdk r|jStt|}|_|SN) _hash_cachehashrrrvrrr__hash__2s zImmutableListMixin.__hash__cCst|t|ffSr%)rrrprotocolrrr __reduce_ex__8sz ImmutableListMixin.__reduce_ex__cCs t|dSr%rrr rrr __delitem__;szImmutableListMixin.__delitem__cCs t|dSr%r.rotherrrr__iadd__>szImmutableListMixin.__iadd__cCs t|dSr%r.r1rrr__imul__AszImmutableListMixin.__imul__cCs t|dSr%r.rr r!rrr __setitem__DszImmutableListMixin.__setitem__cCs t|dSr%r.ritemrrrappendGszImmutableListMixin.appendcCs t|dSr%r.r7rrrremoveJszImmutableListMixin.removecCs t|dSr%r.)riterablerrrextendMszImmutableListMixin.extendcCs t|dSr%r.rposr!rrrinsertPszImmutableListMixin.insertcCs t|dSr%r.)rindexrrrpopSszImmutableListMixin.popcCs t|dSr%r.rrrrreverseVszImmutableListMixin.reverseFcCs t|dSr%r.)rr rCrrrsortYszImmutableListMixin.sort)r@)NF)r __module__ __qualname____doc__r&r*r-r0r3r4r6r9r:r<r?rBrCrDrrrrr$(s r$c@seZdZdZddZdS) ImmutableListzJAn immutable :class:`list`. .. versionadded:: 0.5 :private: cCst|jdt|dSN())rrr__repr__rrrrrLeszImmutableList.__repr__N)rrErFrGrLrrrrrH]srHcs~eZdZdZdZedfdd ZddZddZd d Z dd d Z d dZ dddZ ddZ ddZddZddZZS)ImmutableDictMixinzOMakes a :class:`dict` immutable. .. versionadded:: 0.5 :private: Ncs$t|}|t|t||Sr%)super__new____init__zipr)clskeysr!instance __class__rrfromkeysss zImmutableDictMixin.fromkeyscCst|t|ffSr%)rrr+rrrr-ysz ImmutableDictMixin.__reduce_ex__cCs|Sr%rrrrr_iter_hashitems|sz"ImmutableDictMixin._iter_hashitemscCs*|jdk r|jStt|}|_|Sr%)r&r' frozensetrYr(rrrr*s zImmutableDictMixin.__hash__cCs t|dSr%r.rr defaultrrr setdefaultszImmutableDictMixin.setdefaultcOs t|dSr%r.rargskwargsrrrupdateszImmutableDictMixin.updatecCs t|dSr%r.r[rrrrBszImmutableDictMixin.popcCs t|dSr%r.rrrrpopitemszImmutableDictMixin.popitemcCs t|dSr%r.r5rrrr6szImmutableDictMixin.__setitem__cCs t|dSr%r.r/rrrr0szImmutableDictMixin.__delitem__cCs t|dSr%r.rrrrclearszImmutableDictMixin.clear)N)N)N)rrErFrGr& classmethodrWr-rYr*r]rarBrbr6r0rc __classcell__rrrUrrMis  rMc@sJeZdZdZddZddZddZdd Zd d Zd d Z dddZ dS)ImmutableMultiDictMixinzTMakes a :class:`MultiDict` immutable. .. versionadded:: 0.5 :private: cCst|t|jddffSNTrrrrr+rrrr-sz%ImmutableMultiDictMixin.__reduce_ex__cCs |jddSrgrXrrrrrYsz'ImmutableMultiDictMixin._iter_hashitemscCs t|dSr%r.r5rrraddszImmutableMultiDictMixin.addcCs t|dSr%r.rrrr popitemlistsz#ImmutableMultiDictMixin.popitemlistcCs t|dSr%r.r/rrrpoplistszImmutableMultiDictMixin.poplistcCs t|dSr%r.rr new_listrrrsetlistszImmutableMultiDictMixin.setlistNcCs t|dSr%r.rr Z default_listrrrsetlistdefaultsz&ImmutableMultiDictMixin.setlistdefault)N) rrErFrGr-rYrirjrkrnrprrrrrfsrfcsfdd}|_|S)Ncs.ttt|||}|jdk r*|||Sr%)getattrrNUpdateDictMixin on_update)rr_kwr)namerroncalls  z_calls_update..oncall)r)rvrwrrur _calls_updates rxcs^eZdZdZdZd fdd Zeffdd ZedZ edZ ed Z ed Z ed Z ZS) rrzbMakes dicts call `self.on_update` on modifications. .. versionadded:: 0.5 :private: Ncs2||k}t||}|r.|jdk r.|||Sr%)rNr]rsrr r\modifiedr)rUrrr]s  zUpdateDictMixin.setdefaultcsH||k}|tkrt|}nt||}|rD|jdk rD|||Sr%)r rNrBrsryrUrrrBs zUpdateDictMixin.popr6r0rcrbra)N)rrErFrGrsr]r rBrxr6r0rcrbrarerrrUrrrs rrc@seZdZdZdddZdS)TypeConversionDictzWorks like a regular dict but the :meth:`get` method can perform type conversions. :class:`MultiDict` and :class:`CombinedMultiDict` are subclasses of this class and provide the same feature. .. versionadded:: 0.5 NcCsXz ||}Wntk r$|YSX|dk rTz ||}Wntk rR|}YnX|S)aReturn 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 = TypeConversionDict(foo='42', bar='blub') >>> d.get('foo', type=int) 42 >>> d.get('bar', -1, type=int) -1 :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:`MultiDict`. If a :exc:`ValueError` is raised by this callable the default value is returned. N)KeyError ValueError)rr r\rr)rrrgets    zTypeConversionDict.get)NN)rrErFrGr~rrrrr{sr{c@s eZdZdZddZddZdS)ImmutableTypeConversionDictzpWorks like a :class:`TypeConversionDict` but does not support modifications. .. versionadded:: 0.5 cCst|SzReturn a shallow mutable copy of this object. Keep in mind that the standard library's :func:`copy` function is a no-op for this class like for any other python immutable type (eg: :class:`tuple`). )r{rrrrcopysz ImmutableTypeConversionDict.copycCs|Sr%rrrrr__copy__sz$ImmutableTypeConversionDict.__copy__NrrErFrGrrrrrrrsrc@seZdZdZd9ddZddZddZd d Zd d Zd dZ ddZ d:ddZ ddZ d;ddZ dd$d%Zd?d'd(Zd)d*Zefd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8ZdS)@raA :class:`MultiDict` is a dictionary subclass customized to deal with multiple values for the same key which is for example used by the parsing functions in the wrappers. This is necessary because some HTML form elements pass multiple values for the same key. :class:`MultiDict` implements all standard dictionary methods. Internally, it saves all values for a key as a list, but the standard dict access methods will only return the first value for a key. If you want to gain access to the other values, too, you have to use the `list` methods as explained below. Basic Usage: >>> d = MultiDict([('a', 'b'), ('a', 'c')]) >>> d MultiDict([('a', 'b'), ('a', 'c')]) >>> d['a'] 'b' >>> d.getlist('a') ['b', 'c'] >>> 'a' in d True It behaves like a normal dict thus all dict functions will only return the first value when multiple values for one key are found. 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. A :class:`MultiDict` can be constructed from an iterable of ``(key, value)`` tuples, a dict, a :class:`MultiDict` or from Werkzeug 0.2 onwards some keyword parameters. :param mapping: the initial value for the :class:`MultiDict`. Either a regular dict, an iterable of ``(key, value)`` tuples or `None`. NcCst|tr&t|dd|Dnt|tri}|D]<\}}t|ttfrjt|dkr`qNsz%MultiDict.__init__..rr) rrrrPlistsrrrlenr]r9)rrtmpr r!rrrrPLs      zMultiDict.__init__cCs t|Sr%)rrrrrr __getstate__`szMultiDict.__getstate__cCst|t||dSr%)rrcrarr!rrr __setstate__cs zMultiDict.__setstate__cCs t|Sr%)r__iter__rrrrrgszMultiDict.__iter__cCs6||kr(t||}t|dkr(|dSt|dS)zReturn the first data value for this key; raises KeyError if not found. :param key: The key to be looked up. :raise KeyError: if the key does not exist. rN)r __getitem__rr BadRequestKeyError)rr lstrrrrms   zMultiDict.__getitem__cCst|||gdS)zLike :meth:`add` but removes an existing key first. :param key: the key for the value. :param value: the value to set. N)rr6r5rrrr6{szMultiDict.__setitem__cCst||g|dS)zAdds a new value for the key. .. versionadded:: 0.6 :param key: the key for the value. :param value: the value to add. N)rr]r9r5rrrrisz MultiDict.addc Cstzt||}Wntk r(gYSX|dkr:t|Sg}|D],}z|||WqBtk rlYqBXqB|S)a]Return the list of items for a given key. If that key is not in the `MultiDict`, the return value will be an empty list. Just like `get`, `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:`MultiDict`. 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. N)rrr|rr9r}rr rr)resultr8rrrgetlists  zMultiDict.getlistcCst||t|dS)aRemove the old values for a key and add new ones. Note that the list you pass the values in will be shallow-copied before it is inserted in the dictionary. >>> d = MultiDict() >>> d.setlist('foo', ['1', '2']) >>> d['foo'] '1' >>> d.getlist('foo') ['1', '2'] :param key: The key for which the values are set. :param new_list: An iterable with the new values for the key. Old values are removed first. N)rr6rrlrrrrnszMultiDict.setlistcCs||kr|||<n||}|S)aGReturns the value for the key if it is in the dict, otherwise it returns `default` and sets that value for `key`. :param key: The key to be looked up. :param default: The default value to be returned if the key is not in the dict. If not further specified it's `None`. rr[rrrr]s zMultiDict.setdefaultcCs4||kr$t|pd}t|||n t||}|S)aLike `setdefault` but sets multiple values. The list returned is not a copy, but the list that is actually used internally. This means that you can put new values into the dict by appending items to the list: >>> d = MultiDict({"foo": 1}) >>> d.setlistdefault("foo").extend([2, 3]) >>> d.getlist("foo") [1, 2, 3] :param key: The key to be looked up. :param default_list: An iterable of default values. It is either copied (in case it was a list) or converted into a list before returned. :return: a :class:`list` r)rrr6rrorrrrps   zMultiDict.setlistdefaultFccs@t|D]0\}}|r,|D]}||fVqq ||dfVq dS)aReturn an iterator of ``(key, value)`` pairs. :param multi: If set to `True` the iterator returned will have a pair for each value of each key. Otherwise it will only contain pairs for the first value of each key. rN)rr)rrr valuesr!rrrrs zMultiDict.itemsccs&t|D]\}}|t|fVq dS)zuReturn a iterator of ``(key, values)`` pairs, where values is the list of all values associated with the key.N)rrrrr rrrrrszMultiDict.listsccst|D]}|dVq dS)zAReturns an iterator of the first value on every key's value list.rNrrrrrrrrszMultiDict.valuescCs t|S)aReturn an iterator of all values associated with a key. Zipping :meth:`keys` and this is the same as calling :meth:`lists`: >>> d = MultiDict({"foo": [1, 2, 3]}) >>> zip(d.keys(), d.listvalues()) == d.lists() True rrrrr listvaluesszMultiDict.listvaluescCs ||S)z%Return a shallow copy of this object.rUrrrrrszMultiDict.copycCs|t|jdd|S)z"Return a deep copy of this object.F)flat)rVrto_dictrmemorrrrszMultiDict.deepcopyTcCs|rt|St|S)aReturn the contents as regular dict. If `flat` is `True` the returned dict will only have the first item present, if `flat` is `False` all values will be returned as lists. :param flat: If set to `False` the dict returned will have lists with all the values in it. Otherwise it will only contain the first value for each key. :return: a :class:`dict` )rrr)rrrrrr s  zMultiDict.to_dictcCs$t|D]\}}t|||qdS)aupdate() extends rather than replaces existing key lists: >>> a = MultiDict({'x': 1}) >>> b = MultiDict({'x': 2, 'y': 3}) >>> a.update(b) >>> a MultiDict([('y', 3), ('x', 1), ('x', 2)]) If the value list for a key in ``other_dict`` is empty, no new values will be added to the dict and the key will not be created: >>> x = {'empty_list': []} >>> y = MultiDict() >>> y.update(x) >>> y MultiDict([]) N)r#rrirrr r!rrrraszMultiDict.updatecCs`z,t||}t|dkr$t||dWStk rZ|tk rL|YSt|YnXdS)aPop the first item for a list on the dict. Afterwards the key is removed from the dict, so additional values are discarded: >>> d = MultiDict({"foo": [1, 2, 3]}) >>> d.pop("foo") 1 >>> "foo" in d False :param key: the key to pop. :param default: if provided the value to return if the key was not in the dictionary. rN)rrBrr rr|r )rr r\rrrrrB-s    z MultiDict.popc Csrz:t|}t|ddkr&t||d|ddfWStk rl}zt|jdW5d}~XYnXdS)zPop an item from the dict.r rN)rrbrr rr|r_)rr8errrrbGs  zMultiDict.popitemcCst||gS)zPop the list for a key from the dict. If the key is not in the dict an empty list is returned. .. versionchanged:: 0.5 If the key does no longer exist a list is returned instead of raising an error. )rrBr/rrrrkSszMultiDict.poplistc CsDz t|WStk r>}zt|jdW5d}~XYnXdS)z*Pop a ``(key, list)`` tuple from the dict.rN)rrbr|r rr_)rrrrrrj]s zMultiDict.popitemlistcCs|Sr%rrrrrrdszMultiDict.__copy__cCs |j|dS)N)rrrrrr __deepcopy__gszMultiDict.__deepcopy__cCs"t|jdt|jdddS)NrJTrrK)rrrrrrrrrLjszMultiDict.__repr__)N)N)N)N)F)N)T)rrErFrGrPrrrrr6rirrnr]rprrrrrrrrar rBrbrkrjrrrLrrrrr#s6(           rc@s$eZdZdZdZddZddZdS) _omd_bucketa Wraps values in the :class:`OrderedMultiDict`. This makes it possible to keep an order over multiple different keys. It requires a lot of extra memory and slows down access a lot, but makes it possible to access elements in O(1) and iterate in O(n). )prevr r!nextcCsF|j|_||_||_d|_|jdkr*||_|jdk r<||j_||_dSr%) _last_bucketrr r!r _first_bucket)romdr r!rrrrPws  z_omd_bucket.__init__cCsH|jr|j|j_|jr |j|j_|j|kr2|j|_|j|krD|j|_dSr%)rrrr)rrrrrunlinks    z_omd_bucket.unlinkN)rrErFrG __slots__rPrrrrrrns rc@seZdZdZd2ddZddZdZddZd d Zd d Z d dZ ddZ ddZ ddZ ddZddZd3ddZddZddZd d!Zd4d"d#Zd$d%Zd5d&d'Zd(d)Zd*d+Zefd,d-Zd.d/Zd0d1ZdS)6OrderedMultiDictaNWorks like a regular :class:`MultiDict` but preserves the order of the fields. To convert the ordered multi dict into a list you can use the :meth:`items` method and pass it ``multi=True``. In general an :class:`OrderedMultiDict` is an order of magnitude slower than a :class:`MultiDict`. .. admonition:: note Due to a limitation in Python you cannot convert an ordered multi dict into a regular dict by using ``dict(multidict)``. Instead you have to use the :meth:`to_dict` method, otherwise the internal bucket objects are exposed. NcCs.t|d|_|_|dk r*t||dSr%)rrPrrrra)rrrrrrPs  zOrderedMultiDict.__init__c Cst|tstSt|trt|jdd}t|jdd}z6|D],\}}t|\}}||ksb||kr>WdSq>Wntk rYdSXz t|Wntk rYdSXdSt|t|krdS| D]\}} | || krdSqdS)NTrF) rrNotImplementedriterrr StopIterationrrr) rr2Ziter1Ziter2Zk1Zv1Zk2Zv2r rrrr__eq__s.     zOrderedMultiDict.__eq__cCst|t|jddffSrgrhr+rrrr-szOrderedMultiDict.__reduce_ex__cCst|jddSrg)rrrrrrrszOrderedMultiDict.__getstate__cCs(t||D]\}}|||qdSr%)rrcri)rrr r!rrrrs  zOrderedMultiDict.__setstate__cCs(||krt||djSt|dSNr)rrr!r rr/rrrrszOrderedMultiDict.__getitem__cCs|||||dSr%rkrir5rrrr6s zOrderedMultiDict.__setitem__cCs||dSr%rBr/rrrr0szOrderedMultiDict.__delitem__cCsdd|DS)Ncss|]\}}|VqdSr%rrr r!rrrrsz(OrderedMultiDict.keys..rXrrrrrSszOrderedMultiDict.keyscCs t|Sr%rrSrrrrrszOrderedMultiDict.__iter__cCsdd|DS)Ncss|]\}}|VqdSr%rrrrrrsz*OrderedMultiDict.values..rXrrrrrszOrderedMultiDict.valuesFccsh|j}|r*|dk rd|j|jfV|j}q n:t}|dk rd|j|kr\||j|j|jfV|j}q0dSr%)rr r!rsetri)rrptr returned_keysrrrrs   zOrderedMultiDict.itemsccsJt}|j}|dk rF|j|kr>|j||jfV||j|j}q dSr%)rrr rrir)rrrrrrrs  zOrderedMultiDict.listsccs|D]\}}|VqdSr%r)r_keyrrrrrszOrderedMultiDict.listvaluescCs t||gt|||dSr%)rr]r9rr5rrrriszOrderedMultiDict.addc Cs|zt||}Wntk r(gYSX|dkr@dd|DSg}|D].}z|||jWqHtk rtYqHXqH|S)NcSsg|] }|jqSrr!rxrrr sz,OrderedMultiDict.getlist..)rrr|r9r!r}rrrrrs zOrderedMultiDict.getlistcCs$|||D]}|||qdSr%r)rr rmr!rrrrn s zOrderedMultiDict.setlistcCs tddS)Nz5setlistdefault is unsupported for ordered multi dicts)rrorrrrpszOrderedMultiDict.setlistdefaultcCs$t|D]\}}t|||qdSr%)r#rrirrrrraszOrderedMultiDict.updatecCs0t||d}|D]}||qdd|DS)NrcSsg|] }|jqSrrrrrrrsz,OrderedMultiDict.poplist..)rrBr)rr bucketsbucketrrrrks zOrderedMultiDict.poplistcCs^zt||}Wn.tk r>|tk r0|YSt|YnX|D]}||qD|djSr)rrBr|r r rrr!)rr r\rrrrrrBs zOrderedMultiDict.popc Cshzt|\}}Wn2tk rD}zt|jdW5d}~XYnX|D]}||qJ||djfSr)rrbr|r rr_rr!rr rrrrrrrb)s" zOrderedMultiDict.popitemc Cslzt|\}}Wn2tk rD}zt|jdW5d}~XYnX|D]}||qJ|dd|DfS)NrcSsg|] }|jqSrrrrrrr9sz0OrderedMultiDict.popitemlist..)rrbr|r rr_rrrrrrj2s" zOrderedMultiDict.popitemlist)N)F)N)N)rrErFrGrPrr*r-rrrr6r0rSrrrrrrirrnrprarkr rBrbrjrrrrrs2       rcCst|dd|DS)NcSsi|]\}}|dd|qS)_-)replacerrr"rrr >s z'_options_header_vkw..)httpZdump_options_headerr)r!rtrrr_options_header_vkw<srcCs*t|tr|d}t|ts&t|}|S)Nzlatin-1)rbytesdecodestrrrrr_unicodify_header_valueBs    rc@s0eZdZdZdGddZdHddZdd ZdZdId d ZdJd d Z ddZ dKddZ dLddZ ddZ ddZdMddZddZdefddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Z d;d<Z!d=d>Z"d?d@Z#dAdBZ$dCdDZ%dEdFZ&dS)NHeadersaAn 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 :class:`Headers` object pass it a list or dict of headers which are used as default values. This does not reuse the list passed to the constructor for internal usage. :param defaults: The list of default values for the :class:`Headers`. .. 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. NcCs8g|_|dk r4t|ttfr*|j|n ||dSr%)_listrrrr<)rdefaultsrrrrPls zHeaders.__init__FcCs|s2t|tr|j|St|tr2||j|St|tsFt||}|jD]\}}||krT|SqT|r|t t|dSr%) rintrslicerVrr rlowerr|)rr _get_modeikeyrr"rrrrts       zHeaders.__getitem__cCs4dd}|j|jko2tt||jtt||jkS)NcSs|df|ddSNrr r)r8rrrloweredszHeaders.__eq__..lowered)rVrmapr)rr2rrrrrs  zHeaders.__eq__cCsnz|j|dd}Wntk r*|YSX|r:|d}|dkrF|Sz ||WStk rh|YSXdS)aReturn 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 .. versionadded:: 0.9 Added support for `as_bytes`. :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. :param as_bytes: return bytes instead of strings. Trlatin1N)rr|encoder})rr r\ras_bytesr)rrrr~s   z Headers.getc Csp|}g}|D]Z\}}||kr|r2|d}|dk r`z ||}Wntk r^YqYnX||q|S)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. .. versionadded:: 0.9 Added support for `as_bytes`. :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. :param as_bytes: return bytes instead of strings. rN)rrr}r9)rr rrrrrr"rrrrs      zHeaders.getlistcCs ||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. )rrrvrrrget_allszHeaders.get_allccs(|D]\}}|r|}||fVqdSr%r)rrr r!rrrrs z Headers.itemsccs||D]\}}|Vq dSr%rX)rrr rrrrrSsz Headers.keysccs|D]\}}|VqdSr%rX)rrr!rrrrszHeaders.valuescOsft|dkrtdt||rDt|dD]\}}|||q.t|D]\}}|||qLdS)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``. r )update expected at most 1 arguments, got rN)rrr#ri)rr_r`r r!rrrr<s zHeaders.extendTcCsf|rt|ttfr|j|=dS|}g}|jD]"\}}||kr0|||fq0||jdd<dSr%)rrrrrr9)rr _index_operationnewrr"rrrr0s zHeaders.__delitem__cCs|j|ddS)zBRemove a key. :param key: The key to be removed. F)r)r0r/rrrr: szHeaders.removecCsj|dkr|jSt|tr(|j|Sz||}||Wn&tk rd|tk r^|YSYnX|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)rrBrrr:r|r )rr r\r)rrrrBs    z Headers.popcCs|S)z7Removes a key or index and returns a (key, value) item.rrrrrrb)szHeaders.popitemcCs.z|j|ddWntk r(YdSXdS)zCheck if a key is present.TrF)rr|r/rrr __contains__-s zHeaders.__contains__cCstjdtdd||kSz{ .. deprecated:: 2.0 Will be removed in Werkzeug 2.1. Use ``key in data`` instead. zW'has_key' is deprecated and will be removed in Werkzeug 2.1. Use 'key in data' instead. stacklevelwarningswarnDeprecationWarningr/rrrhas_key5s zHeaders.has_keycCs t|jS)zYield ``(key, value)`` tuples.)rrrrrrrCszHeaders.__iter__cCs t|jSr%)rrrrrr__len__GszHeaders.__len__cKs<|rt||}t|}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. .. versionadded:: 0.4.1 keyword arguments were added for :mod:`wsgiref` compatibility. N)rr_validate_valuerr9rr_valuertrrrriJs   z Headers.addcCs.t|tstdd|ks"d|kr*tddS)NzValue should be a string.  zGDetected newline in header value. This is a potential security problem)rrrr}rrrrras  zHeaders._validate_valuecKs|j||f|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)rirrrZ_kwrrr add_headerjszHeaders.add_headercCs|jdd=dS)zClears all headers.N)rrrrrrcrsz Headers.clearc s|rt||}t|}t|}|||jsB|j||fdSt|j}|t|D]*\}\}}|kr\||f|j|<qq\|j||fdSfdd|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|]}|dkr|qS)rr)rtrrrrszHeaders.set..r )rrrrr9rr enumerate)rrrrtlistiteridxZold_keyZ _old_valuerrrrvs"    z Headers.setcCsB|r4t|}||t||D]}|||q n ||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)rrrrir:)rr rZ values_iterr!rrrrns 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. rr[rrrr]s  zHeaders.setdefaultcCs||kr|||||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 )rnrr[rrrrps zHeaders.setlistdefaultcCszt|ttfrjt|tr|g}dd|D}|D]\}}||q0t|tr^|d|j|<qv||j|<n |||dS)z=Like :meth:`set` but also supports index/slice based setting.cSs g|]\}}t|t|fqSr)rrrrrrsz'Headers.__setitem__..rN)rrrrrr)rr r!rr"rrrr6s     zHeaders.__setitem__cOst|dkrtdt||r|d}t|ttfrZ|D]}||||q@n`t|tr| D]0\}}t|t t fr|||ql| ||qln|D]\}}| ||q| D]0\}}t|t t fr|||q| ||qdS)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 r rrN) rrrrrrSrnrrrrrr)rr_r`rr r!rrrras$    zHeaders.updatecCst|S)zRConvert the headers into a list suitable for WSGI. :return: list )rrrrr to_wsgi_listszHeaders.to_wsgi_listcCs ||jSr%)rVrrrrrr sz Headers.copycCs|Sr%rrrrrrszHeaders.__copy__cCs>g}|D]\}}||d|q |dd|S)z9Returns formatted headers suitable for HTTP transmission.: z )rr9join)rstrsr r!rrr__str__s  zHeaders.__str__cCst|jdt|dSrI)rrrrrrrrLszHeaders.__repr__)N)F)NNF)NF)F)F)T)'rrErFrGrPrrr*r~rrrrSrr<r0r:r rBrbrrrrrirrrcrrnr]rpr6rarrrrrLrrrrrJsF!   $     #&rc@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ defddZddZddZddZdS)ImmutableHeadersMixinzMakes a :class:`Headers` immutable. We do not mark them as hashable though since the only usecase for this datastructure in Werkzeug is a view on a mutable structure. .. versionadded:: 0.5 :private: cKs t|dSr%r.)rr r`rrrr0'sz!ImmutableHeadersMixin.__delitem__cCs t|dSr%r.r5rrrr6*sz!ImmutableHeadersMixin.__setitem__cKs t|dSr%r.rrrrr-szImmutableHeadersMixin.setcCs t|dSr%r.rrrrrn0szImmutableHeadersMixin.setlistcKs t|dSr%r.rrrrri3szImmutableHeadersMixin.addcKs t|dSr%r.rrrrr6sz ImmutableHeadersMixin.add_headercCs t|dSr%r.r/rrrr:9szImmutableHeadersMixin.removecOs t|dSr%r.r^rrrr<<szImmutableHeadersMixin.extendcOs t|dSr%r.r^rrrra?szImmutableHeadersMixin.updatecCs t|dSr%r.r=rrrr?BszImmutableHeadersMixin.insertNcCs t|dSr%r.r[rrrrBEszImmutableHeadersMixin.popcCs t|dSr%r.rrrrrbHszImmutableHeadersMixin.popitemcCs t|dSr%r.r[rrrr]Ksz ImmutableHeadersMixin.setdefaultcCs t|dSr%r.r[rrrrpNsz$ImmutableHeadersMixin.setlistdefault)rrErFrGr0r6rrnrirr:r<rar?r rBrbr]rprrrrrs rc@sFeZdZdZddZddZdZddd Zd d Zd d Z ddZ dS)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. cCs ||_dSr%environ)rrrrrrP]szEnvironHeaders.__init__cCs |j|jkSr%rr1rrrr`szEnvironHeaders.__eq__NFcCsLt|tst||dd}|dkr8t|j|St|jd|S)Nrr CONTENT_TYPECONTENT_LENGTHHTTP_)rrr|upperrrr)rr rrrrres  zEnvironHeaders.__getitem__cCsttt|Sr%)rrrrrrrroszEnvironHeaders.__len__ccst|jD]d\}}|drH|dkrH|ddddt|fVq |dkr |r |ddt|fVq dS)Nr)ZHTTP_CONTENT_TYPEZHTTP_CONTENT_LENGTHrrr)rr startswithrtitlerr5rrrrts zEnvironHeaders.__iter__cCstdt|jddS)Ncannot create z copiesrrrrrrszEnvironHeaders.copy)F) rrErFrGrPrr*rrrrrrrrrRs   rc@seZdZdZddZd+ddZed,ddZd d Zd-d d Z d.d dZ ddZ ddZ ddZ d/ddZddZddZddZddZd0d!d"Zd#d$Zd%d&Zd'd(Zd)d*ZdS)1CombinedMultiDicta>A read only :class:`MultiDict` that you can pass multiple :class:`MultiDict` instances as sequence and it will combine the return values of all wrapped dicts: >>> from werkzeug.datastructures import CombinedMultiDict, MultiDict >>> post = MultiDict([('foo', 'bar')]) >>> get = MultiDict([('blub', 'blah')]) >>> combined = CombinedMultiDict([get, post]) >>> combined['foo'] 'bar' >>> combined['blub'] 'blah' This works for all read operations and will raise a `TypeError` for methods that usually change data which isn't possible. 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. cCst||jffSr%)rdictsr+rrrr-szCombinedMultiDict.__reduce_ex__NcCst|p g|_dSr%)rr )rr rrrrPszCombinedMultiDict.__init__cCstd|jddS)Nr z instances by fromkeys)rr)rRrSr!rrrrWszCombinedMultiDict.fromkeyscCs.|jD]}||kr||Sqt|dSr%)r r rrr drrrrs zCombinedMultiDict.__getitem__c CsX|jD]L}||kr|dk rFz|||WStk rDYqYnX||Sq|Sr%)r r})rr r\rr rrrr~s  zCombinedMultiDict.getcCs&g}|jD]}||||q |Sr%)r r<r)rr rr)r rrrrs zCombinedMultiDict.getlistcCst}|j|j|S)zThis function exists so __len__ can be implemented more efficiently, saving one list creation from an iterator. )rrar r(rrr _keys_impls zCombinedMultiDict._keys_implcCs|Sr%)rrrrrrSszCombinedMultiDict.keyscCs t|Sr%rrrrrrszCombinedMultiDict.__iter__FccsVt}|jD]D}||D]4\}}|r2||fVq||kr||||fVqq dSr%)rr rri)rrfoundr r r!rrrrs   zCombinedMultiDict.itemsccs|D]\}}|VqdSr%rX)rrr!rrrrszCombinedMultiDict.valuescCs@i}|jD](}|D]\}}||g|qq t|Sr%)r rr]r<rr)rr)r r rrrrrs  zCombinedMultiDict.listscCsdd|DS)Ncss|]}|dVqdS)r Nrrrrrrsz/CombinedMultiDict.listvalues..rrrrrrszCombinedMultiDict.listvaluescCst|S)a0Return a shallow mutable copy of this object. This returns a :class:`MultiDict` representing the data at the time of copying. The copy will no longer reflect changes to the wrapped dicts. .. versionchanged:: 0.15 Return a mutable :class:`MultiDict`. rrrrrrs zCombinedMultiDict.copyTcCs(i}t|jD]}|||q|S)aReturn the contents as regular dict. If `flat` is `True` the returned dict will only have the first item present, if `flat` is `False` all values will be returned as lists. :param flat: If set to `False` the dict returned will have lists with all the values in it. Otherwise it will only contain the first item for each key. :return: a :class:`dict` )reversedr rar)rrr)r rrrrs zCombinedMultiDict.to_dictcCs t|Sr%)rrrrrrrszCombinedMultiDict.__len__cCs|jD]}||krdSqdSNTF)r r rrrrs zCombinedMultiDict.__contains__cCstjdtdd||kSrrr/rrrrs zCombinedMultiDict.has_keycCst|jd|jdSrI)rrr rrrrrLszCombinedMultiDict.__repr__)N)N)NN)N)F)T)rrErFrGr-rPrdrWrr~rrrSrrrrrrrrrrrLrrrrr s*     r c@seZdZdZdddZdS) FileMultiDictzA special :class:`MultiDict` that has convenience methods to add files to it. This is used for :class:`EnvironBuilder` and generally useful for unittesting. .. versionadded:: 0.5 NcCslt|tr|}nLt|tr0|dkr&|}t|d}|rN|dkrNt|dpLd}t||||}|||dS)aPAdds a new file to the dict. `file` can be a file name or a :class:`file`-like or a :class:`FileStorage` object. :param name: the name of the field. :param file: a filename or :class:`file`-like object :param filename: an optional filename :param content_type: an optional content type Nrbrzapplication/octet-stream)r FileStorageropen mimetypes guess_typeri)rrvfilefilename content_typer!rrradd_file!s    zFileMultiDict.add_file)NN)rrErFrGrrrrrrsrc@s(eZdZdZddZddZddZdS) ImmutableDictz;An immutable :class:`dict`. .. versionadded:: 0.5 cCst|jdt|dSrIrrrrLrrrrrL@szImmutableDict.__repr__cCst|Sr)rrrrrrCszImmutableDict.copycCs|Sr%rrrrrrJszImmutableDict.__copy__N)rrErFrGrLrrrrrrr:src@s eZdZdZddZddZdS)ImmutableMultiDictz@An immutable :class:`MultiDict`. .. versionadded:: 0.5 cCst|SrrrrrrrTszImmutableMultiDict.copycCs|Sr%rrrrrr[szImmutableMultiDict.__copy__NrrrrrrNsrc@s(eZdZdZddZddZddZdS) ImmutableOrderedMultiDictzGAn immutable :class:`OrderedMultiDict`. .. versionadded:: 0.6 cCst|jddSrg)rrrrrrrYesz)ImmutableOrderedMultiDict._iter_hashitemscCst|Sr)rrrrrrhszImmutableOrderedMultiDict.copycCs|Sr%rrrrrrosz"ImmutableOrderedMultiDict.__copy__N)rrErFrGrYrrrrrrr _sr c@seZdZdZd"ddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZd#ddZed d!ZdS)$AcceptaAn :class:`Accept` object is just a list subclass for lists of ``(value, quality)`` tuples. It is automatically sorted by specificity and quality. All :class:`Accept` objects work similar to a list but provide extra functionality for working with the data. Containment checks are normalized to the rules of that header: >>> a = CharsetAccept([('ISO-8859-1', 1), ('utf-8', 0.7)]) >>> a.best 'ISO-8859-1' >>> 'iso-8859-1' in a True >>> 'UTF8' in a True >>> 'utf7' in a False To get the quality for an item you can use normal item lookup: >>> print a['utf-8'] 0.7 >>> a['utf7'] 0 .. versionchanged:: 0.5 :class:`Accept` objects are forced immutable now. .. versionchanged:: 1.0.0 :class:`Accept` internal values are no longer ordered alphabetically for equal quality tags. Instead the initial order is preserved. rcsf|dkrtd_nHt|tr:|j_t|n(d_t|fdddd}t|dS)NFTcs|d|dfSr) _specificityrrrrz!Accept.__init__..)r rC)rrPprovidedrr!sortedrrrrrPs   zAccept.__init__cCs |dkfS)z3Returns a tuple describing the value's specificity.*rrrrrr"szAccept._specificitycCs|dkp||kS)z-Check if a value matches a given accept item.r(rrr!r8rrr_value_matchesszAccept._value_matchescCs t|tr||St||S)zBesides index lookup (getting item n) you can also pass it a string to get the quality for the item. If the item is not in the list, the returned quality is ``0``. )rrqualityrrr/rrrrs  zAccept.__getitem__cCs&|D]\}}|||r|SqdS)zReturns the quality of the key. .. versionadded:: 0.6 In previous versions you had to use the item-lookup syntax (eg: ``obj[key]`` instead of ``obj.quality(key)``) rr*)rr r8r+rrrr+s   zAccept.qualitycCs$|D]\}}|||rdSqdSrr,)rr!r8_qualityrrrrs  zAccept.__contains__cCs*ddd|D}t|jd|dS)N, css$|]\}}d|d|dVqdS)rJr.rKNr)rryrrrrsz"Accept.__repr__..z([z]))rrr)rZ pairs_strrrrrLszAccept.__repr__cCsHt|trc@sDeZdZdZddZddZeddZedd Zed d Z d S) MIMEAcceptzRLike :class:`Accept` but with special methods and behavior for mimetypes. cCstddt|DS)Ncss|]}|dkVqdS)r(Nrrrrrr,sz*MIMEAccept._specificity..)rr<r=rrrrr"+szMIMEAccept._specificityc Csd|kr dSd|kr"td|t|}|dd\}}t|dd}|dkrh|dkrhtd|t|}|dd\}} t|dd} |dkr| dkrdS|dkr| dkp|dkr|dkp||ko| dkp|dkp| |ko| |kS)N/Fzinvalid mimetype rr()r}r>r') rr!r8Znormalized_valueZ value_typeZ value_subtypeZ value_paramsnormalized_itemZ item_typeZ item_subtypeZ item_paramsrrrr*.s.zMIMEAccept._value_matchescCsd|kpd|kp|jS)z!True if this object accepts HTML.z text/htmlapplication/xhtml+xml) accept_xhtmlrrrr accept_htmlVszMIMEAccept.accept_htmlcCsd|kpd|kS)z"True if this object accepts XHTML.rBzapplication/xmlrrrrrrC]szMIMEAccept.accept_xhtmlcCsd|kS)z!True if this object accepts JSON.zapplication/jsonrrrrr accept_jsonbszMIMEAccept.accept_jsonN) rrErFrGr"r*r;rDrCrErrrrr?&s(  r?z[_-]cCst|S)z$Process a language tag for matching.)_locale_delim_rer=rrrrr_normalize_langksrGcs*eZdZdZddZdfdd ZZS)LanguageAcceptz>Like :class:`Accept` but with normalization for language tags.cCs|dkpt|t|kS)Nr()rGr)rrrr*sszLanguageAccept._value_matchesNcs|t|dk rStdd|D}||dk r@Sdd|D}t|dk rxtfdd|DS|S)aGiven a list of supported values, finds the best match from the list of accepted values. Language tags are normalized for the purpose of matching, but are returned unchanged. If no exact match is found, this will fall back to matching the first subtag (primary language only), first with the accepted values then with the match values. This partial is not applied to any other language subtags. The default is returned if no exact or fallback match is found. :param matches: A list of supported languages to find a match. :param default: The value that is returned if none match. NcSs(g|] }t|ddd|dfqS)rr rFr=rr8rrrrsz-LanguageAccept.best_match..cSsg|]}t|ddqS)r rrIrJrrrrsc3s|]}|r|VqdSr%)rrJrrrrs z,LanguageAccept.best_match..)rNr9r!r)rr8r\fallbackZfallback_matchesrUrKrr9vs    zLanguageAccept.best_match)N)rrErFrGr*r9rerrrUrrHpsrHc@seZdZdZddZdS) CharsetAcceptz9Like :class:`Accept` but with normalization for charsets.cCs dd}|dkp||||kS)NcSs0zt|jWStk r*|YSXdSr%)codecslookuprv LookupErrorrrurrr _normalizesz0CharsetAccept._value_matches.._normalizer(r)rr!r8rQrrrr*szCharsetAccept._value_matchesN)rrErFrGr*rrrrrMsrMcs2tfddfddfdddS)zReturn a new property object for a cache header. Useful if you want to add support for a cache extension in a subclass. .. versionchanged:: 2.0 Renamed from ``cache_property``. cs|Sr%)_get_cache_valuer#emptyr rrrr$r%z(cache_control_property..cs||Sr%)_set_cache_valuerr")r rrrr$r%cs |Sr%)_del_cache_valuer#r rrr$r% accessor for r;r rTrrrSrcache_control_propertys   r\cCstjdtddt|||S)Nzx'cache_property' is renamed to 'cache_control_property'. The old name is deprecated and will be removed in Werkzeug 2.1.rr)rrrr\r[rrrcache_propertys r]c@seZdZdZedddZeddeZeddeZ edddZ dd d Z d d Z ddZ ddZddZddZddZeeZdS) _CacheControlaVSubclass of a dict that stores values for a Cache-Control header. It has accessors for all the cache-control directives specified in RFC 2616. The class does not differentiate between request and response directives. Because the cache-control directives in the HTTP header use dashes the python descriptors use underscores for that. To get a header of the :class:`CacheControl` object again you can convert the object into a string or call the :meth:`to_header` method. If you plan to subclass it and add your own items have a look at the sourcecode for that class. .. versionchanged:: 0.4 Setting `no_cache` or `private` to boolean `True` will set the implicit none-value which is ``*``: >>> cc = ResponseCacheControl() >>> cc.no_cache = True >>> cc >>> cc.no_cache '*' >>> cc.no_cache = None >>> cc In versions before 0.5 the behavior documented here affected the now no longer existing `CacheControl` class. zno-cacher(Nzno-storezmax-ager@z no-transformrcCs$t||p d||_|dk |_dSNrrrPrsr&rrrsrrrrPsz_CacheControl.__init__cCs^|tkr||kS||krZ||}|dkr,|S|dk rVz ||}Wntk rTYnX|SdS+Used internally by the accessor properties.N)boolr})rr rTrr!rrrrRs z_CacheControl._get_cache_valuecCsX|tkr$|rd||<qT||dn0|dkr:||dn|dkrLd||<n|||<dS)rcNT)rdrB)rr r!rrrrrUs  z_CacheControl._set_cache_valuecCs||kr||=dSrbrr/rrrrWsz_CacheControl._del_cache_valuecCs t|Sz6Convert the stored values into a cache control header.)r dump_headerrrrrr3sz_CacheControl.to_headercCs|Sr%r4rrrrrsz_CacheControl.__str__cCs4dddt|D}dt|jd|dS)N css |]\}}|d|VqdS=Nrrrrrr"sz)_CacheControl.__repr__..<>rr'rrrrZkv_strrrrrL!sz_CacheControl.__repr__)rN)rrErFrGr\no_cacherdno_storerZmax_ageZ no_transformrPrRrUrWr3rrL staticmethodr]rrrrr^s     r^c@s4eZdZdZeddeZeddeZeddeZ dS)RequestCacheControla A cache control for requests. This is immutable and gives access to all the request-relevant cache control headers. To get a header of the :class:`RequestCacheControl` object again you can convert the object into a string or call the :meth:`to_header` method. If you plan to subclass it and add your own items have a look at the sourcecode for that class. .. versionadded:: 0.5 In previous versions a `CacheControl` class existed that was used both for request and response. z max-staler(z min-freshzonly-if-cachedN) rrErFrGr\rZ max_stale min_freshrdZonly_if_cachedrrrrrq(s  rqc@sXeZdZdZeddeZedddZeddeZeddeZ edddZ ed deZ dS) ResponseCacheControla*A cache control for responses. Unlike :class:`RequestCacheControl` this is mutable and gives access to response-relevant cache control headers. To get a header of the :class:`ResponseCacheControl` object again you can convert the object into a string or call the :meth:`to_header` method. If you plan to subclass it and add your own items have a look at the sourcecode for that class. .. versionadded:: 0.5 In previous versions a `CacheControl` class existed that was used both for request and response. publicNprivater(zmust-revalidatezproxy-revalidatezs-maxage immutable) rrErFrGr\rdrtruZmust_revalidateZproxy_revalidateZs_maxagervrrrrrs;s     rscs,tfddfddfdddS)zReturn a new property object for a content security policy header. Useful if you want to add support for a csp extension in a subclass. cs |Sr%) _get_valuer#rXrrr$Xr%zcsp_property..cs ||Sr%) _set_valuerVrXrrr$Yr%cs |Sr%) _del_valuer#rXrrr$Zr%rYrZrXrrXr csp_propertyRs    rzc@seZdZdZedZedZedZedZedZ edZ edZ ed Z ed Z ed Zed Zed ZedZedZedZedZedZedZedZedZedZedZedZedZedZd+ddZdd Zd!d"Z d#d$Z!d%d&Z"d'd(Z#d)d*Z$dS),ContentSecurityPolicyaVSubclass of a dict that stores values for a Content Security Policy header. It has accessors for all the level 3 policies. Because the csp directives in the HTTP header use dashes the python descriptors use underscores for that. To get a header of the :class:`ContentSecuirtyPolicy` object again you can convert the object into a string or call the :meth:`to_header` method. If you plan to subclass it and add your own items have a look at the sourcecode for that class. .. versionadded:: 1.0.0 Support for Content Security Policy headers was added. zbase-uriz child-srcz connect-srcz default-srczfont-srcz form-actionzframe-ancestorsz frame-srczimg-srcz manifest-srcz media-srcz navigate-toz object-srcz prefetch-srcz plugin-typesz report-toz report-urisandboxz script-srczscript-src-attrzscript-src-elemz style-srczstyle-src-attrzstyle-src-elemz worker-srcrNcCs$t||p d||_|dk |_dSr_r`rarrrrPszContentSecurityPolicy.__init__cCs ||S)rcr~r/rrrrwsz ContentSecurityPolicy._get_valuecCs"|dkr||dn|||<dSrbrr5rrrrxsz ContentSecurityPolicy._set_valuecCs||kr||=dSrbrr/rrrrysz ContentSecurityPolicy._del_valuecCs t|Sre)rZdump_csp_headerrrrrr3szContentSecurityPolicy.to_headercCs|Sr%r4rrrrrszContentSecurityPolicy.__str__cCs4dddt|D}dt|jd|dS)Nrgcss |]\}}|d|VqdSrhrrrrrrsz1ContentSecurityPolicy.__repr__..rjrkrlrmrrrrLszContentSecurityPolicy.__repr__)rN)%rrErFrGrzZbase_uriZ child_srcZ connect_srcZ default_srcZfont_srcZ form_actionZframe_ancestorsZ frame_srcZimg_srcZ manifest_srcZ media_srcZ navigate_toZ object_srcZ prefetch_srcZ plugin_typesZ report_toZ report_urir|Z script_srcZscript_src_attrZscript_src_elemZ style_srcZstyle_src_attrZstyle_src_elemZ worker_srcrPrwrxryr3rrLrrrrr{_sB r{c@s"eZdZdZdddZddZdS) CallbackDictzwA dict that calls a function passed every time something is changed. The function is passed the dict instance. NcCst||p d||_dSr_rrPrs)rinitialrsrrrrPszCallbackDict.__init__cCsdt|jdt|dSNrjrgrkrrrrrrLszCallbackDict.__repr__)NN)rrErFrGrPrLrrrrr~s r~c@seZdZdZd*ddZddZddZd d Zd d Zd dZ ddZ ddZ d+ddZ ddZ ddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)ZdS), HeaderSetaSimilar to the :class:`ETags` class this implements a set-like structure. Unlike :class:`ETags` this is case insensitive and used for vary, allow, and content-language headers. If not constructed using the :func:`parse_set_header` function the instantiation works like this: >>> hs = HeaderSet(['foo', 'bar', 'baz']) >>> hs HeaderSet(['foo', 'bar', 'baz']) NcCs*t|pd|_dd|jD|_||_dS)NrcSsh|] }|qSrrrrrr sz%HeaderSet.__init__..)r_headers_setrs)rheadersrsrrrrPszHeaderSet.__init__cCs||fdS)zAdd a new header to the set.N)rarheaderrrrrisz HeaderSet.addcCsj|}||jkrt||j|t|jD] \}}||kr0|j|=qRq0|jdk rf||dS)aCRemove a header from the set. This raises an :exc:`KeyError` if the header is not in the set. .. versionchanged:: 0.5 In older versions a :exc:`IndexError` was raised instead of a :exc:`KeyError` if the object was missing. :param header: the header to be removed. N)rrr|r:rrrs)rrr rrrrr:s     zHeaderSet.removecCsXd}|D]2}|}||jkr|j||j|d}q|rT|jdk rT||dS)zAdd all the headers from the iterable to the set. :param iterable: updates the set with the items from the iterable. FTN)rrrr9rirs)rr;Z inserted_anyrr rrrras   zHeaderSet.updatecCs(z||Wntk r"YnXdS)zdLike :meth:`remove` but ignores errors. :param header: the header to be discarded. N)r:r|rrrrdiscardszHeaderSet.discardcCs4|}t|jD]\}}||kr|SqdS)zReturn the index of the header in the set or return -1 if not found. :param header: the header to be looked up. r@)rrr)rrrr8rrrr0s   zHeaderSet.findcCs||}|dkrt||S)zReturn the index of the header in the set or raise an :exc:`IndexError`. :param header: the header to be looked up. r)r0 IndexError)rrr)rrrrA s zHeaderSet.indexcCs.|j|jdd=|jdk r*||dS)zClear the set.N)rrcrrsrrrrrc s   zHeaderSet.clearFcCs|rt|jSt|jS)aReturn the set as real python set type. When calling this, all the items are converted to lowercase and the ordering is lost. :param preserve_casing: if set to `True` the items in the set returned will have the original case like in the :class:`HeaderSet`, otherwise they will be lowercase. )rrr)rZpreserve_casingrrras_set s  zHeaderSet.as_setcCsdttj|jS)r1r.)rrrquote_header_valuerrrrrr3& szHeaderSet.to_headercCs |j|Sr%)r)rrrrrr* szHeaderSet.__getitem__cCs4|j|}|j||jdk r0||dSr%)rrBrr:rrs)rrr)rrrr0- s  zHeaderSet.__delitem__cCsL|j|}|j|||j|<|j||jdk rH||dSr%)rrr:rrirs)rrr!oldrrrr63 s    zHeaderSet.__setitem__cCs||jkSr%)rrrrrrr; szHeaderSet.__contains__cCs t|jSr%)rrrrrrr> szHeaderSet.__len__cCs t|jSr%)rrrrrrrA szHeaderSet.__iter__cCs t|jSr%)rdrrrrr__bool__D szHeaderSet.__bool__cCs|Sr%r4rrrrrG szHeaderSet.__str__cCst|jd|jdSrI)rrrrrrrrLJ szHeaderSet.__repr__)NN)F)rrErFrGrPrir:rarr0rArcrr3rr0r6rrrrrrLrrrrrs(     rc@seZdZdZd"ddZd#ddZdd Zd d Zd d ZddZ ddZ ddZ d$ddZ ddZ ddZddZddZddZd d!ZdS)%ETagszYA set that can be used to check if one etag is present in a collection of etags. NFcCs4|s|rt||_nt|_t|p$d|_||_dSr_)rZ_strong_weakstar_tag)rZ strong_etagsZ weak_etagsrrrrrPS s  zETags.__init__cCst|j}|r||j|S)zoConvert the `ETags` object into a python set. Per default all the weak etags are not part of this set.)rrrar)r include_weakr)rrrr\ s  z ETags.as_setcCs ||jkS)zCheck if an etag is weak.)rretagrrris_weakd sz ETags.is_weakcCs ||jkS)zCheck if an etag is strong.)rrrrr is_strongh szETags.is_strongcCs||p||S)zCCheck if an etag is part of the set including weak and strong tags.)rcontainsrrrr contains_weakl szETags.contains_weakcCs|jr dS||S)zxCheck if an etag is part of the set ignoring weak tags. It is also possible to use the ``in`` operator. T)rrrrrrrp szETags.containscCs&t|\}}|r||S||S)zWhen passed a quoted tag it will check if this tag is part of the set. If the tag is weak it is checked against weak and strong tags, otherwise strong only.)rZ unquote_etagrr)rrZweakrrr contains_rawx s zETags.contains_rawcCs0|jr dSddd|jDdd|jDS)z0Convert the etags set into a HTTP header string.r(r.cSsg|]}d|dqS)"rrrrrr sz#ETags.to_header..cSsg|]}d|dqS)zW/"rrrrrrr s)rrrrrrrrr3 s zETags.to_headercCsH||gddkrtd|dkr,t|}|r>||jkr>dS||jkS)Nr z-either tag or data required, but at least oneT)countrrZ generate_etagrr)rrdatarrrr__call__ s  zETags.__call__cCst|jp|jp|jSr%)rdrrrrrrrr szETags.__bool__cCs|Sr%r4rrrrr sz ETags.__str__cCs t|jSr%)rrrrrrr sz ETags.__len__cCs t|jSr%)rrrrrrr szETags.__iter__cCs ||Sr%)rrrrrr szETags.__contains__cCsdt|jdt|dSrrrrrrrrrL szETags.__repr__)NNF)F)NNF)rrErFrGrPrrrrrrr3rrrrrrrLrrrrrN s    rc@s2eZdZdZd ddZddZddZd d ZdS) IfRangezVery simple object that represents the `If-Range` header in parsed form. It will either have neither a etag or date or one of either but never both. .. versionadded:: 0.7 NcCs||_||_dSr%)rdate)rrrrrrrP szIfRange.__init__cCs0|jdk rt|jS|jdk r,t|jSdS)-Converts the object back into an HTTP header.N)rrZ http_daterZ quote_etagrrrrr3 s     zIfRange.to_headercCs|Sr%r4rrrrr szIfRange.__str__cCsdt|jdt|dSrrrrrrrL szIfRange.__repr__)NN)rrErFrGrPr3rrLrrrrr s  rc@sHeZdZdZddZddZddZdd Zd d Zd d Z ddZ dS)RangeaXRepresents a ``Range`` header. All methods only support only bytes as the unit. Stores a list of ranges if given, but the methods only work if only one range is provided. :raise ValueError: If the ranges provided are invalid. .. versionchanged:: 0.15 The ranges passed in are validated. .. versionadded:: 0.7 cCsP||_||_|D]:\}}|dks8|dk r|dks8||krt||fdqdS)Nrz is not a valid range.)unitsrangesr})rrrstartendrrrrP s   zRange.__init__cCsn|jdks |dks t|jdkr$dS|jd\}}|dkrN|}|dkrN||7}t|||rj|t||fSdS)zIf the range is for bytes, the length is not None and there is exactly one range and it is satisfiable it returns a ``(start, stop)`` tuple, otherwise `None`. rNr r)rrrris_byte_range_validmin)rlengthrrrrrrange_for_length s zRange.range_for_lengthcCs.||}|dk r*t|j|d|d|SdS)zCreates a :class:`~werkzeug.datastructures.ContentRange` object from the current range and given content length. Nrr )r ContentRanger)rrrngrrrmake_content_range s zRange.make_content_rangecCslg}|jD]J\}}|dkr<||dkr0|dnt|q ||d|dq |jdd|S)rNrrr rir2)rr9rrr)rrbeginrrrrr3 s "zRange.to_headercCs>||}|dk r:|jd|dd|ddd|SdS)z\Converts the object into `Content-Range` HTTP header, based on given length Nrgrrr r@)rr)rrrangerrrto_content_range_header s (zRange.to_content_range_headercCs|Sr%r4rrrrr sz Range.__str__cCsdt|jdt|dSrrrrrrrL szRange.__repr__N) rrErFrGrPrrr3rrrLrrrrr s     rcs"fdd}fdd}t||S)Ncs t|Sr%)rqrrurrfget sz _callback_property..fgetcs$t|||jdk r ||dSr%)setattrrsrrurrfset s  z _callback_property..fsetrZ)rvrrrrur_callback_property s  rc@sleZdZdZdddZedZedZedZedZ dd d Z d d Z ddZ ddZ ddZddZdS)rzDRepresents the content range header. .. versionadded:: 0.7 NcCs0t|||std||_|||||dS)NBad range provided)rrAssertionErrorrsr)rrrstoprrsrrrrP! szContentRange.__init___units_start_stop_lengthrcCsFt|||std||_||_||_||_|jdk rB||dS)z#Simple method to update the ranges.rN)rrrrrrrrs)rrrrrrrrr0 s zContentRange.setcCs|jdddddS)zcSets the units to `None` which indicates that the header should no longer be used. Nrrrrrrunset: szContentRange.unsetcCsb|jdkrdS|jdkrd}n|j}|jdkr>|jd|S|jd|jd|jdd|S)Nrr(z */rgrr r@)rrrr)rrrrrr3@ s   zContentRange.to_headercCs |jdk Sr%rrrrrrK szContentRange.__bool__cCs|Sr%r4rrrrrN szContentRange.__str__cCsdt|jdt|dSrrrrrrrLQ szContentRange.__repr__)NN)Nr)rrErFrGrPrrrrrrrr3rrrLrrrrr s   rc@seZdZdZdddZeddZeddZed d Zed d Z ed dZ eddZ eddZ eddZ eddZeddZddZdS) Authorizationa=Represents an ``Authorization`` header sent by the client. This is returned by :func:`~werkzeug.http.parse_authorization_header`. It can be useful to create the object manually to pass to the test :class:`~werkzeug.test.Client`. .. versionchanged:: 0.5 This object became immutable. NcCst||p i||_dSr%)rrPr)r auth_typerrrrrPa szAuthorization.__init__cCs |dS)zdThe username transmitted. This is set for both basic and digest auth all the time. usernamer}rrrrre szAuthorization.usernamecCs |dS)zsWhen the authentication type is basic this is the password transmitted by the client, else `None`. passwordr}rrrrrl szAuthorization.passwordcCs |dS)z8This is the server realm sent back for HTTP digest auth.realmr}rrrrrs szAuthorization.realmcCs |dS)zThe nonce the server sent for digest auth, sent back by the client. A nonce should be unique for every 401 response for HTTP digest auth. noncer}rrrrrx szAuthorization.noncecCs |dS)zThe URI from Request-URI of the Request-Line; duplicated because proxies are allowed to change the Request-Line in transit. HTTP digest auth only. urir}rrrrr szAuthorization.uricCs |dS)zzThe nonce count value transmitted by clients if a qop-header is also transmitted. HTTP digest auth only. ncr}rrrrr szAuthorization.nccCs |dS)zIf the server sent a qop-header in the ``WWW-Authenticate`` header, the client has to provide this value for HTTP digest auth. See the RFC for more details. cnoncer}rrrrr szAuthorization.cnoncecCs |dS)zA string of 32 hex digits computed as defined in RFC 2617, which proves that the user knows a password. Digest auth only. responser}rrrrr szAuthorization.responsecCs |dS)zThe opaque header from the server returned unchanged by the client. It is recommended that this string be base64 or hexadecimal data. Digest auth only. opaquer}rrrrr szAuthorization.opaquecCs |dS)zIndicates what "quality of protection" the client has applied to the message for HTTP digest auth. Note that this is a single token, not a quoted list of alternatives as in WWW-Authenticate. qopr}rrrrr szAuthorization.qopcCsh|jdkr8t|jd|jdd}d|S|jdkrRdt|St d|jdd S) zConvert to a string value for an ``Authorization`` header. .. versionadded:: 2.0 Added to support passing authorization to the test client. basic:utf8zBasic digestzDigest zUnsupported type .N) rbase64 b64encoderrrrrrfr}rrrrr3 s   zAuthorization.to_header)N)rrErFrGrPr;rrrrrrrrrrr3rrrrrU s.           rcs"fdd}tfdd||dS)alA static helper function for Authentication subclasses to add extra authentication system properties onto a class:: class FooAuthenticate(WWWAuthenticate): special_realm = auth_property('special_realm') For more information have a look at the sourcecode to see how the regular properties (:attr:`realm` etc.) are implemented. cs&|dkr|dn t||<dSr%)rBrrrurrrx sz!auth_property.._set_valuecs |Sr%r}r#rurrr$ r%zauth_property..docrZ)rvrrxrrur auth_property s rcsfdd}t||dS)Ncs fdd}t|S)Ncs(|skr=n|r$|<dSr%r4)Z header_set)rvrrrrs s z._set_property..fget..on_update)rZparse_set_headerr~)rrsrurrr sz_set_property..fgetrrZ)rvrrrrur _set_property s rc@seZdZdZedddddgZd$dd Zd%d d Zd&ddZddZ ddZ ddZ e dddZ e dddZedddZe dddZe dddZe dddZedd dZed!d"Zejd#d"Zee Z dS)'WWWAuthenticatez5Provides simple access to `WWW-Authenticate` headers.domainrrrrNcCs&t||p d|r||d<||_dS)Nr __auth_type__r)rrrrsrrrrP szWWWAuthenticate.__init__authentication requiredcCs0t|t|d|d|jr,||dS)z*Clear the auth info and enable basic auth.r)rrN)rrcrars)rrrrr set_basic s zWWWAuthenticate.set_basicauthFcCsjd||t|d}|r d|d<|dk r0||d<|dk r@||d<t|t|||jrf||dS)z+Clear the auth info and enable digest auth.r)rrrrTRUEstaleNr algorithm)rrfrrcrars)rrrrrrrr rrr set_digest s  zWWWAuthenticate.set_digestcsTt}|ddpd}fdd|D}ddd|D}|d |S) z9Convert the stored values into a WWW-Authenticate header.rNrc3s*|]"\}}|tj||jkdfVqdS))Z allow_tokenN)rr_require_quotingrrrrr sz,WWWAuthenticate.to_header..r.cSsg|]\}}|d|qS)rirrrrrr sz-WWWAuthenticate.to_header..rg)rrBrrr)rr rZkv_itemsZ kv_stringrrrr3 s zWWWAuthenticate.to_headercCs|Sr%r4rrrrr szWWWAuthenticate.__str__cCsdt|jd|dSr)rrr3rrrrrL szWWWAuthenticate.__repr__rzZThe type of the auth mechanism. HTTP currently specifies ``Basic`` and ``Digest``.raA string to be displayed to users so they know which username and password to use. This string should contain at least the name of the host performing the authentication and might additionally indicate the collection of users who might have access.zA list of URIs that define the protection space. If a URI is an absolute path, it is relative to the canonical root URL of the server being accessed.z A server-specified data string which should be uniquely generated each time a 401 response is made. It is recommended that this string be base64 or hexadecimal data.aA string of data, specified by the server, which should be returned by the client unchanged in the Authorization header of subsequent requests with URIs in the same protection space. It is recommended that this string be base64 or hexadecimal data.ra A string indicating a pair of algorithms used to produce the digest and a checksum. If this is not present it is assumed to be "MD5". If the algorithm is not understood, the challenge should be ignored (and a different one used, if there is more than one).zIA set of quality-of-privacy directives such as auth and auth-int.cCs"|d}|dk r|dkSdS)z}A flag, indicating that the previous request from the client was rejected because the nonce value was stale. rNtrue)r~r)rvalrrrrI s zWWWAuthenticate.stalecCs*|dkr|ddn|rdnd|d<dS)NrrFALSErrrrrrR s)NNN)r)rNNF)rrErFrGrZrrPrrr3rrLrrrrrrrrrr;rsetterrprrrrr sZ      rc@seZdZdZdddZddZeddZed d Zed d Z ed dZ dddZ ddZ ddZ ddZddZddZdS)ra@The :class:`FileStorage` class is a thin wrapper over incoming files. It is used by the request object to represent uploaded files. All the attributes of the wrapper stream are proxied by the file storage so it's possible to do ``storage.read()`` instead of the long form ``storage.stream.read()``. NcCs||_|pt|_|dkrnt|dd}t|}|rV|d|dkrV|d|dkrVd}t|trn|td}||_ |dkrt }||_ |dk r||d<|dk rt ||d<dS) Nrvrrjr@rkrz Content-TypezContent-Length) rvrstreamrqr rrrr rrrr)rrrrvrcontent_lengthrsrrrrPd s"   $ zFileStorage.__init__cCst|dst|j|_dS)N_parsed_content_type)hasattrrZparse_options_headerrrrrrr_parse_content_type s zFileStorage._parse_content_typecCs |jdS)z;The content-type sent in the header. Usually not availablez content-type)rr~rrrrr szFileStorage.content_typecCst|jdpdS)z=The content-length sent in the header. Usually not availablezcontent-lengthr)rrr~rrrrr szFileStorage.content_lengthcCs||jdS)aLike :attr:`content_type`, but without parameters (eg, without charset, type etc.) and always lowercase. For example if the content type is ``text/HTML; charset=utf-8`` the mimetype would be ``'text/html'``. .. versionadded:: 0.7 r)rrrrrrrmimetype s zFileStorage.mimetypecCs||jdS)zThe mimetype parameters as dict. For example if the content type is ``text/html; charset=utf-8`` the params would be ``{'charset': 'utf-8'}``. .. versionadded:: 0.7 r )rrrrrrmimetype_params szFileStorage.mimetype_params@cCs`ddlm}d}t|dr"t|}t|tr:t|d}d}z||j||W5|rZ|XdS)anSave the file to a destination path or file object. If the destination is a file object you have to close it yourself after the call. The buffer size is the number of bytes held in memory during the copy process. It defaults to 16KB. For secure file saving also have a look at :func:`secure_filename`. :param dst: a filename, :class:`os.PathLike`, or open file object to write to. :param buffer_size: Passed as the ``length`` parameter of :func:`shutil.copyfileobj`. .. versionchanged:: 1.0 Supports :mod:`pathlib`. r) copyfileobjF __fspath__wbTN) shutilrrrrrrcloser)rdst buffer_sizerZ close_dstrrrsave s    zFileStorage.savecCs(z|jWntk r"YnXdS)z&Close the underlying file if possible.N)rr Exceptionrrrrr szFileStorage.closecCs t|jSr%)rdrrrrrr szFileStorage.__bool__cCsHzt|j|WStk rBt|jdr)rrrrrrrrrL szFileStorage.__repr__)NNNNNN)r)rrErFrGrPrr;rrrrrrrrrrLrrrrr\ s.  $    ! r)r)N)N)MrrNrrercollections.abcrrrrior itertoolsrosrrr _internalr r filesystemr rr#r$rrHrMrfrxrrrr{rrrrrrrrrr rrrr r!compiler<r>r?rFrGrHrMr\r]r^rqrsrzr{r~rrrrrrrrrrrrrrrrs          5 2 ")M /V53!- B 6  \ L XK :j  |