# Data Structures

Werkzeug provides some subclasses of common Python objects to extend them with additional features. Some of them are used to make them immutable, others are used to change some semantics to better work with HTTP.

## General Purpose

Changelog

Changed in version 0.6: The general purpose classes are now pickleable in each protocol as long as the contained objects are pickleable. This means that the `FileMultiDict` won’t be pickleable as soon as it contains a file.

class werkzeug.datastructures.TypeConversionDict

  Works like a regular dict but the `get()` method can perform type conversions. `MultiDict` and `CombinedMultiDict` are subclasses of this class and provide the same feature.

  Changelog

  New in version 0.5.

  get(key, default=None, type=None)

    Return the default value if the requested data doesn’t exist. If type is provided and is a callable it should convert the value, return it or raise a `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

    Parameters

      - key – The key to be looked up.

      - default – The default value to be returned if the key can’t be looked up. If not further specified None is returned.

      - type – A callable that is used to cast the value in the `MultiDict`. If a `ValueError` is raised by this callable the default value is returned.

class werkzeug.datastructures.ImmutableTypeConversionDict

  Works like a `TypeConversionDict` but does not support modifications.

  Changelog

  New in version 0.5.

  copy()

    Return a shallow mutable copy of this object. Keep in mind that the standard library’s `copy()` function is a no-op for this class like for any other python immutable type (eg: `tuple`).

class werkzeug.datastructures.MultiDict(mapping=None)

  A `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.

  `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 `BadRequest` HTTP exception and will render a page for a `400 BAD REQUEST` if caught in a catch-all for HTTP exceptions.

  A `MultiDict` can be constructed from an iterable of `(key, value)` tuples, a dict, a `MultiDict` or from Werkzeug 0.2 onwards some keyword parameters.

  Parameters

    mapping – the initial value for the `MultiDict`. Either a regular dict, an iterable of `(key, value)` tuples or None.

  add(key, value)

    Adds a new value for the key.

    Changelog

    New in version 0.6.

    Parameters

      - key – the key for the value.

      - value – the value to add.

  clear() → None. Remove all items from D.
  copy()

    Return a shallow copy of this object.

  deepcopy(memo=None)

    Return a deep copy of this object.

  fromkeys(value=None, /)

    Create a new dictionary with keys from iterable and values set to value.

  get(key, default=None, type=None)

    Return the default value if the requested data doesn’t exist. If type is provided and is a callable it should convert the value, return it or raise a `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

    Parameters

      - key – The key to be looked up.

      - default – The default value to be returned if the key can’t be looked up. If not further specified None is returned.

      - type – A callable that is used to cast the value in the `MultiDict`. If a `ValueError` is raised by this callable the default value is returned.

  getlist(key, type=None)

    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.

    Parameters

      - key – The key to be looked up.

      - type – A callable that is used to cast the value in the `MultiDict`. If a `ValueError` is raised by this callable the value will be removed from the list.

    Returns

      a `list` of all the values for the key.

  items(multi=False)

    Return an iterator of `(key, value)` pairs.

    Parameters

      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.

  keys() → a set-like object providing a view on D's keys
  lists()

    Return a iterator of `(key, values)` pairs, where values is the list of all values associated with the key.

  listvalues()

    Return an iterator of all values associated with a key. Zipping `keys()` and this is the same as calling `lists()`:

        >>> d = MultiDict({"foo": [1, 2, 3]})
        >>> zip(d.keys(), d.listvalues()) == d.lists()
        True

  pop(key, default=no value)

    Pop 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

    Parameters

      - key – the key to pop.

      - default – if provided the value to return if the key was not in the dictionary.

  popitem()

    Pop an item from the dict.

  popitemlist()

    Pop a `(key, list)` tuple from the dict.

  poplist(key)

    Pop the list for a key from the dict. If the key is not in the dict an empty list is returned.

    Changelog

    Changed in version 0.5: If the key does no longer exist a list is returned instead of raising an error.

  setdefault(key, default=None)

    Returns the value for the key if it is in the dict, otherwise it returns default and sets that value for key.

    Parameters

      - key – The key to be looked up.

      - default – The default value to be returned if the key is not in the dict. If not further specified it’s None.

  setlist(key, new_list)

    Remove 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']

    Parameters

      - key – The key for which the values are set.

      - new_list – An iterable with the new values for the key. Old values are removed first.

  setlistdefault(key, default_list=None)

    Like 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]

    Parameters

      - key – The key to be looked up.

      - default_list – An iterable of default values. It is either copied (in case it was a list) or converted into a list before returned.

    Returns

      a `list`

  to_dict(flat=True)

    Return 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.

    Parameters

      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.

    Returns

      a `dict`

  update(mapping)

    update() 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([])

  values()

    Returns an iterator of the first value on every key’s value list.

