Package wtf :: Module httputil
[hide private]
[frames] | no frames]

Module httputil

source code

This module implements various common HTTP utilities.


Author: André Malo

Classes [hide private]
  HeaderError
Base header parse error
  InvalidHeaderLine
A header line is invalid
  IncompleteHeaders
The headers are incomplete
  CookieCodecInterface
Interface for Cookie codecs
  CookieMaker
Cookie maker helper class
Functions [hide private]
str
make_date(stamp=None, cookie=False)
Make a HTTP date
source code
dict
read_headers(stream)
Read MIME headers from stream
source code
str
make_cookie(name, value, codec=None, **kwargs)
Make a cookie
source code
Variables [hide private]
str CR = '\r'
ASCII CR byte (r)
str LF = '\n'
ASCII LF byte (n)
str CRLF = '\r\n'
ASCII CRLF sequence (rn)
  __package__ = 'wtf'
Function Details [hide private]

make_date(stamp=None, cookie=False)

source code 
Make a HTTP date
Parameters:
  • stamp (datetime.datetime) - The UTC timestamp to process. If omitted or None, the current time is taken
Returns: str
The HTTP date string

read_headers(stream)

source code 
Read MIME headers from stream
Parameters:
  • stream (file) - The stream to read from
Returns: dict
Dictionary of lists of headers ({'name': ['val', ...], ...})
Raises:

make_cookie(name, value, codec=None, **kwargs)

source code 

Make a cookie

The is a simple interface to the CookieMaker class. See there for detailed information.

Parameters:
  • name (str) - Cookie name
  • value (str) - Cookie value
  • codec (CookieCodecInterface) - Value codec. If unset or None, the identity codec is applied.
  • kwargs (dict) - Cookie attributes
Returns: str
The cookie string
Raises:
  • ValueError - Invalid name or values given
  • TypeError - Unrecognized attributes given