/usr/local/lib/python3.6/site-packages/werkzeug/__pycache__
NameSizeModeActions
datastructures.cpython-36.pyc1077480644editdlrm
exceptions.cpython-36.pyc306390644editdlrm
filesystem.cpython-36.pyc20250644editdlrm
formparser.cpython-36.pyc138140644editdlrm
http.cpython-36.pyc379050644editdlrm
local.cpython-36.pyc226910644editdlrm
routing.cpython-36.pyc729310644editdlrm
security.cpython-36.pyc80400644editdlrm
serving.cpython-36.pyc304780644editdlrm
test.cpython-36.pyc389610644editdlrm
testapp.cpython-36.pyc95490644editdlrm
urls.cpython-36.pyc364140644editdlrm
useragents.cpython-36.pyc74170644editdlrm
user_agent.cpython-36.pyc17200644editdlrm
utils.cpython-36.pyc329600644editdlrm
wsgi.cpython-36.pyc301020644editdlrm
_internal.cpython-36.pyc182680644editdlrm
_reloader.cpython-36.pyc118990644editdlrm
__init__.cpython-36.pyc3100644editdlrm
Edit: /usr/local/lib/python3.6/site-packages/werkzeug/__pycache__/datastructures.cpython-36.pyc (107748B)
3 _TBg~@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@dAdAe0Z4ej1dBZ5dCdDZ6GdEdFdFe0Z7GdGdHdHe0Z8dIdJZ9dKdLZ:GdMdNdNe eZ;GdOdPdPee;ZGdUdVdVe eZ?GdWdXdXe eZ@GdYdZdZeZAGd[d\d\eZBGd]d^d^ZCGd_d`d`ZDdadbZEGdcddddZFGdedfdfeeZGdpdgdhZHdqdidjZIGdkdldle eZJGdmdndnZKddolmLZLdS)rN) Collection) MutableSet)deepcopy)BytesIO)repeat)fspath) exceptions)_make_encode_wrapper)_missing)get_filesystem_encodingcCstt|jddS)Nz objects are immutable) TypeErrortype__name__)selfr;/tmp/pip-build-0s3hx122/Werkzeug/werkzeug/datastructures.py is_immutablesrccst|tr|jddEdHn^t|trrxR|jD]:\}}t|ttfrbx"|D]}||fVqNWq2||fVq2Wn |EdHdS)zyIterates over the items of a mapping yielding keys and values without dropping any from more complex structures. T)multiN) isinstance MultiDictitemsdicttuplelist)mappingkeyvaluevrrriter_multi_itemss   rc@seZdZdZdZddZddZddZd d Zd d Z d dZ ddZ ddZ ddZ ddZd ddZddZd!ddZdS)"ImmutableListMixinzOMakes a :class:`list` immutable. .. versionadded:: 0.5 :private: NcCs&|jdk r|jStt|}|_|S)N) _hash_cachehashr)rrvrrr__hash__2s zImmutableListMixin.__hash__cCst|t|ffS)N)rr)rprotocolrrr __reduce_ex__8sz ImmutableListMixin.__reduce_ex__cCs t|dS)N)r)rrrrr __delitem__;szImmutableListMixin.__delitem__cCs t|dS)N)r)rotherrrr__iadd__>szImmutableListMixin.__iadd__cCs t|dS)N)r)rr(rrr__imul__AszImmutableListMixin.__imul__cCs t|dS)N)r)rrrrrr __setitem__DszImmutableListMixin.__setitem__cCs t|dS)N)r)ritemrrrappendGszImmutableListMixin.appendcCs t|dS)N)r)rr,rrrremoveJszImmutableListMixin.removecCs t|dS)N)r)riterablerrrextendMszImmutableListMixin.extendcCs t|dS)N)r)rposrrrrinsertPszImmutableListMixin.insertrcCs t|dS)N)r)rindexrrrpopSszImmutableListMixin.popcCs t|dS)N)r)rrrrreverseVszImmutableListMixin.reverseFcCs t|dS)N)r)rrr5rrrsortYszImmutableListMixin.sort)r7)NF)r __module__ __qualname____doc__r!r$r&r'r)r*r+r-r.r0r2r4r5r6rrrrr (s r c@seZdZdZddZdS) ImmutableListzJAn immutable :class:`list`. .. versionadded:: 0.5 :private: cCst|jdtj|dS)N())rrr__repr__)rrrrr>eszImmutableList.__repr__N)rr8r9r:r>rrrrr;]sr;cs~eZdZdZdZedfdd ZddZddZd d Z dd d Z d dZ dddZ ddZ ddZddZddZZS)ImmutableDictMixinzOMakes a :class:`dict` immutable. .. versionadded:: 0.5 :private: Ncs$tj|}|jt|t||S)N)super__new____init__zipr)clskeysrinstance) __class__rrfromkeysss zImmutableDictMixin.fromkeyscCst|t|ffS)N)rr)rr%rrrr&ysz ImmutableDictMixin.__reduce_ex__cCs|jS)N)r)rrrr_iter_hashitems|sz"ImmutableDictMixin._iter_hashitemscCs*|jdk r|jStt|j}|_|S)N)r!r" frozensetrI)rr#rrrr$s zImmutableDictMixin.__hash__cCs t|dS)N)r)rrdefaultrrr setdefaultszImmutableDictMixin.setdefaultcOs t|dS)N)r)rargskwargsrrrupdateszImmutableDictMixin.updatecCs t|dS)N)r)rrrKrrrr4szImmutableDictMixin.popcCs t|dS)N)r)rrrrpopitemszImmutableDictMixin.popitemcCs t|dS)N)r)rrrrrrr+szImmutableDictMixin.__setitem__cCs t|dS)N)r)rrrrrr'szImmutableDictMixin.__delitem__cCs t|dS)N)r)rrrrclearszImmutableDictMixin.clear)N)N)N)rr8r9r:r! classmethodrHr&rIr$rLrOr4rPr+r'rQ __classcell__rr)rGrr?is  r?c@sJeZdZdZddZddZddZdd Zd d Zd d Z dddZ dS)ImmutableMultiDictMixinzTMakes a :class:`MultiDict` immutable. .. versionadded:: 0.5 :private: cCst|t|jddffS)NT)r)rrr)rr%rrrr&sz%ImmutableMultiDictMixin.__reduce_ex__cCs |jddS)NT)r)r)rrrrrIsz'ImmutableMultiDictMixin._iter_hashitemscCs t|dS)N)r)rrrrrraddszImmutableMultiDictMixin.addcCs t|dS)N)r)rrrr popitemlistsz#ImmutableMultiDictMixin.popitemlistcCs t|dS)N)r)rrrrrpoplistszImmutableMultiDictMixin.poplistcCs t|dS)N)r)rrnew_listrrrsetlistszImmutableMultiDictMixin.setlistNcCs t|dS)N)r)rr default_listrrrsetlistdefaultsz&ImmutableMultiDictMixin.setlistdefault)N) rr8r9r:r&rIrUrVrWrYr[rrrrrTsrTcsfdd}|_|S)Ncs.ttt|||}|jdk r*|j||S)N)getattrr@UpdateDictMixin on_update)rrMkwr#)namerroncalls  z_calls_update..oncall)r)r`rar)r`r _calls_updates rbcs^eZdZdZdZd fdd Zeffdd ZedZ edZ ed Z ed Z ed Z ZS) r]zbMakes dicts call `self.on_update` on modifications. .. versionadded:: 0.5 :private: Ncs2||k}tj||}|r.|jdk r.|j||S)N)r@rLr^)rrrKmodifiedr#)rGrrrLs  zUpdateDictMixin.setdefaultcsH||k}|tkrtj|}ntj||}|rD|jdk rD|j||S)N)r r@r4r^)rrrKrcr#)rGrrr4s zUpdateDictMixin.popr+r'rQrPrO)N)rr8r9r:r^rLr r4rbr+r'rQrPrOrSrr)rGrr]s r]c@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 NcCsTy ||}Wntk r |SX|dk rPy ||}Wntk rN|}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)rrrKrr#rrrgets   zTypeConversionDict.get)NN)rr8r9r:rgrrrrrdsrdc@s eZdZdZddZddZdS)ImmutableTypeConversionDictzpWorks like a :class:`TypeConversionDict` but does not support modifications. .. versionadded:: 0.5 cCst|S)zReturn 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`). )rd)rrrrcopysz ImmutableTypeConversionDict.copycCs|S)Nr)rrrr__copy__sz$ImmutableTypeConversionDict.__copy__N)rr8r9r:rirjrrrrrhsrhc@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&tj|dd|jDnt|tri}xH|jD]<\}}t|ttfrlt|dkrbq>t|}n|g}|||<q>Wtj||n8i}x&|pfD]\}}|j |gj |qWtj||dS)Ncss"|]\}}||ddfVqdS)Nr).0klrrr Nsz%MultiDict.__init__..r) rrrrBlistsrrrlenrLr-)rrtmprrrrrrBLs      zMultiDict.__init__cCs t|jS)N)rro)rrrr __getstate__`szMultiDict.__getstate__cCstj|tj||dS)N)rrQrO)rrrrr __setstate__cs zMultiDict.__setstate__cCs tj|S)N)r__iter__)rrrrrtgszMultiDict.__iter__cCs6||kr(tj||}t|dkr(|dStj|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__rpr BadRequestKeyError)rrlstrrrrums   zMultiDict.__getitem__cCstj|||gdS)zLike :meth:`add` but removes an existing key first. :param key: the key for the value. :param value: the value to set. N)rr+)rrrrrrr+{szMultiDict.__setitem__cCstj||gj|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)rrLr-)rrrrrrrUsz MultiDict.addcCstytj||}Wntk r$gSX|dkr6t|Sg}x4|D],}y|j||Wq@tk rjYq@Xq@W|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)rrurerr-rf)rrrr#resultr,rrrgetlists   zMultiDict.getlistcCstj||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)rr+r)rrrXrrrrYszMultiDict.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`. r)rrrKrrrrLs zMultiDict.setdefaultcCs4||kr$t|pf}tj|||n tj||}|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` )rrr+ru)rrrZrrrr[s   zMultiDict.setlistdefaultFccsHxBtj|D]4\}}|r2x&|D]}||fVqWq ||dfVq WdS)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)rrrvaluesrrrrrs  zMultiDict.itemsccs*x$tj|D]\}}|t|fVq WdS)zuReturn a iterator of ``(key, values)`` pairs, where values is the list of all values associated with the key.N)rrr)rrrzrrrroszMultiDict.listsccs"xtj|D]}|dVq WdS)zAReturns an iterator of the first value on every key's value list.rN)rrz)rrzrrrrzszMultiDict.valuescCs tj|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 )rrz)rrrr listvaluesszMultiDict.listvaluescCs |j|S)z%Return a shallow copy of this object.)rG)rrrrriszMultiDict.copycCs|jt|jdd|S)z"Return a deep copy of this object.F)flat)rGrto_dict)rmemorrrrszMultiDict.deepcopyTcCs|rt|jSt|jS)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` )rrro)rr|rrrr} s  zMultiDict.to_dictcCs(x"t|D]\}}tj|||q WdS)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)rrrU)rrrrrrrrOszMultiDict.updatec Cs\y*tj||}t|dkr$tj||dStk rV|tk rF|Stj|dYnXdS)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)rr4rpr rvrer )rrrKrwrrrr4-s   z MultiDict.popcCsvy}ztj|jddWYdd}~XnXdS)z*Pop a ``(key, list)`` tuple from the dict.rN)rrPrer rvrM)rrrrrrV^s zMultiDict.popitemlistcCs|jS)N)ri)rrrrrjeszMultiDict.__copy__cCs |j|dS)N)r~)r)rr~rrr __deepcopy__hszMultiDict.__deepcopy__cCs"t|jdt|jdddS)Nr<T)rr=)rrrr)rrrrr>kszMultiDict.__repr__)N)N)N)N)F)N)T)rr8r9r:rBrrrsrtrur+rUryrYrLr[rrorzr{rirr}rOr r4rPrWrVrjrr>rrrrr#s6'           rc@s$eZdZdZd ZddZdd Zd S) _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). prevrrnextcCsF|j|_||_||_d|_|jdkr*||_|jdk r<||j_||_dS)N) _last_bucketrrrr _first_bucket)romdrrrrrrBxs  z_omd_bucket.__init__cCsH|jr|j|j_|jr |j|j_|j|kr2|j|_|j|krD|j|_dS)N)rrrr)rrrrrunlinks    z_omd_bucket.unlinkN)rrrr)rr8r9r: __slots__rBrrrrrros 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.tj|d|_|_|dk r*tj||dS)N)rrBrrrrO)rrrrrrBs  zOrderedMultiDict.__init__c Cst|tstSt|trt|jdd}t|jdd}y6x0|D](\}}t|\}}||ksd||kr@dSq@WWntk rdSXy t|Wntk rdSXdSt|t|krdSx&|j D]\}} |j || krdSqWdS)NT)rF) rrNotImplementedriterrr StopIterationrprory) rr(Ziter1Ziter2Zk1Zv1Zk2Zv2rrzrrr__eq__s.     zOrderedMultiDict.__eq__cCst|t|jddffS)NT)r)rrr)rr%rrrr&szOrderedMultiDict.__reduce_ex__cCst|jddS)NT)r)rr)rrrrrrszOrderedMultiDict.__getstate__cCs,tj|x|D]\}}|j||qWdS)N)rrQrU)rrzrrrrrrss zOrderedMultiDict.__setstate__cCs(||krtj||djStj|dS)Nr)rrurr rv)rrrrrruszOrderedMultiDict.__getitem__cCs|j||j||dS)N)rWrU)rrrrrrr+s zOrderedMultiDict.__setitem__cCs|j|dS)N)r4)rrrrrr'szOrderedMultiDict.__delitem__cCsdd|jDS)Ncss|]\}}|VqdS)Nr)rkrrrrrrnsz(OrderedMultiDict.keys..)r)rrrrrEszOrderedMultiDict.keyscCs t|jS)N)rrE)rrrrrtszOrderedMultiDict.__iter__cCsdd|jDS)Ncss|]\}}|VqdS)Nr)rkrrrrrrnsz*OrderedMultiDict.values..)r)rrrrrzszOrderedMultiDict.valuesFccsp|j}|r.x`|dk r*|j|jfV|j}q Wn>t}x6|dk rj|j|krb|j|j|j|jfV|j}q6WdS)N)rrrrsetrU)rrptr returned_keysrrrrs     zOrderedMultiDict.itemsccsNt}|j}x<|dk rH|j|kr@|j|j|jfV|j|j|j}qWdS)N)rrrryrUr)rrrrrrros   zOrderedMultiDict.listsccs x|jD]\}}|Vq WdS)N)ro)r_keyrzrrrr{szOrderedMultiDict.listvaluescCs tj||gjt|||dS)N)rrLr-r)rrrrrrrUszOrderedMultiDict.addcCs|ytj||}Wntk r$gSX|dkrsz,OrderedMultiDict.getlist..)rrurer-rrf)rrrr#rxr,rrrrys  zOrderedMultiDict.getlistcCs(|j|x|D]}|j||qWdS)N)rWrU)rrrXrrrrrY s  zOrderedMultiDict.setlistcCs tddS)Nz5setlistdefault is unsupported for ordered multi dicts)r )rrrZrrrr[szOrderedMultiDict.setlistdefaultcCs(x"t|D]\}}tj|||q WdS)N)rrrU)rrrrrrrrOszOrderedMultiDict.updatecCs4tj||f}x|D]}|j|qWdd|DS)NcSsg|] }|jqSr)r)rkrrrrrsz,OrderedMultiDict.poplist..)rr4r)rrbucketsbucketrrrrWs zOrderedMultiDict.poplistc Cs`ytj||}Wn,tk r<|tk r,|Stj|dYnXx|D]}|j|qDW|djS)Nr)rr4rer r rvrr)rrrKrrrrrr4s zOrderedMultiDict.popcCsnytj|\}}Wn4tk rF}ztj|jddWYdd}~XnXx|D]}|j|qNW||djfS)Nr)rrPrer rvrMrr)rrrrrrrrrP-s$ zOrderedMultiDict.popitemcCsrytj|\}}Wn4tk rF}ztj|jddWYdd}~XnXx|D]}|j|qNW|dd|DfS)NrcSsg|] }|jqSr)r)rkrrrrrAsz0OrderedMultiDict.popitemlist..)rrPrer rvrMr)rrrrrrrrrV8s$ zOrderedMultiDict.popitemlist)N)F)N)N)rr8r9r:rBrr$r&rrrsrur+r'rErtrzrror{rUryrYr[rOrWr r4rPrVrrrrrs2       rcCstj|dd|jDS)NcSsi|]\}}||jddqS)_-)replace)rkrlrrrr Fsz'_options_header_vkw..)httpZdump_options_headerr)rr_rrr_options_header_vkwDsrcCs*t|tr|jd}t|ts&t|}|S)Nzlatin-1)rbytesdecodestr)rrrr_unicodify_header_valueJs    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*|jj|n |j|dS)N)_listrrrr0)rdefaultsrrrrBts zHeaders.__init__FcCs|s2t|tr|j|St|tr2|j|j|St|tsFtj||j}x"|jD]\}}|j|krV|SqVW|r|t tj|dS)N) rintrslicerGrr rvlowerre)rr _get_modeikeyrlrrrrru|s      zHeaders.__getitem__cCs4dd}|j|jko2tt||jtt||jkS)NcSs|djf|ddS)Nrr)r)r,rrrloweredszHeaders.__eq__..lowered)rGrmapr)rr(rrrrrs zHeaders.__eq__cCsdy|j|dd}Wntk r&|SX|r6|jd}|dkrB|Sy||Stk r^|SXdS)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. T)rlatin1N)rureencoderf)rrrKras_bytesr#rrrrgs z Headers.getc Csr|j}g}x`|D]X\}}|j|kr|r4|jd}|dk r`y ||}Wntk r^wYnX|j|qW|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)rrrfr-)rrrrrrxrlrrrrrys   zHeaders.getlistcCs |j|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. )ry)rr`rrrget_allszHeaders.get_allccs,x&|D]\}}|r|j}||fVqWdS)N)r)rrrrrrrrsz Headers.itemsccs"x|j|D]\}}|Vq WdS)N)r)rrrrrrrrEsz Headers.keysccs x|jD]\}}|Vq WdS)N)r)rrrrrrrzszHeaders.valuescOsnt|dkrtdt||rHx$t|dD]\}}|j||q0Wx t|D]\}}|j||qRWdS)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``. rz)update expected at most 1 arguments, got rN)rpr rrU)rrMrNrrrrrr0s zHeaders.extendTcCsj|rt|ttfr|j|=dS|j}g}x,|jD]"\}}|j|kr2|j||fq2W||jdd<dS)N)rrrrrr-)rr_index_operationnewrlrrrrr' s zHeaders.__delitem__cCs|j|ddS)zBRemove a key. :param key: The key to be removed. F)r)r')rrrrrr.szHeaders.removec Csf|dkr|jjSt|tr(|jj|Sy||}|j|Wn"tk r`|tk rZ|SYnX|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)rr4rrr.rer )rrrKr#rrrr4s    z Headers.popcCs|jS)z7Removes a key or index and returns a (key, value) item.)r4)rrrrrP1szHeaders.popitemc Cs,y|j|ddWntk r&dSXdS)zCheck if a key is present.T)rF)rure)rrrrr __contains__5s zHeaders.__contains__cCstjdtdd||kS)z{ .. 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.) stacklevel)warningswarnDeprecationWarning)rrrrrhas_key=s zHeaders.has_keycCs t|jS)zYield ``(key, value)`` tuples.)rr)rrrrrtKszHeaders.__iter__cCs t|jS)N)rpr)rrrr__len__OszHeaders.__len__cKs<|rt||}t|}t|}|j||jj||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_valuerr-)rr_valuer_rrrrURs   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)rrr rf)rrrrrris  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)rU)rrr_kwrrr add_headerrszHeaders.add_headercCs|jdd=dS)zClears all headers.N)r)rrrrrQzsz Headers.clearc s|rt||}t|}t|}|j||jsB|jj||fdSt|j}|jxHt|D](\}\}}|jkr^||f|j|<Pq^W|jj||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|]}|djkr|qS)r)r)rkt)rrrrszHeaders.set..r)rrrrr-rr enumerate)rrrr_listiteridxZold_keyZ _old_valuer)rrr~s"    z Headers.setcCsF|r8t|}|j|t|x$|D]}|j||q"Wn |j|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)rrrrUr.)rrrzZ values_iterrrrrrYs  zHeaders.setlistcCs ||kr||S|j|||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)rrrKrrrrLs  zHeaders.setdefaultcCs||kr|j|||j|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 )rYry)rrrKrrrr[s zHeaders.setlistdefaultcCs~t|ttfrnt|tr|g}dd|D}x|D]\}}|j|q2Wt|trb|d|j|<qz||j|<n |j||dS)z=Like :meth:`set` but also supports index/slice based setting.cSs g|]\}}t|t|fqSr)r)rkrlrrrrrsz'Headers.__setitem__..rN)rrrrrr)rrrrrrrrr+s   zHeaders.__setitem__cOst|dkrtdt||r|d}t|ttfr^x|jD]}|j||j|qBWnht|trx\|j D]0\}}t|t t fr|j||qr|j ||qrWnx|D]\}}|j ||qWx<|j D]0\}}t|t t fr|j||q|j ||qWdS)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 rz)update expected at most 1 arguments, got rN) rpr rrrrErYryrrrrr)rrMrNrrrrrrrOs$  zHeaders.updatecCst|S)zRConvert the headers into a list suitable for WSGI. :return: list )r)rrrr to_wsgi_list szHeaders.to_wsgi_listcCs |j|jS)N)rGr)rrrrrisz Headers.copycCs|jS)N)ri)rrrrrjszHeaders.__copy__cCsBg}x(|jD]\}}|j|d|qW|jddj|S)z9Returns formatted headers suitable for HTTP transmission.z: z )rr-join)rstrsrrrrr__str__s  zHeaders.__str__cCst|jdt|dS)Nr<r=)rrr)rrrrr>!szHeaders.__repr__)N)F)NNF)NF)F)F)T)'rr8r9r:rBrurr$rgryrrrErzr0r'r.r r4rPrrrtrrUrrrQrrYrLr[r+rOrrirjrr>rrrrrRsF    $     #&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|dS)N)r)rrrNrrrr'/sz!ImmutableHeadersMixin.__delitem__cCs t|dS)N)r)rrrrrrr+2sz!ImmutableHeadersMixin.__setitem__cKs t|dS)N)r)rrrr_rrrr5szImmutableHeadersMixin.setcCs t|dS)N)r)rrrzrrrrY8szImmutableHeadersMixin.setlistcKs t|dS)N)r)rrrr_rrrrU;szImmutableHeadersMixin.addcKs t|dS)N)r)rrrrrrrr>sz ImmutableHeadersMixin.add_headercCs t|dS)N)r)rrrrrr.AszImmutableHeadersMixin.removecOs t|dS)N)r)rrMrNrrrr0DszImmutableHeadersMixin.extendcOs t|dS)N)r)rrMrNrrrrOGszImmutableHeadersMixin.updatecCs t|dS)N)r)rr1rrrrr2JszImmutableHeadersMixin.insertNcCs t|dS)N)r)rrrKrrrr4MszImmutableHeadersMixin.popcCs t|dS)N)r)rrrrrPPszImmutableHeadersMixin.popitemcCs t|dS)N)r)rrrKrrrrLSsz ImmutableHeadersMixin.setdefaultcCs t|dS)N)r)rrrKrrrr[Vsz$ImmutableHeadersMixin.setlistdefault)rr8r9r:r'r+rrYrUrr.r0rOr2r r4rPrLr[rrrrr%src@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 ||_dS)N)environ)rrrrrrBeszEnvironHeaders.__init__cCs |j|jkS)N)r)rr(rrrrhszEnvironHeaders.__eq__NFcCsLt|tst||jjdd}|dkr8t|j|St|jd|S)Nrr CONTENT_TYPECONTENT_LENGTHHTTP_)rr)rrreupperrrr)rrrrrrrums  zEnvironHeaders.__getitem__cCsttt|S)N)rprr)rrrrrwszEnvironHeaders.__len__ccsxxr|jjD]d\}}|jdrJ|d krJ|ddjddjt|fVq |d kr |r |jddjt|fVq WdS) NrHTTP_CONTENT_TYPEHTTP_CONTENT_LENGTHrrrr)rr)rr)rr startswithrtitler)rrrrrrrt|s  zEnvironHeaders.__iter__cCstdt|jddS)Nzcannot create z copies)r rr)rrrrriszEnvironHeaders.copy)F) rr8r9r:rBrr$rurrtrirrrrrZs   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||jffS)N)rdicts)rr%rrrr&szCombinedMultiDict.__reduce_ex__NcCst|p g|_dS)N)rr)rrrrrrBszCombinedMultiDict.__init__cCstd|jddS)Nzcannot create z instances by fromkeys)r r)rDrErrrrrHszCombinedMultiDict.fromkeyscCs.x|jD]}||kr||SqWtj|dS)N)rr rv)rrdrrrrus  zCombinedMultiDict.__getitem__c CsPxJ|jD]@}||kr|dk r@y |||Stk r>wYnX||SqW|S)N)rrf)rrrKrrrrrrgs   zCombinedMultiDict.getcCs*g}x |jD]}|j|j||q W|S)N)rr0ry)rrrr#rrrrrys zCombinedMultiDict.getlistcCst}|j|j|S)zThis function exists so __len__ can be implemented more efficiently, saving one list creation from an iterator. )rrOr)rr#rrr _keys_impls zCombinedMultiDict._keys_implcCs|jS)N)r)rrrrrEszCombinedMultiDict.keyscCs t|jS)N)rrE)rrrrrtszCombinedMultiDict.__iter__Fccs^t}xR|jD]H}xB|j|D]4\}}|r6||fVq||kr|j|||fVqWqWdS)N)rrrrU)rrfoundrrrrrrrs   zCombinedMultiDict.itemsccs x|jD]\}}|Vq WdS)N)r)rrrrrrrzszCombinedMultiDict.valuescCsHi}x6|jD],}x&|jD]\}}|j|gj|qWq Wt|jS)N)rrorLr0rr)rr#rrrzrrrros  zCombinedMultiDict.listscCsdd|jDS)Ncss|]}|dVqdS)rNr)rkrrrrrnsz/CombinedMultiDict.listvalues..)ro)rrrrr{szCombinedMultiDict.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`. )r)rrrrris zCombinedMultiDict.copyTcCs|rt|jSt|jS)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` )rrro)rr|rrrr}s  zCombinedMultiDict.to_dictcCs t|jS)N)rpr)rrrrrszCombinedMultiDict.__len__cCs x|jD]}||krdSqWdS)NTF)r)rrrrrrr s zCombinedMultiDict.__contains__cCstjdtdd||kS)z{ .. 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.r)r)rrr)rrrrrrs zCombinedMultiDict.has_keycCst|jd|jdS)Nr<r=)rrr)rrrrr>szCombinedMultiDict.__repr__)N)N)NN)N)F)T)rr8r9r:r&rBrRrHrurgryrrErtrrzror{rir}rrrr>rrrrrs*     rc@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|dkrNtj|dpLd}t||||}|j||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_typerU)rr`filefilename content_typerrrradd_file)s    zFileMultiDict.add_file)NN)rr8r9r:rrrrrr!src@s(eZdZdZddZddZddZdS) ImmutableDictz;An immutable :class:`dict`. .. versionadded:: 0.5 cCst|jdtj|dS)Nr<r=)rrrr>)rrrrr>HszImmutableDict.__repr__cCst|S)zReturn 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)rrrrriKszImmutableDict.copycCs|S)Nr)rrrrrjRszImmutableDict.__copy__N)rr8r9r:r>rirjrrrrrBsrc@s eZdZdZddZddZdS)ImmutableMultiDictz@An immutable :class:`MultiDict`. .. versionadded:: 0.5 cCst|S)zReturn 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)rrrrri\szImmutableMultiDict.copycCs|S)Nr)rrrrrjcszImmutableMultiDict.__copy__N)rr8r9r:rirjrrrrrVsrc@s(eZdZdZddZddZddZdS) ImmutableOrderedMultiDictzGAn immutable :class:`OrderedMultiDict`. .. versionadded:: 0.6 cCst|jddS)NT)r)rr)rrrrrImsz)ImmutableOrderedMultiDict._iter_hashitemscCst|S)zReturn 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)rrrrripszImmutableOrderedMultiDict.copycCs|S)Nr)rrrrrjwsz"ImmutableOrderedMultiDict.__copy__N)rr8r9r:rIrirjrrrrrgsrc@seZdZdZffddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZd!ddZedd 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. csf|dkrtjd_nHt|tr:|j_tj|n(d_t|fdddd}tj|dS)NFTcsj|d|dfS)Nrr) _specificity)r)rrrsz!Accept.__init__..)rr5)rrBprovidedrrsorted)rrzr)rrrBs  zAccept.__init__cCs |dkfS)z3Returns a tuple describing the value's specificity.*r)rrrrrrszAccept._specificitycCs|dkp|j|jkS)z-Check if a value matches a given accept item.r)r)rrr,rrr_value_matchesszAccept._value_matchescCs t|tr|j|Stj||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``. )rrqualityrru)rrrrrrus  zAccept.__getitem__cCs&x |D]\}}|j||r|SqWdS)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)``) r)r)rrr,rrrrrs zAccept.qualitycCs&x |D]\}}|j||rdSqWdS)NTF)r)rrr,_qualityrrrrs zAccept.__contains__cCs*djdd|D}t|jd|dS)Nz, css$|]\}}d|d|dVqdS)r<z, r=Nr)rkryrrrrnsz"Accept.__repr__..z([z]))rrr)rZ pairs_strrrrr>szAccept.__repr__cCsHt|trr3rrzrrrrpropertyrrrrrr{s "      rz /|(?:\s*;\s*)cCstj|jS)N)_mime_split_resplitr)rrrr_normalize_mime*src@sDeZdZdZddZddZeddZedd Zed d Z d S) MIMEAcceptzRLike :class:`Accept` but with special methods and behavior for mimetypes. cCstddtj|DS)Ncss|]}|dkVqdS)rNr)rkrrrrrn4sz*MIMEAccept._specificity..)rrr)rrrrrr3szMIMEAccept._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)rfrr) rrr,Znormalized_valueZ value_typeZ value_subtypeZ value_paramsZnormalized_itemZ item_typeZ item_subtypeZ item_paramsrrrr6s(zMIMEAccept._value_matchescCsd|kpd|kp|jS)z!True if this object accepts HTML.z text/htmlzapplication/xhtml+xml) accept_xhtml)rrrr accept_html^szMIMEAccept.accept_htmlcCsd|kpd|kS)z"True if this object accepts XHTML.zapplication/xhtml+xmlzapplication/xmlr)rrrrreszMIMEAccept.accept_xhtmlcCsd|kS)z!True if this object accepts JSON.zapplication/jsonr)rrrr accept_jsonjszMIMEAccept.accept_jsonN) rr8r9r:rrrrrrrrrrr.s (  rz[_-]cCstj|jS)z$Process a language tag for matching.)_locale_delim_rerr)rrrr_normalize_langssrcs*eZdZdZddZdfdd ZZS)LanguageAcceptz>Like :class:`Accept` but with normalization for language tags.cCs|dkpt|t|kS)Nr)r)rrr,rrrr{szLanguageAccept._value_matchesNcs|tj|dk rStdd|D}|j|dk r@Sdd|D}tj|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|] }tj|ddd|dfqS)rr)rr)rkr,rrrrsz-LanguageAccept.best_match..cSsg|]}tj|ddqS)rr)rr)rkr,rrrrsc3s|]}|jr|VqdS)N)r)rkr,)rxrrrnsz,LanguageAccept.best_match..)r@rrr)rrrKfallbackZfallback_matches)rG)rxrr~s   zLanguageAccept.best_match)N)rr8r9r:rrrSrr)rGrrxsrc@seZdZdZddZdS) CharsetAcceptz9Like :class:`Accept` but with normalization for charsets.cCs dd}|dkp||||kS)Nc Ss*y tj|jStk r$|jSXdS)N)codecslookupr` LookupErrorr)r`rrr _normalizes z0CharsetAccept._value_matches.._normalizerr)rrr,rrrrrszCharsetAccept._value_matchesN)rr8r9r:rrrrrrsrcs2tfddfddfdddS)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|jS)N)_get_cache_value)r)emptyrrrrrsz(cache_control_property..cs|j|S)N)_set_cache_value)rr)rrrrrscs |jS)N)_del_cache_value)r)rrrrsz accessor for )r)rr rr)r rrrcache_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.r)r)rrrr )rr rrrrcache_propertys rc@seZdZdZedddZeddeZeddeZ edddZ fdfd d Z d d Z d dZ 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-cacherNzno-storezmax-agerz no-transformcCs$tj||p f||_|dk |_dS)N)rrBr^r)rrzr^rrrrBsz_CacheControl.__init__c Cs^|tkr||kS||krZ||}|dkr,|S|dk rVy ||}Wntk rTYnX|SdS)z+Used internally by the accessor properties.N)boolrf)rrr rrrrrr s z_CacheControl._get_cache_valuecCsX|tkr$|rd||<qT|j|dn0|dkr:|j|dn|dkrLd||<n|||<dS)z+Used internally by the accessor properties.NT)rr4)rrrrrrrr s  z_CacheControl._set_cache_valuecCs||kr||=dS)z+Used internally by the accessor properties.Nr)rrrrrr sz_CacheControl._del_cache_valuecCs tj|S)z6Convert the stored values into a cache control header.)r dump_header)rrrrr"sz_CacheControl.to_headercCs|jS)N)r)rrrrr&sz_CacheControl.__str__cCs4djddt|jD}dt|jd|dS)N css |]\}}|d|VqdS)=Nr)rkrlrrrrrn*sz)_CacheControl.__repr__..<>)rrrrr)rkv_strrrrr>)sz_CacheControl.__repr__r7)rr8r9r:r no_cacherno_storerZmax_ageZ no_transformrBr r r rrr> staticmethodrrrrrrs    rc@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-stalerz min-freshzonly-if-cachedN) rr8r9r:r rZ max_stale min_freshrZonly_if_cachedrrrrr0s   rc@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. publicNprivaterzmust-revalidatezproxy-revalidatezs-maxage immutable) rr8r9r:r rrrZmust_revalidateZproxy_revalidateZs_maxagerrrrrrCs      rcs,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 |jS)N) _get_value)r)rrrr`szcsp_property..cs |j|S)N) _set_value)rr)rrrrascs |jS)N) _del_value)r)rrrrbsz accessor for )r)rr)rr csp_propertyZs    r#c@seZdZdZedZedZedZedZedZ edZ edZ ed Z ed Z ed Zed Zed ZedZedZedZedZedZedZedZedZedZedZedZedZedZfdfddZddZd 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-srcNcCs$tj||p f||_|dk |_dS)N)rrBr^r)rrzr^rrrrBszContentSecurityPolicy.__init__cCs |j|S)z+Used internally by the accessor properties.)rg)rrrrrr sz ContentSecurityPolicy._get_valuecCs"|dkr|j|dn|||<dS)z+Used internally by the accessor properties.N)r4)rrrrrrr!sz ContentSecurityPolicy._set_valuecCs||kr||=dS)z+Used internally by the accessor properties.Nr)rrrrrr"sz ContentSecurityPolicy._del_valuecCs tj|S)z6Convert the stored values into a cache control header.)rZdump_csp_header)rrrrrszContentSecurityPolicy.to_headercCs|jS)N)r)rrrrrszContentSecurityPolicy.__str__cCs4djddt|jD}dt|jd|dS)Nrcss |]\}}|d|VqdS)rNr)rkrlrrrrrnsz1ContentSecurityPolicy.__repr__..rr)rrrrr)rrrrrr>szContentSecurityPolicy.__repr__)%rr8r9r:r#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_urir%Z script_srcZscript_src_attrZscript_src_elemZ style_srcZstyle_src_attrZstyle_src_elemZ worker_srcrBr r!r"rrr>rrrrr$gsBr$c@s"eZdZdZdddZddZdS) CallbackDictzwA dict that calls a function passed every time something is changed. The function is passed the dict instance. NcCstj||p f||_dS)N)rrBr^)rinitialr^rrrrBszCallbackDict.__init__cCsdt|jdtj|dS)Nrrr)rrrr>)rrrrr>szCallbackDict.__repr__)NN)rr8r9r:rBr>rrrrr&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|pf|_dd|jD|_||_dS)NcSsh|] }|jqSr)r)rkrrrr sz%HeaderSet.__init__..)r_headers_setr^)rheadersr^rrrrBszHeaderSet.__init__cCs|j|fdS)zAdd a new header to the set.N)rO)rheaderrrrrUsz HeaderSet.addcCsl|j}||jkrt||jj|x,t|jD]\}}|j|kr2|j|=Pq2W|jdk rh|j|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)rr+rer.rr*r^)rr-rrrrrr.s     zHeaderSet.removecCs\d}x:|D]2}|j}||jkr |jj||jj|d}q W|rX|jdk rX|j|dS)zAdd all the headers from the iterable to the set. :param iterable: updates the set with the items from the iterable. FTN)rr+r*r-rUr^)rr/Z inserted_anyr-rrrrrOs    zHeaderSet.updatec Cs(y|j|Wntk r"YnXdS)zdLike :meth:`remove` but ignores errors. :param header: the header to be discarded. N)r.re)rr-rrrdiscardszHeaderSet.discardcCs4|j}x&t|jD]\}}|j|kr|SqWdS)zReturn the index of the header in the set or return -1 if not found. :param header: the header to be looked up. rr7)rrr*)rr-rr,rrrr s  zHeaderSet.findcCs|j|}|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)r IndexError)rr-r#rrrr3 s zHeaderSet.indexcCs.|jj|jdd=|jdk r*|j|dS)zClear the set.N)r+rQr*r^)rrrrrQ 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. )rr*r+)rZpreserve_casingrrras_set! s  zHeaderSet.as_setcCsdjttj|jS)z2Convert the header set into an HTTP header string.z, )rrrquote_header_valuer*)rrrrr. szHeaderSet.to_headercCs |j|S)N)r*)rrrrrru2 szHeaderSet.__getitem__cCs4|jj|}|jj|j|jdk r0|j|dS)N)r*r4r+r.rr^)rrr#rrrr'5 s  zHeaderSet.__delitem__cCsL|j|}|jj|j||j|<|jj|j|jdk rH|j|dS)N)r*r+r.rrUr^)rrroldrrrr+; s    zHeaderSet.__setitem__cCs|j|jkS)N)rr+)rr-rrrrC szHeaderSet.__contains__cCs t|jS)N)rpr+)rrrrrF szHeaderSet.__len__cCs t|jS)N)rr*)rrrrrtI szHeaderSet.__iter__cCs t|jS)N)rr+)rrrr__bool__L szHeaderSet.__bool__cCs|jS)N)r)rrrrrO szHeaderSet.__str__cCst|jd|jdS)Nr<r=)rrr*)rrrrr>R szHeaderSet.__repr__)NN)F)rr8r9r:rBrUr.rOr.rr3rQr0rrur'r+rrrtr3rr>rrrrr(s(      r(c@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. NFcCs6| r|rt||_nt|_t|p&f|_||_dS)N)rJ_strong_weakstar_tag)rZ strong_etagsZ weak_etagsr7rrrrB[ s   zETags.__init__cCst|j}|r|j|j|S)zoConvert the `ETags` object into a python set. Per default all the weak etags are not part of this set.)rr5rOr6)r include_weakr#rrrr0d s  z ETags.as_setcCs ||jkS)zCheck if an etag is weak.)r6)retagrrris_weakl sz ETags.is_weakcCs ||jkS)zCheck if an etag is strong.)r5)rr9rrr is_strongp szETags.is_strongcCs|j|p|j|S)zCCheck if an etag is part of the set including weak and strong tags.)r:contains)rr9rrr contains_weakt szETags.contains_weakcCs|jr dS|j|S)zxCheck if an etag is part of the set ignoring weak tags. It is also possible to use the ``in`` operator. T)r7r;)rr9rrrr<x szETags.containscCs&tj|\}}|r|j|S|j|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_etagr=r<)rr9Zweakrrr contains_raw s zETags.contains_rawcCs0|jr dSdjdd|jDdd|jDS)z0Convert the etags set into a HTTP header string.rz, cSsg|]}d|dqS)"r)rkrrrrr sz#ETags.to_header..cSsg|]}d|dqS)zW/"r?r)rkrrrrr s)r7rr5r6)rrrrr szETags.to_headercCsH||gjddkrtd|dkr,tj|}|r>||jkr>dS||jkS)Nrz-either tag or data required, but at least oneT)countr rZ generate_etagr6r5)rr9datar8rrr__call__ s  zETags.__call__cCst|jp|jp|jS)N)rr7r5r6)rrrrr3 szETags.__bool__cCs|jS)N)r)rrrrr sz ETags.__str__cCs t|jS)N)rpr5)rrrrr sz ETags.__len__cCs t|jS)N)rr5)rrrrrt szETags.__iter__cCs |j|S)N)r<)rr9rrrr szETags.__contains__cCsdt|jdt|dS)Nrrr)rrr)rrrrr> szETags.__repr__)NNF)F)NNF)rr8r9r:rBr0r:r;r=r<r>rrBr3rrrtrr>rrrrr4V s    r4c@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||_||_dS)N)r9date)rr9rDrrrrB szIfRange.__init__cCs0|jdk rtj|jS|jdk r,tj|jSdS)z-Converts the object back into an HTTP header.N)rDrZ http_dater9Z quote_etag)rrrrr s     zIfRange.to_headercCs|jS)N)r)rrrrr szIfRange.__str__cCsdt|jdt|dS)Nrrr)rrr)rrrrr> szIfRange.__repr__)NN)rr8r9r:rBrrr>rrrrrC s  rCc@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 cCsT||_||_xB|D]:\}}|dks:|dk r|dks:||krt||fdqWdS)Nrz is not a valid range.)unitsrangesrf)rrGrHstartendrrrrB s  zRange.__init__cCsn|jdks |dks t|jdkr$dS|jd\}}|dkrN|}|dkrN||7}tj|||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`. rNrr)rGrprHris_byte_range_validmin)rlengthrIrJrrrrange_for_length s zRange.range_for_lengthcCs.|j|}|dk r*t|j|d|d|SdS)zCreates a :class:`~werkzeug.datastructures.ContentRange` object from the current range and given content length. Nrr)rN ContentRangerG)rrMrngrrrmake_content_range s zRange.make_content_rangecCspg}xT|jD]J\}}|dkr>|j|dkr2|dnt|q |j|d|dq W|jddj|S)z-Converts the object back into an HTTP header.Nrrrrr)rHr-rrGr)rrHbeginrJrrrr s "zRange.to_headercCs>|j|}|dk r:|jd|dd|ddd|SdS)z\Converts the object into `Content-Range` HTTP header, based on given length Nrrrrr)rNrG)rrMrangerrrto_content_range_header s (zRange.to_content_range_headercCs|jS)N)r)rrrrr sz Range.__str__cCsdt|jdt|dS)Nrrr)rrr)rrrrr> szRange.__repr__N) rr8r9r:rBrNrQrrTrr>rrrrrF s     rFcs"fdd}fdd}t||S)Ncs t|S)N)r\)r)r`rrfget sz _callback_property..fgetcs$t|||jdk r |j|dS)N)setattrr^)rr)r`rrfset s  z _callback_property..fset)r)r`rUrWr)r`r_callback_property s  rXc@sleZdZdZdddZedZedZedZedZ dd d Z d d Z ddZ ddZ ddZddZdS)rOzDRepresents the content range header. .. versionadded:: 0.7 NcCs0tj|||std||_|j||||dS)NzBad range provided)rrKAssertionErrorr^r)rrGrIstoprMr^rrrrB) szContentRange.__init___units_start_stop_lengthrcCsFtj|||std||_||_||_||_|jdk rB|j|dS)z#Simple method to update the ranges.zBad range providedN)rrKrYr[r\r]r^r^)rrIrZrMrGrrrr8 s zContentRange.setcCs|jdddddS)zcSets the units to `None` which indicates that the header should no longer be used. N)rG)r)rrrrunsetB szContentRange.unsetcCsb|jdkrdS|jdkrd}n|j}|jdkr>|jd|S|jd|jd|jdd|S)NrErz */rrrr)rGrMrIrZ)rrMrrrrH s   zContentRange.to_headercCs |jdk S)N)rG)rrrrr3S szContentRange.__bool__cCs|jS)N)r)rrrrrV szContentRange.__str__cCsdt|jdt|dS)Nrrr)rrr)rrrrr>Y szContentRange.__repr__)NN)Nr)rr8r9r:rBrXrGrIrZrMrr_rr3rr>rrrrrO# s   rOc@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. NcCstj||p i||_dS)N)rrBr)r auth_typerArrrrBi szAuthorization.__init__cCs |jdS)zdThe username transmitted. This is set for both basic and digest auth all the time. username)rg)rrrrrbm szAuthorization.usernamecCs |jdS)zsWhen the authentication type is basic this is the password transmitted by the client, else `None`. password)rg)rrrrrct szAuthorization.passwordcCs |jdS)z8This is the server realm sent back for HTTP digest auth.realm)rg)rrrrrd{ szAuthorization.realmcCs |jdS)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. nonce)rg)rrrrre szAuthorization.noncecCs |jdS)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. uri)rg)rrrrrf szAuthorization.uricCs |jdS)zzThe nonce count value transmitted by clients if a qop-header is also transmitted. HTTP digest auth only. nc)rg)rrrrrg szAuthorization.nccCs |jdS)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. cnonce)rg)rrrrrh szAuthorization.cnoncecCs |jdS)zA string of 32 hex digits computed as defined in RFC 2617, which proves that the user knows a password. Digest auth only. response)rg)rrrrri szAuthorization.responsecCs |jdS)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. opaque)rg)rrrrrj szAuthorization.opaquecCs |jdS)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. qop)rg)rrrrrk szAuthorization.qopcCsf|jdkr6tj|jd|jjjd}d|S|jdkrPdtj|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 b64encoderbrcrrrrrf)rrrrrr s   zAuthorization.to_header)N)rr8r9r:rBrrbrcrdrerfrgrhrirjrkrrrrrr`] s            r`cs"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|jdn t||<dS)N)r4r)rr)r`rrr! sz!auth_property.._set_valuecs |jS)N)rg)r)r`rrr szauth_property..)doc)r)r`rsr!r)r`r auth_property s rtcsfdd}t||dS)Ncs fdd}tjj|S)Ncs*| rkr=n|r&|j<dS)N)r)Z header_set)r`rrrr^ sz._set_property..fget..on_update)rZparse_set_headerrg)rr^)r`)rrrU sz_set_property..fget)rs)r)r`rsrUr)r`r _set_property s ruc@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.domainrerjrdrkNcCs&tj||p f|r||d<||_dS)N __auth_type__)rrBr^)rrarzr^rrrrB szWWWAuthenticate.__init__authentication requiredcCs0tj|tj|d|d|jr,|j|dS)z*Clear the auth info and enable basic auth.rl)rxrdN)rrQrOr^)rrdrrr set_basic s zWWWAuthenticate.set_basicauthFcCsjd||tj|d}|r d|d<|dk r0||d<|dk r@||d<tj|tj|||jrf|j|dS)z+Clear the auth info and enable digest auth.ro)rxrdrerkTRUEstaleNrj algorithm)rrrrQrOr^)rrdrerkrjr~r}rrrr set_digest s  zWWWAuthenticate.set_digestcsTt}|jddpd}fdd|jD}djdd|D}|jd |S) z9Convert the stored values into a WWW-Authenticate header.rxNrlc3s*|]"\}}|tj||jkdfVqdS))Z allow_tokenN)rr1_require_quoting)rkrlr)rrrrn sz,WWWAuthenticate.to_header..z, cSsg|]\}}|d|qS)rr)rkrlrrrrr sz-WWWAuthenticate.to_header..r)rr4rrr)rrraZkv_itemsZ kv_stringr)rrr s   zWWWAuthenticate.to_headercCs|jS)N)r)rrrrr szWWWAuthenticate.__str__cCsdt|jd|jdS)Nrrr)rrr)rrrrr> szWWWAuthenticate.__repr__rxzZThe type of the auth mechanism. HTTP currently specifies ``Basic`` and ``Digest``.)rsaA 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.r~a 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"|jd}|dk r|jdkSdS)z}A flag, indicating that the previous request from the client was rejected because the nonce value was stale. r}Ntrue)rgr)rvalrrrr}Q s zWWWAuthenticate.stalecCs*|dkr|jddn|rdnd|d<dS)Nr}r|FALSE)r4)rrrrrr}Z s)NNN)ryr{)rNNF)rr8r9r:rJrrBrzrrrr>rtrrdrurwrerjr~rkrr}setterrrrrrrv s@     rvc@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|jtd}||_ |dkrt }||_ |dk r||d<|dk rt ||d<dS) Nr`rrrrrz Content-TypezContent-Lengthr7) r`rstreamr\r rrrr rrr,r)rrrr`rcontent_lengthr,srrrrBl s"   $ zFileStorage.__init__cCst|dstj|j|_dS)N_parsed_content_type)hasattrrZparse_options_headerrr)rrrr_parse_content_type s zFileStorage._parse_content_typecCs |jjdS)z;The content-type sent in the header. Usually not availablez content-type)r,rg)rrrrr szFileStorage.content_typecCst|jjdpdS)z=The content-length sent in the header. Usually not availablezcontent-lengthr)rr,rg)rrrrr szFileStorage.content_lengthcCs|j|jdjS)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)rrr)rrrrmimetype s zFileStorage.mimetypecCs|j|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)rr)rrrrmimetype_params szFileStorage.mimetype_params@c Cs`ddlm}d}t|dr"t|}t|tr:t|d}d}z||j||Wd|rZ|jXdS)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) shutilrrrrrrrclose)rdst buffer_sizerZ close_dstrrrsave s    zFileStorage.savec Cs(y|jjWntk r"YnXdS)z&Close the underlying file if possible.N)rr Exception)rrrrr szFileStorage.closecCs t|jS)N)rr)rrrrr3 szFileStorage.__bool__c CsBy t|j|Stk r<t|jdr6t|jj|SYnXdS)N_file)r\rAttributeErrorrr)rr`rrr __getattr__ s   zFileStorage.__getattr__cCs t|jS)N)rr)rrrrrt szFileStorage.__iter__cCs"dt|jd|jd|jdS)Nrz: z (z)>)rrrr)rrrrr> szFileStorage.__repr__)NNNNNN)r)rr8r9r:rBrrrrrrrrr3rrtr>rrrrrd s$    ! r)r)N)N)Mrqrrrercollections.abcrrririor itertoolsrosrrEr Z _internalr r filesystemr rrr rr;r?rTrbrr]rdrhrrrrrrrrrrrrrrcompilerrrrrrrr rrrrr#r$r&r(r4rCrFrXrOr`rtrurvrrrrrrs          5 2 ")N 6V53!- B 6  \ L XK :j  |