class werkzeug.datastructures.OrderedMultiDict(mapping=None)

  Works like a regular `MultiDict` but preserves the order of the fields. To convert the ordered multi dict into a list you can use the `items()` method and pass it `multi=True`.

  In general an `OrderedMultiDict` is an order of magnitude slower than a `MultiDict`.

  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 `to_dict()` method, otherwise the internal bucket objects are exposed.

class werkzeug.datastructures.ImmutableMultiDict(mapping=None)

  An immutable `MultiDict`.

  Changelog

  New in version 0.5.

  copy()

    Return a shallow mutable copy of this object. Keep in mind that the standard library’s `copy()` function is a no-op for this class like for any other python immutable type (eg: `tuple`).

class werkzeug.datastructures.ImmutableOrderedMultiDict(mapping=None)

  An immutable `OrderedMultiDict`.

  Changelog

  New in version 0.6.

  copy()

    Return a shallow mutable copy of this object. Keep in mind that the standard library’s `copy()` function is a no-op for this class like for any other python immutable type (eg: `tuple`).

class werkzeug.datastructures.CombinedMultiDict(dicts=None)

  A read only `MultiDict` that you can pass multiple `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 `BadRequest` HTTP exception and will render a page for a `400 BAD REQUEST` if caught in a catch-all for HTTP exceptions.

class werkzeug.datastructures.ImmutableDict

  An immutable `dict`.

  Changelog

  New in version 0.5.

  copy()

    Return a shallow mutable copy of this object. Keep in mind that the standard library’s `copy()` function is a no-op for this class like for any other python immutable type (eg: `tuple`).

class werkzeug.datastructures.ImmutableList(iterable=(), /)

  An immutable `list`.

  Changelog

  New in version 0.5.

  Private

class werkzeug.datastructures.FileMultiDict(mapping=None)

  A special `MultiDict` that has convenience methods to add files to it. This is used for `EnvironBuilder` and generally useful for unittesting.

  Changelog

  New in version 0.5.

  add_file(name, file, filename=None, content_type=None)

    Adds a new file to the dict. file can be a file name or a `file`-like or a `FileStorage` object.

    Parameters

      - name – the name of the field.

      - file – a filename or `file`-like object

      - filename – an optional filename

      - content_type – an optional content type

## HTTP Related

class werkzeug.datastructures.Headers([defaults])

  An 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 `KeyError` raised by this class is also a subclass of the `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 `wsgiref.headers.Headers` class, with the exception of __getitem__. `wsgiref` will return None for `headers['missing']`, whereas `Headers` will raise a `KeyError`.

  To create a new `Headers` object, pass it a list, dict, or other `Headers` object with default values. These values are validated the same way values added later are.

  Parameters

    defaults – The list of default values for the `Headers`.

  Changelog

  Changed in version 2.1.0: Default values are validated the same as values added later.

  Changed in version 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.

  Changed in version 0.9: The `linked()` function was removed without replacement as it was an API that does not support the changes to the encoding model.

  add(_key, _value, **kw)

    Add 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 `dump_options_header()` behind the scenes.

    Changelog

    New in version 0.4.1: keyword arguments were added for `wsgiref` compatibility.

  add_header(_key, _value, **_kw)

    Add a new header tuple to the list.

    An alias for `add()` for compatibility with the `wsgiref` `add_header()` method.

  clear()

    Clears all headers.

  extend(*args, **kwargs)

    Extend headers in this object with items from another object containing header items as well as keyword arguments.

    To replace existing keys instead of extending, use `update()` instead.

    If provided, the first argument can be another `Headers` object, a `MultiDict`, `dict`, or iterable of pairs.

    Changelog

    Changed in version 1.0: Support `MultiDict`. Allow passing `kwargs`.

  get(key, default=None, type=None, as_bytes=False)

    Return the default value if the requested data doesn’t exist. If type is provided and is a callable it should convert the value, return it or raise a `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

    Changelog

    New in version 0.9: Added support for as_bytes.

    Parameters

      - key – The key to be looked up.

      - default – The default value to be returned if the key can’t be looked up. If not further specified None is returned.

      - type – A callable that is used to cast the value in the `Headers`. If a `ValueError` is raised by this callable the default value is returned.

      - as_bytes – return bytes instead of strings.

  get_all(name)

    Return a list of all the values for the named field.

    This method is compatible with the `wsgiref` `get_all()` method.

  getlist(key, type=None, as_bytes=False)

    Return the list of items for a given key. If that key is not in the `Headers`, 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.

    Changelog

    New in version 0.9: Added support for as_bytes.

    Parameters

      - key – The key to be looked up.

      - type – A callable that is used to cast the value in the `Headers`. If a `ValueError` is raised by this callable the value will be removed from the list.

      - as_bytes – return bytes instead of strings.

    Returns

      a `list` of all the values for the key.

  pop(key=None, default=no value)

    Removes and returns a key or index.

    Parameters

      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.

    Returns

      an item.

  popitem()

    Removes a key or index and returns a (key, value) item.

  remove(key)

    Remove a key.

    Parameters

      key – The key to be removed.

  set(_key, _value, **kw)

    Remove 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 `add()` for more information.

    Changelog

    Changed in version 0.6.1: `set()` now accepts the same arguments as `add()`.

    Parameters

      - key – The key to be inserted.

      - value – The value to be inserted.

  setdefault(key, default)

    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.

    Parameters

      - key – The header key to get.

      - default – The value to set for the key if it is not in the headers.

  setlist(key, values)

    Remove any existing values for a header and add new ones.

    Parameters

      - key – The header key to set.

      - values – An iterable of values to set for the key.

    Changelog

    New in version 1.0.

  setlistdefault(key, default)

    Return the list of values for the key if it is in the headers, otherwise set the header to the list of values given by `default` and return that.

    Unlike `MultiDict.setlistdefault()`, modifying the returned list will not affect the headers.

    Parameters

      - key – The header key to get.

      - default – An iterable of values to set for the key if it is not in the headers.

    Changelog

    New in version 1.0.

  to_wsgi_list()

    Convert the headers into a list suitable for WSGI.

    Returns

      list

  update(*args, **kwargs)

    Replace headers in this object with items from another headers object and keyword arguments.

    To extend existing keys instead of replacing, use `extend()` instead.

    If provided, the first argument can be another `Headers` object, a `MultiDict`, `dict`, or iterable of pairs.

    Changelog

    New in version 1.0.

class werkzeug.datastructures.EnvironHeaders(environ)

  Read only version of the headers from a WSGI environment. This provides the same interface as Headers and is constructed from a WSGI environment.

  From Werkzeug 0.3 onwards, the KeyError raised by this class is also a subclass of the `BadRequest` HTTP exception and will render a page for a `400 BAD REQUEST` if caught in a catch-all for HTTP exceptions.

class werkzeug.datastructures.HeaderSet(headers=None, on_update=None)

  Similar to the `ETags` class this implements a set-like structure. Unlike `ETags` this is case insensitive and used for vary, allow, and content-language headers.

  If not constructed using the `parse_set_header()` function the instantiation works like this:

      >>> hs = HeaderSet(['foo', 'bar', 'baz'])
      >>> hs
      HeaderSet(['foo', 'bar', 'baz'])

  add(header)

    Add a new header to the set.

  as_set(preserve_casing=False)

    Return the set as real python set type. When calling this, all the items are converted to lowercase and the ordering is lost.

    Parameters

      preserve_casing – if set to True the items in the set returned will have the original case like in the `HeaderSet`, otherwise they will be lowercase.

  clear()

    Clear the set.

  discard(header)

    Like `remove()` but ignores errors.

    Parameters

      header – the header to be discarded.

  find(header)

    Return the index of the header in the set or return -1 if not found.

    Parameters

      header – the header to be looked up.

  index(header)

    Return the index of the header in the set or raise an `IndexError`.

    Parameters

      header – the header to be looked up.

  remove(header)

    Remove a header from the set. This raises an `KeyError` if the header is not in the set.

    Changelog

    Changed in version 0.5: In older versions a `IndexError` was raised instead of a `KeyError` if the object was missing.

    Parameters

      header – the header to be removed.

  to_header()

    Convert the header set into an HTTP header string.

  update(iterable)

    Add all the headers from the iterable to the set.

    Parameters

      iterable – updates the set with the items from the iterable.

class werkzeug.datastructures.Accept(values=())

  An `Accept` object is just a list subclass for lists of `(value, quality)` tuples. It is automatically sorted by specificity and quality.

  All `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

  Changelog

  Changed in version 1.0.0: `Accept` internal values are no longer ordered alphabetically for equal quality tags. Instead the initial order is preserved.

  Changed in version 0.5: `Accept` objects are forced immutable now.

  property best

    The best match as value.

  best_match(matches, default=None)

    Returns the best match from a list of possible matches based on the specificity and quality of the client. If two items have the same quality and specificity, the one is returned that comes first.

    Parameters

      - matches – a list of matches to check for

      - default – the value that is returned if none match

  find(key)

    Get the position of an entry or return -1.

    Parameters

      key – The key to be looked up.

  index(key)

    Get the position of an entry or raise `ValueError`.

    Parameters

      key – The key to be looked up.

    Changelog

    Changed in version 0.5: This used to raise `IndexError`, which was inconsistent with the list API.

  quality(key)

    Returns the quality of the key.

    Changelog

    New in version 0.6: In previous versions you had to use the item-lookup syntax (eg: `obj[key]` instead of `obj.quality(key)`)

  to_header()

    Convert the header set into an HTTP header string.

  values()

    Iterate over all values.

