Package cherrypy :: Package lib :: Module httputil
[hide private]
[frames] | no frames]

Module httputil

source code

HTTP library functions.

This module contains functions for building an HTTP application framework: any one, not just one whose name starts with "Ch". ;) If you reference any modules from some popular framework inside *this* module, FuManChu will personally hang you up by your thumbs and submit you to a public caning.

Classes [hide private]
  HeaderElement
An element (with parameters) from an HTTP header's element list.
  AcceptElement
An element (with parameters) from an Accept* header's element list.
  CaseInsensitiveDict
A case-insensitive dict subclass.
  HeaderMap
A dict subclass for HTTP request and response headers.
  Host
An internet address.
Functions [hide private]
 
urljoin(*atoms)
Return the given path \*atoms, joined into a single URL.
source code
 
urljoin_bytes(*atoms)
Return the given path *atoms, joined into a single URL.
source code
 
protocol_from_http(protocol_str)
Return a protocol tuple from the given 'HTTP/x.y' string.
source code
 
get_ranges(headervalue, content_length)
Return a list of (start, stop) indices from a Range header, or None.
source code
 
header_elements(fieldname, fieldvalue)
Return a sorted HeaderElement list from a comma-separated header string.
source code
 
decode_TEXT(value)
Decode :rfc:`2047` TEXT (e.g.
source code
 
valid_status(status)
Return legal HTTP status Code, Reason-phrase and Message.
source code
 
_parse_qs(qs, keep_blank_values=0, strict_parsing=0, encoding='utf-8')
Parse a query given as a string argument.
source code
 
parse_query_string(query_string, keep_blank_values=True, encoding='utf-8')
Build a params dictionary from a query_string.
source code
Variables [hide private]
  response_codes = {100: ('Continue', 'Request received, please ...
  q_separator = re.compile(r'; *q *=')
  image_map_pattern = re.compile(r'[0-9]+,[0-9]+')
  header_translate_table = '\x00\x01\x02\x03\x04\x05\x06\x07\x08...
  header_translate_deletechars = '\x00\x01\x02\x03\x04\x05\x06\x...
  __package__ = 'cherrypy.lib'
  i = 31
Function Details [hide private]

urljoin(*atoms)

source code 

Return the given path \*atoms, joined into a single URL.

This will correctly join a SCRIPT_NAME and PATH_INFO into the original URL, even if either atom is blank.

urljoin_bytes(*atoms)

source code 

Return the given path *atoms, joined into a single URL.

This will correctly join a SCRIPT_NAME and PATH_INFO into the original URL, even if either atom is blank.

get_ranges(headervalue, content_length)

source code 

Return a list of (start, stop) indices from a Range header, or None.

Each (start, stop) tuple will be composed of two ints, which are suitable for use in a slicing operation. That is, the header "Range: bytes=3-6", if applied against a Python string, is requesting resource[3:7]. This function will return the list [(3, 7)].

If this function returns an empty list, you should return HTTP 416.

decode_TEXT(value)

source code 

Decode :rfc:`2047` TEXT (e.g. "=?utf-8?q?f=C3=BCr?=" -> "f\xfcr").

valid_status(status)

source code 

Return legal HTTP status Code, Reason-phrase and Message.

The status arg must be an int, or a str that begins with an int.

If status is an int, or a str and no reason-phrase is supplied, a default reason-phrase will be provided.

_parse_qs(qs, keep_blank_values=0, strict_parsing=0, encoding='utf-8')

source code 
Parse a query given as a string argument.

Arguments:

qs: URL-encoded query string to be parsed

keep_blank_values: flag indicating whether blank values in
    URL encoded queries should be treated as blank strings.  A
    true value indicates that blanks should be retained as blank
    strings.  The default false value indicates that blank values
    are to be ignored and treated as if they were  not included.

strict_parsing: flag indicating what to do with parsing errors. If
    false (the default), errors are silently ignored. If true,
    errors raise a ValueError exception.

Returns a dict, as G-d intended.

parse_query_string(query_string, keep_blank_values=True, encoding='utf-8')

source code 

Build a params dictionary from a query_string.

Duplicate key/value pairs in the provided query_string will be returned as {'key': [val1, val2, ...]}. Single key/values will be returned as strings: {'key': 'value'}.


Variables Details [hide private]

response_codes

Value:
{100: ('Continue', 'Request received, please continue'),
 101: ('Switching Protocols',
       'Switching to new protocol; obey Upgrade header'),
 200: ('OK', 'Request fulfilled, document follows'),
 201: ('Created', 'Document created, URL follows'),
 202: ('Accepted', 'Request accepted, processing continues off-line'),
 203: ('Non-Authoritative Information',
       'Request fulfilled from cache'),
...

header_translate_table

Value:
'''\x00\x01\x02\x03\x04\x05\x06\x07\x08\t
\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\
\x1d\x1e\x1f !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWX\
YZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x8\
6\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\\
x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa\
9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\\
xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xc\
...

header_translate_deletechars

Value:
'''\x00\x01\x02\x03\x04\x05\x06\x07\x08\t
\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\
\x1d\x1e\x1f\x7f'''