<!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-example.html" /> <link rel="prev" href="pyapi-cookie-classes.html" /> <link rel="parent" href="pyapi-cookie.html" /> <link rel="next" href="pyapi-cookie-example.html" /> <meta name='aesop' content='information' /> <title>4.7.2 Functions</title> </head> <body> <DIV CLASS="navigation"> <div id='top-navigation-panel' xml:id='top-navigation-panel'> <table align="center" width="100%" cellpadding="0" cellspacing="2"> <tr> <td class='online-navigation'><a rel="prev" title="4.7.1 Classes" href="pyapi-cookie-classes.html"><img src='previous.png' border='0' height='32' alt='Previous Page' width='32' /></A></td> <td class='online-navigation'><a rel="parent" title="4.7 Cookie - HTTP" href="pyapi-cookie.html"><img src='up.png' border='0' height='32' alt='Up One Level' width='32' /></A></td> <td class='online-navigation'><a rel="next" title="4.7.3 Examples" href="pyapi-cookie-example.html"><img src='next.png' border='0' height='32' alt='Next Page' width='32' /></A></td> <td align="center" width="100%">Mod_python Manual</td> <td class='online-navigation'><a rel="contents" title="Table of Contents" href="contents.html"><img src='contents.png' border='0' height='32' alt='Contents' width='32' /></A></td> <td class='online-navigation'><img src='blank.png' border='0' height='32' alt='' width='32' /></td> <td class='online-navigation'><a rel="index" title="Index" href="genindex.html"><img src='index.png' border='0' height='32' alt='Index' width='32' /></A></td> </tr></table> <div class='online-navigation'> <b class="navlabel">Previous:</b> <a class="sectref" rel="prev" href="pyapi-cookie-classes.html">4.7.1 Classes</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-example.html">4.7.3 Examples</A> </div> <hr /></div> </DIV> <!--End of Navigation Panel--> <H2><A NAME="SECTION006720000000000000000"></A><A NAME="pyapi-cookie-func"></A> <BR> 4.7.2 Functions </H2> <P> <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> <td><nobr><b><tt id='l2h-234' xml:id='l2h-234' class="function">add_cookie</tt></b>(</nobr></td> <td><var>req, cookie</var><big>[</big><var>, value, attributes</var><big>]</big><var></var>)</td></tr></table></dt> <dd> This is a convenience function for setting a cookie in request headers. <var>req</var> is a mod_python <tt class="class">Request</tt> object. If <var>cookie</var> is an instance of <tt class="class">Cookie</tt> (or subclass thereof), then the cookie is set, otherwise, <var>cookie</var> must be a string, in which case a <tt class="class">Cookie</tt> is constructed using <var>cookie</var> as name, <var>value</var> as the value, along with any valid <tt class="class">Cookie</tt> attributes specified as keyword arguments. <P> This function will also set "<tt class="samp">Cache-Control: no-cache="set-cookie"</tt>" header to inform caches that the cookie value should not be cached. <P> Here is one way to use this function: <div class="verbatim"><pre> c = Cookie.Cookie('spam', 'eggs', expires=time.time()+300) Cookie.add_cookie(req, c) </pre></div> Here is another: <div class="verbatim"><pre> Cookie.add_cookie(req, 'spam', 'eggs', expires=time.time()+300) </pre></div> </dl> <P> <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> <td><nobr><b><tt id='l2h-235' xml:id='l2h-235' class="function">get_cookies</tt></b>(</nobr></td> <td><var>req </var><big>[</big><var>, Class, data</var><big>]</big><var></var>)</td></tr></table></dt> <dd> This is a convenience function for retrieving cookies from incoming headers. <var>req</var> is a mod_python <tt class="class">Request</tt> object. <var>Class</var> is a class whose <tt class="method">parse()</tt> method will be used to parse the cookies, it defaults to <code>Cookie</code>. <var>Data</var> can be any number of keyword arguments which, will be passed to <tt class="method">parse()</tt> (This is useful for <tt class="class">signedCookie</tt> and <tt class="class">MarshalCookie</tt> which require <code>secret</code> as an additional argument to <tt class="method">parse</tt>). The set of cookies found is returned as a dictionary. </dl> <P> <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> <td><nobr><b><tt id='l2h-236' xml:id='l2h-236' class="function">get_cookie</tt></b>(</nobr></td> <td><var>req, name </var><big>[</big><var>, Class, data</var><big>]</big><var></var>)</td></tr></table></dt> <dd> This is a convenience function for retrieving a single named cookie from incoming headers. <var>req</var> is a mod_python <tt class="class">Request</tt> object. <var>name</var> is the name of the cookie. <var>Class</var> is a class whose <tt class="method">parse()</tt> method will be used to parse the cookies, it defaults to <code>Cookie</code>. <var>Data</var> can be any number of keyword arguments which, will be passed to <tt class="method">parse()</tt> (This is useful for <tt class="class">signedCookie</tt> and <tt class="class">MarshalCookie</tt> which require <code>secret</code> as an additional argument to <tt class="method">parse</tt>). The cookie if found is returned, otherwise <code>None</code> is returned. </dl> <P> <DIV CLASS="navigation"> <div class='online-navigation'> <p></p><hr /> <table align="center" width="100%" cellpadding="0" cellspacing="2"> <tr> <td class='online-navigation'><a rel="prev" title="4.7.1 Classes" href="pyapi-cookie-classes.html"><img src='previous.png' border='0' height='32' alt='Previous Page' width='32' /></A></td> <td class='online-navigation'><a rel="parent" title="4.7 Cookie - HTTP" href="pyapi-cookie.html"><img src='up.png' border='0' height='32' alt='Up One Level' width='32' /></A></td> <td class='online-navigation'><a rel="next" title="4.7.3 Examples" href="pyapi-cookie-example.html"><img src='next.png' border='0' height='32' alt='Next Page' width='32' /></A></td> <td align="center" width="100%">Mod_python Manual</td> <td class='online-navigation'><a rel="contents" title="Table of Contents" href="contents.html"><img src='contents.png' border='0' height='32' alt='Contents' width='32' /></A></td> <td class='online-navigation'><img src='blank.png' border='0' height='32' alt='' width='32' /></td> <td class='online-navigation'><a rel="index" title="Index" href="genindex.html"><img src='index.png' border='0' height='32' alt='Index' width='32' /></A></td> </tr></table> <div class='online-navigation'> <b class="navlabel">Previous:</b> <a class="sectref" rel="prev" href="pyapi-cookie-classes.html">4.7.1 Classes</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-example.html">4.7.3 Examples</A> </div> </div> <hr /> <span class="release-info">Release 3.3.1, documentation updated on January 29, 2007.</span> </DIV> <!--End of Navigation Panel--> </BODY> </HTML>