class werkzeug.datastructures.MIMEAccept(values=())

  Like `Accept` but with special methods and behavior for mimetypes.

  property accept_html

    True if this object accepts HTML.

  property accept_json

    True if this object accepts JSON.

  property accept_xhtml

    True if this object accepts XHTML.

class werkzeug.datastructures.CharsetAccept(values=())

  Like `Accept` but with normalization for charsets.

class werkzeug.datastructures.LanguageAccept(values=())

  Like `Accept` but with normalization for language tags.

class werkzeug.datastructures.RequestCacheControl(values=(), on_update=None)

  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 `RequestCacheControl` object again you can convert the object into a string or call the `to_header()` method. If you plan to subclass it and add your own items have a look at the sourcecode for that class.

  Changelog

  Changed in version 2.1.0: Setting int properties such as `max_age` will convert the value to an int.

  New in version 0.5: In previous versions a CacheControl class existed that was used both for request and response.

  no_cache

    accessor for ‘no-cache’

  no_store

    accessor for ‘no-store’

  max_age

    accessor for ‘max-age’

  no_transform

    accessor for ‘no-transform’

  property max_stale

    accessor for ‘max-stale’

  property min_fresh

    accessor for ‘min-fresh’

  property only_if_cached

    accessor for ‘only-if-cached’

