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

Class CookieMaker

source code

object --+
         |
        CookieMaker

Cookie maker helper class
Instance Methods [hide private]
 
UNSAFE_SEARCH(...)
Unsafe character search function
source code
D[k] if k in D, else d
_ATTR(D, k, d=...)
Attribute spelling and type getter
source code
 
__init__(self, codec=None)
Initialization
source code
str
__call__(self, name, value, **kwargs)
Create the cookie string
source code
 
_string(self, key, value)
String translator
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods [hide private]
 
_date(key, value)
Date translator
source code
 
_int(key, value)
Integer translator
source code
 
_bool(key, value)
Boolean translator
source code
 
_ustring(key, value)
Unquoted string translator
source code
Class Variables [hide private]
tuple KEYS = ('comment', 'domain', 'expires', 'max_age', 'path', 'se...
Valid attribute keys
Instance Variables [hide private]
callable _encode
Value encoder
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

UNSAFE_SEARCH(...)

source code 
Unsafe character search function

__init__(self, codec=None)
(Constructor)

source code 
Initialization
Parameters:
  • codec (CookieCodecInterface) - Cookie codec to apply. If unset or None, an identity codec is applied (leaving 8bit chars as-is)
Overrides: object.__init__

__call__(self, name, value, **kwargs)
(Call operator)

source code 

Create the cookie string

Cookie parameters are given in kwargs. Valid keys are listed in KEYS. None-values are ignored. Here are short descriptions of the valid parameters:

comment
Cookie comment (str)
domain
Valid domain (str)
expires
Expire time of the cookie (datetime.datetime). If unset or None the cookie is dropped when the browser is closed. See also the max_age keyword.
max_age
Max age of the cookie in seconds (int). If set, make sure it matches the expiry time. The difference is that expires will be transformed to a HTTP date, while max-age will stay an integer. The expires parameter is the older one and better understood by the clients out there. For that reason if you set max_age only, expires will be set automatically to now + max_age. If unset or None the cookie will be dropped when the browser is closed.
path
Valid URL base path for the cookie. It should always be set to a reasonable path (at least /), otherwise the cookie will only be valid for the current URL and below.
secure
Whether this is an SSL-only cookie or not (bool)
version
Cookie spec version (int). See RFC 2965
Parameters:
  • name (str) - Cookie name
  • value (str) - Cookie value (if a codec was given, the type should be applicable for the codec encoder).
  • kwargs (dict) - Cookie parameters
Returns: str
The cookie string
Raises:
  • ValueError - Invalid name or values given
  • TypeError - Unrecognized attributes given

Class Variable Details [hide private]

KEYS

Valid attribute keys
Type:
tuple
Value:
('comment',
 'domain',
 'expires',
 'max_age',
 'path',
 'secure',
 'version')