|
Server : Apache/2.2.2 (Fedora) System : Linux App1.pathumtani.go.th 2.6.20-1.2320.fc5smp #1 SMP Tue Jun 12 19:40:16 EDT 2007 i686 User : apache ( 48) PHP Version : 5.2.9 Disable Function : NONE Directory : /var/www/manual/mod/mod_python/ |
Upload File : |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="modpython.css" type='text/css'>
<link rel="first" href="modpython.html" title='Mod_python Manual'>
<link rel='contents' href='contents.html' title="Contents">
<link rel='index' href='genindex.html' title='Index'>
<link rel='last' href='about.html' title='About this document...'>
<link rel='help' href='about.html' title='About this document...'>
<LINK REL="next" href="pyapi-cookie-func.html">
<LINK REL="prev" href="pyapi-cookie.html">
<LINK REL="parent" href="pyapi-cookie.html">
<LINK REL="next" href="pyapi-cookie-func.html">
<meta name='aesop' content='information'>
<META NAME="description" CONTENT="Classes">
<META NAME="keywords" CONTENT="modpython">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<title>4.7.1 Classes</title>
</head>
<body>
<DIV CLASS="navigation">
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><a rel="prev" title="4.7 Cookie - HTTP"
href="pyapi-cookie.html"><img src='previous.gif'
border='0' height='32' alt='Previous Page' width='32'></A></td>
<td><a rel="parent" title="4.7 Cookie - HTTP"
href="pyapi-cookie.html"><img src='up.gif'
border='0' height='32' alt='Up One Level' width='32'></A></td>
<td><a rel="next" title="4.7.2 Functions"
href="pyapi-cookie-func.html"><img src='next.gif'
border='0' height='32' alt='Next Page' width='32'></A></td>
<td align="center" width="100%">Mod_python Manual</td>
<td><a rel="contents" title="Table of Contents"
href="contents.html"><img src='contents.gif'
border='0' height='32' alt='Contents' width='32'></A></td>
<td><img src='blank.gif'
border='0' height='32' alt='' width='32'></td>
<td><a rel="index" title="Index"
href="genindex.html"><img src='index.gif'
border='0' height='32' alt='Index' width='32'></A></td>
</tr></table>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="pyapi-cookie.html">4.7 Cookie - HTTP</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="pyapi-cookie.html">4.7 Cookie - HTTP</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="pyapi-cookie-func.html">4.7.2 Functions</A>
<br><hr>
</DIV>
<!--End of Navigation Panel-->
<H2><A NAME="SECTION006710000000000000000"> </A>
<BR>
4.7.1 Classes
</H2>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><span class="typelabel">class</span> <a name="l2h-200"><tt class="class">Cookie</tt></a></b>(</nobr></td>
<td><var>name, value</var><big>[</big><var>, attributes</var><big>]</big>)</td></tr></table>
<dd>
<P>
This class is used to construct a single cookie named <var>name</var>
and having <var>value</var> as the value. Additionally, any of the
attributes defined in the Netscape specification and RFC2109 can by
supplied as keyword arguments.
<P>
The attributes of the class represent cookie attributes, and their
string representations become part of the string representation of
the cookie. The <tt class="class">Cookie</tt> class restricts attribute names to
only valid values, specifically, only the following attributes are
allowed: <code>name, value, version, path, domain, secure, comment,
expires, max_age, commentURL, discard, port, __data__</code>.
<P>
The <code>__data__</code> attribute is a general-purpose dictionary that
can be used for storing arbitrary values, when necessary (This is
useful when subclassing <tt class="class">Cookie</tt>).
<P>
The <tt class="member">expires</tt> attribute is a property whose value is checked
upon setting to be in format "<tt class="samp">Wdy, DD-Mon-YYYY HH:MM:SS GMT</tt>" (as dictated per Netscape cookie specification), or a numeric value
representing time in seconds since beginning of epoch (which will be
automatically correctly converted to GMT time string). An invalid
<code>expires</code> value will raise <tt class="exception">ValueError</tt>.
<P>
When converted to a string, a <tt class="class">Cookie</tt> will be in correct
format usable as value in a "<tt class="samp">Cookie</tt>" or "<tt class="samp">Set-Cookie</tt>" header.
<P>
<div class="note"><b class="label">Note:</b>
Unlike the Python Standard Library Cookie classes, this
class represents a single cookie (referred to as <i class="dfn">Morsel</i> in
Python Standard Library).
</div>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><a name="l2h-201"><tt class="method">parse</tt></a></b>(</nobr></td>
<td><var>string</var>)</td></tr></table>
<dd>
This is a class method that can be used to create a <tt class="class">Cookie</tt>
instance from a cookie string <var>string</var> as passed in a header
value. During parsing, attribute names are converted to lower
case.
<P>
Because this is a class method, it must be called explicitly
specifying the class.
<P>
This method returns a dictionary of <tt class="class">Cookie</tt> instances, not
a single <tt class="class">Cookie</tt> instance.
<P>
Here is an example of getting a single <tt class="class">Cookie</tt> instance:
<div class="verbatim"><pre>
mycookies = Cookie.parse("spam=eggs; expires=Sat, 14-Jun-2003 02:42:36 GMT")
spamcookie = mycookies["spam"]
</pre></div>
<P>
<div class="note"><b class="label">Note:</b>
Because this method uses a dictionary, it is not possible to
have duplicate cookies. If you would like to have more than one
value in a single cookie, consider using a <tt class="class">MarshalCookie</tt>.
</div>
<P>
</dl>
<P>
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><span class="typelabel">class</span> <a name="l2h-202"><tt class="class">SignedCookie</tt></a></b>(</nobr></td>
<td><var>name, value, secret</var><big>[</big><var>, attributes</var><big>]</big>)</td></tr></table>
<dd>
<P>
This is a subclass of <tt class="class">Cookie</tt>. This class creates cookies
whose name and value are automatically signed using HMAC (md5) with
a provided secret <var>secret</var>, which must be a non-empty string.
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><a name="l2h-203"><tt class="method">parse</tt></a></b>(</nobr></td>
<td><var>string, secret</var>)</td></tr></table>
<dd>
This method acts the same way as <tt class="class">Cookie.parse()</tt>, but also
verifies that the cookie is correctly signed. If the signature
cannot be verified, the object returned will be of class
<tt class="class">Cookie</tt>.
<P>
<div class="note"><b class="label">Note:</b>
Always check the types of objects returned by
<tt class="method">SignedCookie.parse()</tt>.If it is an instance of
<tt class="class">Cookie</tt> (as opposed to <tt class="class">SignedCookie</tt>), the
signature verification has failed:
<div class="verbatim"><pre>
# assume spam is supposed to be a signed cookie
if type(spam) is not Cookie.SignedCookie:
# do something that indicates cookie isn't signed correctly
</pre></div>
</div>
</dl>
<P>
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><span class="typelabel">class</span> <a name="l2h-204"><tt class="class">MarshalCookie</tt></a></b>(</nobr></td>
<td><var>name, value, secret</var><big>[</big><var>, attributes</var><big>]</big>)</td></tr></table>
<dd>
<P>
This is a subclass of <tt class="class">SignedCookie</tt>. It allows for
<var>value</var> to be any marshallable objects. Core Python types such as
string, integer, list, etc. are all marshallable object. For a
complete list see
<em class="citetitle"><a
href="http://www.python.org/doc/current/lib/module-marshal.html"
title="marshal"
>marshal</a></em>
module documentation.
<P>
When parsing, the signature is checked first, so incorrectly signed cookies
will not be unmarshalled.
<P>
</dl>
<P>
<DIV CLASS="navigation">
<p><hr>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><a rel="prev" title="4.7 Cookie - HTTP"
rel="prev" title="4.7 Cookie - HTTP"
href="pyapi-cookie.html"><img src='previous.gif'
border='0' height='32' alt='Previous Page' width='32'></A></td>
<td><a rel="parent" title="4.7 Cookie - HTTP"
rel="parent" title="4.7 Cookie - HTTP"
href="pyapi-cookie.html"><img src='up.gif'
border='0' height='32' alt='Up One Level' width='32'></A></td>
<td><a rel="next" title="4.7.2 Functions"
rel="next" title="4.7.2 Functions"
href="pyapi-cookie-func.html"><img src='next.gif'
border='0' height='32' alt='Next Page' width='32'></A></td>
<td align="center" width="100%">Mod_python Manual</td>
<td><a rel="contents" title="Table of Contents"
rel="contents" title="Table of Contents"
href="contents.html"><img src='contents.gif'
border='0' height='32' alt='Contents' width='32'></A></td>
<td><img src='blank.gif'
border='0' height='32' alt='' width='32'></td>
<td><a rel="index" title="Index"
rel="index" title="Index"
href="genindex.html"><img src='index.gif'
border='0' height='32' alt='Index' width='32'></A></td>
</tr></table>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="pyapi-cookie.html">4.7 Cookie - HTTP</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="pyapi-cookie.html">4.7 Cookie - HTTP</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="pyapi-cookie-func.html">4.7.2 Functions</A>
<hr>
<span class="release-info">Release 3.2.8, documentation updated on February 19, 2006.</span>
</DIV>
<!--End of Navigation Panel-->
</BODY>
</HTML>