<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>4.7.2 Functions</title> <META NAME="description" CONTENT="4.7.2 Functions"> <META NAME="keywords" CONTENT="modpython"> <META NAME="resource-type" CONTENT="document"> <META NAME="distribution" CONTENT="global"> <link rel="STYLESHEET" href="modpython.css"> <link rel="first" href="modpython.html"> <link rel="contents" href="contents.html" title="Contents"> <link rel="index" href="genindex.html" title="Index"> <LINK REL="next" href="pyapi-cookie-example.html"> <LINK REL="previous" href="pyapi-cookie-classes.html"> <LINK REL="up" href="pyapi-cookie.html"> <LINK REL="next" href="pyapi-cookie-example.html"> </head> <body> <DIV CLASS="navigation"> <table align="center" width="100%" cellpadding="0" cellspacing="2"> <tr> <td><A href="pyapi-cookie-classes.html"><img src="icons/previous.png" border="0" height="32" alt="Previous Page" width="32"></A></td> <td><A href="pyapi-cookie.html"><img src="icons/up.png" border="0" height="32" alt="Up One Level" width="32"></A></td> <td><A href="pyapi-cookie-example.html"><img src="icons/next.png" border="0" height="32" alt="Next Page" width="32"></A></td> <td align="center" width="100%">Mod_python Manual</td> <td><A href="contents.html"><img src="icons/contents.png" border="0" height="32" alt="Contents" width="32"></A></td> <td><img src="icons/blank.png" border="0" height="32" alt="" width="32"></td> <td><A href="genindex.html"><img src="icons/index.png" border="0" height="32" alt="Index" width="32"></A></td> </tr></table> <b class="navlabel">Previous:</b> <a class="sectref" href="pyapi-cookie-classes.html">4.7.1 Classes</A> <b class="navlabel">Up:</b> <a class="sectref" href="pyapi-cookie.html">4.7 Cookie - HTTP</A> <b class="navlabel">Next:</b> <a class="sectref" href="pyapi-cookie-example.html">4.7.3 Examples</A> <br><hr> </DIV> <!--End of Navigation Panel--> <H2><A NAME="SECTION006720000000000000000"> </A> <BR> 4.7.2 Functions </H2> <P> <dl><dt><b><a name="l2h-187"><tt class="function">add_cookie</tt></a></b>(<var>req, cookie</var><big>[</big><var>, value, attributes</var><big>]</big>) <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: <dl><dd><pre class="verbatim"> c = Cookie.Cookie('spam', 'eggs', expires=time.time()+300) Cookie.add_cookie(req, c) </pre></dl> Here is another: <dl><dd><pre class="verbatim"> Cookie.add_cookie(req, 'spam', 'eggs', expires=time.time()+300) </pre></dl> </dl> <P> <dl><dt><b><a name="l2h-188"><tt class="function">get_cookies</tt></a></b>(<var>req </var><big>[</big><var>, Class, data</var><big>]</big>) <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>). </dl> <P> <DIV CLASS="navigation"> <p><hr> <table align="center" width="100%" cellpadding="0" cellspacing="2"> <tr> <td><A href="pyapi-cookie-classes.html"><img src="icons/previous.png" border="0" height="32" alt="Previous Page" width="32"></A></td> <td><A href="pyapi-cookie.html"><img src="icons/up.png" border="0" height="32" alt="Up One Level" width="32"></A></td> <td><A href="pyapi-cookie-example.html"><img src="icons/next.png" border="0" height="32" alt="Next Page" width="32"></A></td> <td align="center" width="100%">Mod_python Manual</td> <td><A href="contents.html"><img src="icons/contents.png" border="0" height="32" alt="Contents" width="32"></A></td> <td><img src="icons/blank.png" border="0" height="32" alt="" width="32"></td> <td><A href="genindex.html"><img src="icons/index.png" border="0" height="32" alt="Index" width="32"></A></td> </tr></table> <b class="navlabel">Previous:</b> <a class="sectref" href="pyapi-cookie-classes.html">4.7.1 Classes</A> <b class="navlabel">Up:</b> <a class="sectref" href="pyapi-cookie.html">4.7 Cookie - HTTP</A> <b class="navlabel">Next:</b> <a class="sectref" href="pyapi-cookie-example.html">4.7.3 Examples</A> <hr> <span class="release-info">Release 3.1.0a, documentation updated on August 26, 2003.</span> </DIV> <!--End of Navigation Panel--> </BODY> </HTML>