Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="default-cookie-policy-objects.html" /> | |
13 | <link rel="prev" href="file-cookie-jar-classes.html" /> | |
14 | <link rel="parent" href="module-cookielib.html" /> | |
15 | <link rel="next" href="default-cookie-policy-objects.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>11.20.3 CookiePolicy Objects </title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="11.20.2 FileCookieJar subclasses and" | |
25 | href="file-cookie-jar-classes.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="11.20 cookielib " | |
28 | href="module-cookielib.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="11.20.4 DefaultCookiePolicy Objects" | |
31 | href="default-cookie-policy-objects.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="file-cookie-jar-classes.html">11.20.2 FileCookieJar subclasses and</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="module-cookielib.html">11.20 cookielib </A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="default-cookie-policy-objects.html">11.20.4 DefaultCookiePolicy Objects</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H2><A NAME="SECTION00132030000000000000000"></A><A NAME="cookie-policy-objects"></A> | |
56 | <BR> | |
57 | 11.20.3 CookiePolicy Objects | |
58 | </H2> | |
59 | ||
60 | <P> | |
61 | Objects implementing the <tt class="class">CookiePolicy</tt> interface have the | |
62 | following methods: | |
63 | ||
64 | <P> | |
65 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
66 | <td><nobr><b><tt id='l2h-3636' xml:id='l2h-3636' class="method">set_ok</tt></b>(</nobr></td> | |
67 | <td><var>cookie, request</var>)</td></tr></table></dt> | |
68 | <dd> | |
69 | Return boolean value indicating whether cookie should be accepted from server. | |
70 | ||
71 | <P> | |
72 | <var>cookie</var> is a <tt class="class">cookielib.Cookie</tt> instance. <var>request</var> is | |
73 | an object implementing the interface defined by the documentation for | |
74 | <tt class="method">CookieJar.extract_cookies()</tt>. | |
75 | </dl> | |
76 | ||
77 | <P> | |
78 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
79 | <td><nobr><b><tt id='l2h-3637' xml:id='l2h-3637' class="method">return_ok</tt></b>(</nobr></td> | |
80 | <td><var>cookie, request</var>)</td></tr></table></dt> | |
81 | <dd> | |
82 | Return boolean value indicating whether cookie should be returned to server. | |
83 | ||
84 | <P> | |
85 | <var>cookie</var> is a <tt class="class">cookielib.Cookie</tt> instance. <var>request</var> is | |
86 | an object implementing the interface defined by the documentation for | |
87 | <tt class="method">CookieJar.add_cookie_header()</tt>. | |
88 | </dl> | |
89 | ||
90 | <P> | |
91 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
92 | <td><nobr><b><tt id='l2h-3638' xml:id='l2h-3638' class="method">domain_return_ok</tt></b>(</nobr></td> | |
93 | <td><var>domain, request</var>)</td></tr></table></dt> | |
94 | <dd> | |
95 | Return false if cookies should not be returned, given cookie domain. | |
96 | ||
97 | <P> | |
98 | This method is an optimization. It removes the need for checking | |
99 | every cookie with a particular domain (which might involve reading | |
100 | many files). Returning true from <tt class="method">domain_return_ok()</tt> and | |
101 | <tt class="method">path_return_ok()</tt> leaves all the work to <tt class="method">return_ok()</tt>. | |
102 | ||
103 | <P> | |
104 | If <tt class="method">domain_return_ok()</tt> returns true for the cookie domain, | |
105 | <tt class="method">path_return_ok()</tt> is called for the cookie path. Otherwise, | |
106 | <tt class="method">path_return_ok()</tt> and <tt class="method">return_ok()</tt> are never called | |
107 | for that cookie domain. If <tt class="method">path_return_ok()</tt> returns true, | |
108 | <tt class="method">return_ok()</tt> is called with the <tt class="class">Cookie</tt> object itself | |
109 | for a full check. Otherwise, <tt class="method">return_ok()</tt> is never called for | |
110 | that cookie path. | |
111 | ||
112 | <P> | |
113 | Note that <tt class="method">domain_return_ok()</tt> is called for every | |
114 | <em>cookie</em> domain, not just for the <em>request</em> domain. For | |
115 | example, the function might be called with both <code>".example.com"</code> | |
116 | and <code>"www.example.com"</code> if the request domain is | |
117 | <code>"www.example.com"</code>. The same goes for | |
118 | <tt class="method">path_return_ok()</tt>. | |
119 | ||
120 | <P> | |
121 | The <var>request</var> argument is as documented for <tt class="method">return_ok()</tt>. | |
122 | </dl> | |
123 | ||
124 | <P> | |
125 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
126 | <td><nobr><b><tt id='l2h-3639' xml:id='l2h-3639' class="method">path_return_ok</tt></b>(</nobr></td> | |
127 | <td><var>path, request</var>)</td></tr></table></dt> | |
128 | <dd> | |
129 | Return false if cookies should not be returned, given cookie path. | |
130 | ||
131 | <P> | |
132 | See the documentation for <tt class="method">domain_return_ok()</tt>. | |
133 | </dl> | |
134 | ||
135 | <P> | |
136 | In addition to implementing the methods above, implementations of the | |
137 | <tt class="class">CookiePolicy</tt> interface must also supply the following | |
138 | attributes, indicating which protocols should be used, and how. All | |
139 | of these attributes may be assigned to. | |
140 | ||
141 | <P> | |
142 | <dl><dt><b><tt id='l2h-3640' xml:id='l2h-3640' class="member">netscape</tt></b></dt> | |
143 | <dd> | |
144 | Implement Netscape protocol. | |
145 | </dl> | |
146 | <dl><dt><b><tt id='l2h-3641' xml:id='l2h-3641' class="member">rfc2965</tt></b></dt> | |
147 | <dd> | |
148 | Implement RFC 2965 protocol. | |
149 | </dl> | |
150 | <dl><dt><b><tt id='l2h-3642' xml:id='l2h-3642' class="member">hide_cookie2</tt></b></dt> | |
151 | <dd> | |
152 | Don't add <span class="mailheader">Cookie2:</span> header to requests (the presence of | |
153 | this header indicates to the server that we understand RFC 2965 | |
154 | cookies). | |
155 | </dl> | |
156 | ||
157 | <P> | |
158 | The most useful way to define a <tt class="class">CookiePolicy</tt> class is by | |
159 | subclassing from <tt class="class">DefaultCookiePolicy</tt> and overriding some or | |
160 | all of the methods above. <tt class="class">CookiePolicy</tt> itself may be used as | |
161 | a 'null policy' to allow setting and receiving any and all cookies | |
162 | (this is unlikely to be useful). | |
163 | ||
164 | <P> | |
165 | ||
166 | <DIV CLASS="navigation"> | |
167 | <div class='online-navigation'> | |
168 | <p></p><hr /> | |
169 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
170 | <tr> | |
171 | <td class='online-navigation'><a rel="prev" title="11.20.2 FileCookieJar subclasses and" | |
172 | href="file-cookie-jar-classes.html"><img src='../icons/previous.png' | |
173 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
174 | <td class='online-navigation'><a rel="parent" title="11.20 cookielib " | |
175 | href="module-cookielib.html"><img src='../icons/up.png' | |
176 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
177 | <td class='online-navigation'><a rel="next" title="11.20.4 DefaultCookiePolicy Objects" | |
178 | href="default-cookie-policy-objects.html"><img src='../icons/next.png' | |
179 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
180 | <td align="center" width="100%">Python Library Reference</td> | |
181 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
182 | href="contents.html"><img src='../icons/contents.png' | |
183 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
184 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
185 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
186 | <td class='online-navigation'><a rel="index" title="Index" | |
187 | href="genindex.html"><img src='../icons/index.png' | |
188 | border='0' height='32' alt='Index' width='32' /></A></td> | |
189 | </tr></table> | |
190 | <div class='online-navigation'> | |
191 | <b class="navlabel">Previous:</b> | |
192 | <a class="sectref" rel="prev" href="file-cookie-jar-classes.html">11.20.2 FileCookieJar subclasses and</A> | |
193 | <b class="navlabel">Up:</b> | |
194 | <a class="sectref" rel="parent" href="module-cookielib.html">11.20 cookielib </A> | |
195 | <b class="navlabel">Next:</b> | |
196 | <a class="sectref" rel="next" href="default-cookie-policy-objects.html">11.20.4 DefaultCookiePolicy Objects</A> | |
197 | </div> | |
198 | </div> | |
199 | <hr /> | |
200 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
201 | </DIV> | |
202 | <!--End of Navigation Panel--> | |
203 | <ADDRESS> | |
204 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
205 | </ADDRESS> | |
206 | </BODY> | |
207 | </HTML> |