<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
<link rel=
"STYLESHEET" href=
"lib.css" type='text/css'
/>
<link rel=
"SHORTCUT ICON" href=
"../icons/pyfav.png" type=
"image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index'
/>
<link rel=
"first" href=
"lib.html" title='Python Library Reference'
/>
<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=
"cookielib-examples.html" />
<link rel=
"prev" href=
"default-cookie-policy-objects.html" />
<link rel=
"parent" href=
"module-cookielib.html" />
<link rel=
"next" href=
"cookielib-examples.html" />
<meta name='aesop' content='information'
/>
<title>11.20.5 Cookie Objects
</title>
<div id='top-navigation-panel' xml:id='top-navigation-panel'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"11.20.4 DefaultCookiePolicy Objects"
href=
"default-cookie-policy-objects.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"11.20 cookielib "
href=
"module-cookielib.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"11.20.6 Examples"
href=
"cookielib-examples.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python Library Reference
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><a href=
"modindex.html" title=
"Module Index"><img src='../icons/modules.png'
border='
0' height='
32' alt='Module Index' width='
32'
/></a></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"default-cookie-policy-objects.html">11.20.4 DefaultCookiePolicy Objects
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"module-cookielib.html">11.20 cookielib
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"cookielib-examples.html">11.20.6 Examples
</A>
<!--End of Navigation Panel-->
<H2><A NAME=
"SECTION00132050000000000000000"></A><A NAME=
"cookie-jar-objects"></A>
<tt class=
"class">Cookie
</tt> instances have Python attributes roughly corresponding
to the standard cookie-attributes specified in the various cookie
standards. The correspondence is not one-to-one, because there are
complicated rules for assigning default values, and because the
<code>max-age
</code> and
<code>expires
</code> cookie-attributes contain equivalent
Assignment to these attributes should not be necessary other than in
rare circumstances in a
<tt class=
"class">CookiePolicy
</tt> method. The class does
not enforce internal consistency, so you should know what you're
<dl><dt><b><tt id='l2h-
3660' xml:id='l2h-
3660'
class=
"member">version
</tt></b></dt>
Integer or
<tt class=
"constant">None
</tt>. Netscape cookies have version
0. RFC
2965 and RFC
2109 cookies have version
1.
<dl><dt><b><tt id='l2h-
3661' xml:id='l2h-
3661'
class=
"member">name
</tt></b></dt>
<dl><dt><b><tt id='l2h-
3662' xml:id='l2h-
3662'
class=
"member">value
</tt></b></dt>
Cookie value (a string), or
<tt class=
"constant">None
</tt>.
<dl><dt><b><tt id='l2h-
3663' xml:id='l2h-
3663'
class=
"member">port
</tt></b></dt>
String representing a port or a set of ports (eg. '
80', or '
80,
8080'),
or
<tt class=
"constant">None
</tt>.
<dl><dt><b><tt id='l2h-
3664' xml:id='l2h-
3664'
class=
"member">path
</tt></b></dt>
Cookie path (a string, eg.
<code>'/acme/rocket_launchers'
</code>).
<dl><dt><b><tt id='l2h-
3665' xml:id='l2h-
3665'
class=
"member">secure
</tt></b></dt>
True if cookie should only be returned over a secure connection.
<dl><dt><b><tt id='l2h-
3666' xml:id='l2h-
3666'
class=
"member">expires
</tt></b></dt>
Integer expiry date in seconds since epoch, or
<tt class=
"constant">None
</tt>. See
also the
<tt class=
"method">is_expired()
</tt> method.
<dl><dt><b><tt id='l2h-
3667' xml:id='l2h-
3667'
class=
"member">discard
</tt></b></dt>
True if this is a session cookie.
<dl><dt><b><tt id='l2h-
3668' xml:id='l2h-
3668'
class=
"member">comment
</tt></b></dt>
String comment from the server explaining the function of this cookie,
or
<tt class=
"constant">None
</tt>.
<dl><dt><b><tt id='l2h-
3669' xml:id='l2h-
3669'
class=
"member">comment_url
</tt></b></dt>
URL linking to a comment from the server explaining the function of
this cookie, or
<tt class=
"constant">None
</tt>.
<dl><dt><b><tt id='l2h-
3670' xml:id='l2h-
3670'
class=
"member">port_specified
</tt></b></dt>
True if a port or set of ports was explicitly specified by the server
(in the
<span class=
"mailheader">Set-Cookie:
</span> /
<span class=
"mailheader">Set-Cookie2:
</span> header).
<dl><dt><b><tt id='l2h-
3671' xml:id='l2h-
3671'
class=
"member">domain_specified
</tt></b></dt>
True if a domain was explicitly specified by the server.
<dl><dt><b><tt id='l2h-
3672' xml:id='l2h-
3672'
class=
"member">domain_initial_dot
</tt></b></dt>
True if the domain explicitly specified by the server began with a
Cookies may have additional non-standard cookie-attributes. These may
be accessed using the following methods:
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
3673' xml:id='l2h-
3673'
class=
"method">has_nonstandard_attr
</tt></b>(
</nobr></td>
<td><var>name
</var>)
</td></tr></table></dt>
Return true if cookie has the named cookie-attribute.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
3674' xml:id='l2h-
3674'
class=
"method">get_nonstandard_attr
</tt></b>(
</nobr></td>
<td><var>name, default=
<tt class=
"constant">None
</tt></var>)
</td></tr></table></dt>
If cookie has the named cookie-attribute, return its value.
Otherwise, return
<var>default
</var>.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
3675' xml:id='l2h-
3675'
class=
"method">set_nonstandard_attr
</tt></b>(
</nobr></td>
<td><var>name, value
</var>)
</td></tr></table></dt>
Set the value of the named cookie-attribute.
The
<tt class=
"class">Cookie
</tt> class also defines the following method:
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
3676' xml:id='l2h-
3676'
class=
"method">is_expired
</tt></b>(
</nobr></td>
<td><var></var><big>[
</big><var>now=
<tt class=
"constant">None
</tt></var><big>]
</big><var></var>)
</td></tr></table></dt>
True if cookie has passed the time at which the server requested it
should expire. If
<var>now
</var> is given (in seconds since the epoch),
return whether the cookie has expired at the specified time.
<div class='online-navigation'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"11.20.4 DefaultCookiePolicy Objects"
href=
"default-cookie-policy-objects.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"11.20 cookielib "
href=
"module-cookielib.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"11.20.6 Examples"
href=
"cookielib-examples.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python Library Reference
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><a href=
"modindex.html" title=
"Module Index"><img src='../icons/modules.png'
border='
0' height='
32' alt='Module Index' width='
32'
/></a></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"default-cookie-policy-objects.html">11.20.4 DefaultCookiePolicy Objects
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"module-cookielib.html">11.20 cookielib
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"cookielib-examples.html">11.20.6 Examples
</A>
<span class=
"release-info">Release
2.4.2, documentation updated on
28 September
2005.
</span>
<!--End of Navigation Panel-->
See
<i><a href=
"about.html">About this document...
</a></i> for information on suggesting changes.