pesto.httputils API documention

pesto.httputils

Utility functions to handle HTTP data

class pesto.httputils.FileUpload(filename, headers, fileob)

Represent a file uploaded in an HTTP form submission

save(fileob)

Save the upload to the file object or path fileob

Parameters:fileob – a file-like object open for writing, or the path to the file to be written
class pesto.httputils.HTTPMessage

Represent HTTP request message headers

exception pesto.httputils.MissingContentLength

No Content-Length header given

response()

Return a pesto.response.Response object to represent this error condition

exception pesto.httputils.RequestParseError

Error encountered while parsing the HTTP request

response()

Return a pesto.response.Response object to represent this error condition

exception pesto.httputils.TooBig

Request body is too big

response()

Return a pesto.response.Response object to represent this error condition

pesto.httputils.dequote(s)

Return s with surrounding quotes removed. Example usage:

>>> dequote('foo')
'foo'
>>> dequote('"foo"')
'foo'
pesto.httputils.parse_header(header)

Given a header, return a tuple of (value, [(parameter_name, parameter_value)]).

Example usage:

>>> parse_header("text/html; charset=UTF-8")
('text/html', {'charset': 'UTF-8'})
>>> parse_header("multipart/form-data; boundary=---------------------------7d91772e200be")
('multipart/form-data', {'boundary': '---------------------------7d91772e200be'})
pesto.httputils.parse_multipart(fp, boundary, default_charset, max_size)

Parse data encoded as multipart/form-data. Generate tuples of:

(<field-name>, <data>)

Where data will be a string in the case of a regular input field, or a FileUpload instance if a file was uploaded.

Parameters:
  • fp – input stream from which to read data
  • boundary – multipart boundary string, as specified by the Content-Disposition header
  • default_charset – character set to use for encoding, if not specified by a content-type header. In practice web browsers don’t supply a content-type header so this needs to contain a sensible value.
  • max_size – Maximum size in bytes for any non file upload part
pesto.httputils.parse_post(environ, fp, default_charset=None, max_size=16384, max_multipart_size=2097152)

Parse the contents of an HTTP POST request, which may be either application/x-www-form-urlencoded or multipart/form-data encoded.

Returned items are either tuples of (name, value) for simple string values or (name, FileUpload) for uploaded files.

Parameters:
  • max_multipart_size – Maximum size of total data for a multipart form submission
  • max_size – The maximum size of data allowed to be read into memory. For a application/x-www-form-urlencoded submission, this is the maximum size of the entire data. For a multipart/form-data submission, this is the maximum size of any individual field (except file uploads).
pesto.httputils.parse_querystring(data, charset=None, strict=False, keep_blank_values=True, pairsplitter=<built-in method split of _sre.SRE_Pattern object at 0x80519c530>)

Return (key, value) pairs from the given querystring:

>>> list(parse_querystring('green%20eggs=ham;me=sam+i+am'))
[(u'green eggs', u'ham'), (u'me', u'sam i am')]
Parameters:
  • charset – Character encoding used to decode values. If not specified, pesto.DEFAULT_CHARSET will be used.
  • keep_blank_values – if True, keys without associated values will be returned as empty strings. if False, no key, value pair will be returned.
  • strict – if True, a ValueError will be raised on parsing errors.

Table Of Contents

Previous topic

Session storage

Next topic

pesto.wsgiutils API documention

This Page