class werkzeug.datastructures.ResponseCacheControl(values=(), on_update=None)

  A cache control for responses. Unlike `RequestCacheControl` this is mutable and gives access to response-relevant cache control headers.

  To get a header of the `ResponseCacheControl` object again you can convert the object into a string or call the `to_header()` method. If you plan to subclass it and add your own items have a look at the sourcecode for that class.

  Changelog

  Changed in version 2.1.1: `s_maxage` converts the value to an int.

  Changed in version 2.1.0: Setting int properties such as `max_age` will convert the value to an int.

  New in version 0.5: In previous versions a CacheControl class existed that was used both for request and response.

  no_cache

    accessor for ‘no-cache’

  no_store

    accessor for ‘no-store’

  max_age

    accessor for ‘max-age’

  no_transform

    accessor for ‘no-transform’

  property immutable

    accessor for ‘immutable’

  property must_revalidate

    accessor for ‘must-revalidate’

  property private

    accessor for ‘private’

  property proxy_revalidate

    accessor for ‘proxy-revalidate’

  property public

    accessor for ‘public’

  property s_maxage

    accessor for ‘s-maxage’

class werkzeug.datastructures.ETags(strong_etags=None, weak_etags=None, star_tag=False)

  A set that can be used to check if one etag is present in a collection of etags.

  as_set(include_weak=False)

    Convert the ETags object into a python set. Per default all the weak etags are not part of this set.

  contains(etag)

    Check if an etag is part of the set ignoring weak tags. It is also possible to use the `in` operator.

  contains_raw(etag)

    When 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.

  contains_weak(etag)

    Check if an etag is part of the set including weak and strong tags.

  is_strong(etag)

    Check if an etag is strong.

  is_weak(etag)

    Check if an etag is weak.

  to_header()

    Convert the etags set into a HTTP header string.

