ASPN ActiveState Programmer Network
  ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups | Web Services
SEARCH

Reference
ActivePython 2.5
Python Documentation
Library Reference
18. Internet Protocols and Support
18.1 webbrowser -- Convenient Web-browser controller
18.2 cgi -- Common Gateway Interface support.
18.3 cgitb -- Traceback manager for CGI scripts
18.4 wsgiref -- WSGI Utilities and Reference Implementation
18.5 urllib -- Open arbitrary resources by URL
18.6 urllib2 -- extensible library for opening URLs
18.7 httplib -- HTTP protocol client
18.8 ftplib -- FTP protocol client
18.9 gopherlib -- Gopher protocol client
18.10 poplib -- POP3 protocol client
18.11 imaplib -- IMAP4 protocol client
18.12 nntplib -- NNTP protocol client
18.13 smtplib -- SMTP protocol client
18.14 smtpd -- SMTP Server
18.15 telnetlib -- Telnet client
18.16 uuid -- UUID objects according to RFC 4122
18.17 urlparse -- Parse URLs into components
18.18 SocketServer -- A framework for network servers
18.19 BaseHTTPServer -- Basic HTTP server
18.20 SimpleHTTPServer -- Simple HTTP request handler
18.21 CGIHTTPServer -- CGI-capable HTTP request handler
18.22 cookielib -- Cookie handling for HTTP clients
18.23 Cookie -- HTTP state management
18.23.1 Cookie Objects
18.23.2 Morsel Objects
18.23.3 Example
18.24 xmlrpclib -- XML-RPC client access
18.25 SimpleXMLRPCServer -- Basic XML-RPC server
18.26 DocXMLRPCServer -- Self-documenting XML-RPC server

MyASPN >> Reference >> ActivePython 2.5 >> Python Documentation >> Library Reference >> 18. Internet Protocols and Support
ActivePython 2.5 documentation

18.23 Cookie -- HTTP state management

The Cookie module defines classes for abstracting the concept of cookies, an HTTP state management mechanism. It supports both simple string-only cookies, and provides an abstraction for having any serializable data-type as cookie value.

The module formerly strictly applied the parsing rules described in the RFC 2109 and RFC 2068 specifications. It has since been discovered that MSIE 3.0x doesn't follow the character rules outlined in those specs. As a result, the parsing rules used are a bit less strict.

exception CookieError
Exception failing because of RFC 2109 invalidity: incorrect attributes, incorrect Set-Cookie: header, etc.

class BaseCookie( [input])
This class is a dictionary-like object whose keys are strings and whose values are Morsel instances. Note that upon setting a key to a value, the value is first converted to a Morsel containing the key and the value.

If input is given, it is passed to the load() method.

class SimpleCookie( [input])
This class derives from BaseCookie and overrides value_decode() and value_encode() to be the identity and str() respectively.

class SerialCookie( [input])
This class derives from BaseCookie and overrides value_decode() and value_encode() to be the pickle.loads() and pickle.dumps().

Deprecated since release 2.3. Reading pickled values from untrusted cookie data is a huge security hole, as pickle strings can be crafted to cause arbitrary code to execute on your server. It is supported for backwards compatibility only, and may eventually go away.

class SmartCookie( [input])
This class derives from BaseCookie. It overrides value_decode() to be pickle.loads() if it is a valid pickle, and otherwise the value itself. It overrides value_encode() to be pickle.dumps() unless it is a string, in which case it returns the value itself.

Deprecated since release 2.3. The same security warning from SerialCookie applies here.

A further security note is warranted. For backwards compatibility, the Cookie module exports a class named Cookie which is just an alias for SmartCookie. This is probably a mistake and will likely be removed in a future version. You should not use the Cookie class in your applications, for the same reason why you should not use the SerialCookie class.

See Also:

Module cookielib:
HTTP cookie handling for web clients. The cookielib and Cookie modules do not depend on each other.

RFC 2109, HTTP State Management Mechanism
This is the state management specification implemented by this module.



See About this document... for information on suggesting changes.

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState 2004 All rights reserved