# HTTP Utilties

You can import all these objects directly from :mod:werkzeug.

## Date Functions

The following functions simplify working with times in an HTTP context. Werkzeug uses offset-naive :class:~datetime.datetime objects internally that store the time in UTC. If you're working with timezones in your application make sure to replace the tzinfo attribute with a UTC timezone information before processing the values.

## Form Data Parsing

Werkzeug provides the form parsing functions separately from the request object so that you can access form data from a plain WSGI environment.

The following formats are supported by the form data parser currently:

• application/x-www-form-urlencoded
• multipart/form-data

Nested multipart is currently not supported (Werkzeug 0.6) albeit unused by any of the modern webbrowsers.

Usage example:

>>> from cStringIO import StringIO
>>> data = '--foo\r\nContent-Disposition: form-data; name="test"\r\n' \
... '\r\nHello World!\r\n--foo--'
>>> environ = {'wsgi.input': StringIO(data), 'CONTENT_LENGTH': str(len(data)),
...            'CONTENT_TYPE': 'multipart/form-data; boundary=foo',
...            'REQUEST_METHOD': 'POST'}
>>> stream, form, files = parse_form_data(environ)
''
>>> form['test']
u'Hello World!'
>>> not files
True


Normally the WSGI environment is provided by the WSGI gateway with the incoming data as part of it. If you want to generate such fake-WSGI environments for unittesting you might want to use the :func:create_environ function or the :class:EnvironBuilder instead.

The following functions can be used to parse incoming HTTP headers. Because Python does not provide data structures with the semantics required by RFC 2616, Werkzeug implements some custom data structures that are :ref:documented separately <http-datastructures>_.