class werkzeug.datastructures.Authorization(auth_type, data=None)

  Represents an `Authorization` header sent by the client.

  This is returned by `parse_authorization_header()`. It can be useful to create the object manually to pass to the test `Client`.

  Changelog

  Changed in version 0.5: This object became immutable.

  property cnonce

    If 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.

  property nc

    The nonce count value transmitted by clients if a qop-header is also transmitted. HTTP digest auth only.

  property nonce

    The 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.

  property opaque

    The opaque header from the server returned unchanged by the client. It is recommended that this string be base64 or hexadecimal data. Digest auth only.

  property password

    When the authentication type is basic this is the password transmitted by the client, else None.

  property qop

    Indicates 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.

  property realm

    This is the server realm sent back for HTTP digest auth.

  property response

    A string of 32 hex digits computed as defined in RFC 2617, which proves that the user knows a password. Digest auth only.

  to_header()

    Convert to a string value for an `Authorization` header.

    Changelog

    New in version 2.0: Added to support passing authorization to the test client.

  property uri

    The URI from Request-URI of the Request-Line; duplicated because proxies are allowed to change the Request-Line in transit. HTTP digest auth only.

  property username

    The username transmitted. This is set for both basic and digest auth all the time.

class werkzeug.datastructures.WWWAuthenticate(auth_type=None, values=None, on_update=None)

  Provides simple access to WWW-Authenticate headers.

  property algorithm

    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).

  static auth_property(name, doc=None)

    A 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 (`realm` etc.) are implemented.

  property domain

    A 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.

  property nonce

    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.

  property opaque

    A 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.

  property qop

    A set of quality-of-privacy directives such as auth and auth-int.

  property realm

    A 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.

  set_basic(realm='authentication required')

    Clear the auth info and enable basic auth.

  set_digest(realm, nonce, qop=('auth',), opaque=None, algorithm=None, stale=False)

    Clear the auth info and enable digest auth.

  property stale

    A flag, indicating that the previous request from the client was rejected because the nonce value was stale.

  to_header()

    Convert the stored values into a WWW-Authenticate header.

  property type

    The type of the auth mechanism. HTTP currently specifies `Basic` and `Digest`.

class werkzeug.datastructures.IfRange(etag=None, date=None)

  Very 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.

  Changelog

  New in version 0.7.

  date

    The date in parsed format or None.

  etag

    The etag parsed and unquoted. Ranges always operate on strong etags so the weakness information is not necessary.

  to_header()

    Converts the object back into an HTTP header.

class werkzeug.datastructures.Range(units, ranges)

  Represents 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.

  Raises

    ValueError – If the ranges provided are invalid.

  Changelog

  Changed in version 0.15: The ranges passed in are validated.

  New in version 0.7.

  make_content_range(length)

    Creates a `ContentRange` object from the current range and given content length.

  range_for_length(length)

    If 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.

  ranges

    A list of `(begin, end)` tuples for the range header provided. The ranges are non-inclusive.

  to_content_range_header(length)

    Converts the object into Content-Range HTTP header, based on given length

  to_header()

    Converts the object back into an HTTP header.

  units

    The units of this range. Usually “bytes”.

class werkzeug.datastructures.ContentRange(units, start, stop, length=None, on_update=None)

  Represents the content range header.

  Changelog

  New in version 0.7.

  property length

    The length of the range or None.

  set(start, stop, length=None, units='bytes')

    Simple method to update the ranges.

  property start

    The start point of the range or None.

  property stop

    The stop point of the range (non-inclusive) or None. Can only be None if also start is None.

  property units

    The units to use, usually “bytes”

  unset()

    Sets the units to None which indicates that the header should no longer be used.

## Others

class werkzeug.datastructures.FileStorage(stream=None, filename=None, name=None, content_type=None, content_length=None, headers=None)

  The `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()`.

  stream

    The input stream for the uploaded file. This usually points to an open temporary file.

  filename

    The filename of the file on the client. Can be a `str`, or an instance of `os.PathLike`.

  name

    The name of the form field.

  headers

    The multipart headers as `Headers` object. This usually contains irrelevant information but in combination with custom multipart requests the raw headers might be interesting.

    Changelog

    New in version 0.6.

  close()

    Close the underlying file if possible.

  property content_length

    The content-length sent in the header. Usually not available

  property content_type

    The content-type sent in the header. Usually not available

  property mimetype

    Like `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'`.

    Changelog

    New in version 0.7.

  property mimetype_params

    The mimetype parameters as dict. For example if the content type is `text/html; charset=utf-8` the params would be `{'charset': 'utf-8'}`.

    Changelog

    New in version 0.7.

  save(dst, buffer_size=16384)

    Save 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 `secure_filename()`.

    Parameters

      - dst – a filename, `os.PathLike`, or open file object to write to.

      - buffer_size – Passed as the `length` parameter of `shutil.copyfileobj()`.

    Changelog

    Changed in version 1.0: Supports `pathlib`.