Mercurial > cpython-lru_cache-weakref
annotate Doc/lib/libcookie.tex @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | bea92c3d77a3 |
| children | 5ca7072361bd |
| rev | line source |
|---|---|
|
14071
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
1 \section{\module{Cookie} --- |
| 14075 | 2 HTTP state management} |
| 3 | |
|
14071
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
4 \declaremodule{standard}{Cookie} |
| 14075 | 5 \modulesynopsis{Support for HTTP state management (cookies).} |
|
14071
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
6 \moduleauthor{Timothy O'Malley}{timo@alum.mit.edu} |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
7 \sectionauthor{Moshe Zadka}{moshez@zadka.site.co.il} |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
8 |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
9 |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
10 The \module{Cookie} module defines classes for abstracting the concept of |
|
15800
3a260274bcc6
SourceForge patch #103140, checked in at fdrake's invitation. Minor fixes and
Eric S. Raymond <esr@thyrsus.com>
parents:
14093
diff
changeset
|
11 cookies, an HTTP state management mechanism. It supports both simple |
|
14071
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
12 string-only cookies, and provides an abstraction for having any serializable |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
13 data-type as cookie value. |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
14 |
|
14093
ec6a0b4a6479
Strengthen the warning against using SerialCookie and SmartCookie.
Andrew M. Kuchling <amk@amk.ca>
parents:
14075
diff
changeset
|
15 The module formerly strictly applied the parsing rules described in in |
|
ec6a0b4a6479
Strengthen the warning against using SerialCookie and SmartCookie.
Andrew M. Kuchling <amk@amk.ca>
parents:
14075
diff
changeset
|
16 the \rfc{2109} and \rfc{2068} specifications. It has since been discovered |
|
ec6a0b4a6479
Strengthen the warning against using SerialCookie and SmartCookie.
Andrew M. Kuchling <amk@amk.ca>
parents:
14075
diff
changeset
|
17 that MSIE 3.0x doesn't follow the character rules outlined in those |
|
ec6a0b4a6479
Strengthen the warning against using SerialCookie and SmartCookie.
Andrew M. Kuchling <amk@amk.ca>
parents:
14075
diff
changeset
|
18 specs. As a result, the parsing rules used are a bit less strict. |
|
14071
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
19 |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
20 \begin{excdesc}{CookieError} |
| 14075 | 21 Exception failing because of \rfc{2109} invalidity: incorrect |
| 22 attributes, incorrect \code{Set-Cookie} header, etc. | |
|
14071
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
23 \end{excdesc} |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
24 |
| 14075 | 25 \begin{classdesc}{BaseCookie}{\optional{input}} |
|
14071
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
26 This class is a dictionary-like object whose keys are strings and |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
27 whose values are \class{Morsel}s. Note that upon setting a key to |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
28 a value, the value is first converted to a \class{Morsel} containing |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
29 the key and the value. |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
30 |
|
18345
0200cd22492e
Removed some stray periods, and fix up a number of visible markup
Fred Drake <fdrake@acm.org>
parents:
15981
diff
changeset
|
31 If \var{input} is given, it is passed to the \method{load()} method. |
|
14071
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
32 \end{classdesc} |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
33 |
| 14075 | 34 \begin{classdesc}{SimpleCookie}{\optional{input}} |
|
18345
0200cd22492e
Removed some stray periods, and fix up a number of visible markup
Fred Drake <fdrake@acm.org>
parents:
15981
diff
changeset
|
35 This class derives from \class{BaseCookie} and overrides |
|
0200cd22492e
Removed some stray periods, and fix up a number of visible markup
Fred Drake <fdrake@acm.org>
parents:
15981
diff
changeset
|
36 \method{value_decode()} and \method{value_encode()} to be the identity |
|
0200cd22492e
Removed some stray periods, and fix up a number of visible markup
Fred Drake <fdrake@acm.org>
parents:
15981
diff
changeset
|
37 and \function{str()} respectively. |
| 14075 | 38 \end{classdesc} |
| 39 | |
| 40 \begin{classdesc}{SerialCookie}{\optional{input}} | |
|
18345
0200cd22492e
Removed some stray periods, and fix up a number of visible markup
Fred Drake <fdrake@acm.org>
parents:
15981
diff
changeset
|
41 This class derives from \class{BaseCookie} and overrides |
|
0200cd22492e
Removed some stray periods, and fix up a number of visible markup
Fred Drake <fdrake@acm.org>
parents:
15981
diff
changeset
|
42 \method{value_decode()} and \method{value_encode()} to be the |
|
0200cd22492e
Removed some stray periods, and fix up a number of visible markup
Fred Drake <fdrake@acm.org>
parents:
15981
diff
changeset
|
43 \function{pickle.loads()} and \function{pickle.dumps()}. |
|
14093
ec6a0b4a6479
Strengthen the warning against using SerialCookie and SmartCookie.
Andrew M. Kuchling <amk@amk.ca>
parents:
14075
diff
changeset
|
44 |
|
21002
bea92c3d77a3
Toughen up the security warnings a bit.
Barry Warsaw <barry@python.org>
parents:
18345
diff
changeset
|
45 \strong{Do not use this class!} Reading pickled values from untrusted |
|
bea92c3d77a3
Toughen up the security warnings a bit.
Barry Warsaw <barry@python.org>
parents:
18345
diff
changeset
|
46 cookie data is a huge security hole, as pickle strings can be crafted |
|
bea92c3d77a3
Toughen up the security warnings a bit.
Barry Warsaw <barry@python.org>
parents:
18345
diff
changeset
|
47 to cause arbitrary code to execute on your server. It is supported |
|
bea92c3d77a3
Toughen up the security warnings a bit.
Barry Warsaw <barry@python.org>
parents:
18345
diff
changeset
|
48 for backwards compatibility only, and may eventually go away. |
| 14075 | 49 \end{classdesc} |
| 50 | |
| 51 \begin{classdesc}{SmartCookie}{\optional{input}} | |
|
18345
0200cd22492e
Removed some stray periods, and fix up a number of visible markup
Fred Drake <fdrake@acm.org>
parents:
15981
diff
changeset
|
52 This class derives from \class{BaseCookie}. It overrides |
|
0200cd22492e
Removed some stray periods, and fix up a number of visible markup
Fred Drake <fdrake@acm.org>
parents:
15981
diff
changeset
|
53 \method{value_decode()} to be \function{pickle.loads()} if it is a |
|
0200cd22492e
Removed some stray periods, and fix up a number of visible markup
Fred Drake <fdrake@acm.org>
parents:
15981
diff
changeset
|
54 valid pickle, and otherwise the value itself. It overrides |
|
0200cd22492e
Removed some stray periods, and fix up a number of visible markup
Fred Drake <fdrake@acm.org>
parents:
15981
diff
changeset
|
55 \method{value_encode()} to be \function{pickle.dumps()} unless it is a |
|
0200cd22492e
Removed some stray periods, and fix up a number of visible markup
Fred Drake <fdrake@acm.org>
parents:
15981
diff
changeset
|
56 string, in which case it returns the value itself. |
| 14075 | 57 |
|
21002
bea92c3d77a3
Toughen up the security warnings a bit.
Barry Warsaw <barry@python.org>
parents:
18345
diff
changeset
|
58 \strong{Note:} The same security warning from \class{SerialCookie} |
|
bea92c3d77a3
Toughen up the security warnings a bit.
Barry Warsaw <barry@python.org>
parents:
18345
diff
changeset
|
59 applies here. |
| 14075 | 60 \end{classdesc} |
| 61 | |
|
21002
bea92c3d77a3
Toughen up the security warnings a bit.
Barry Warsaw <barry@python.org>
parents:
18345
diff
changeset
|
62 A further security note is warranted. For backwards compatibility, |
|
bea92c3d77a3
Toughen up the security warnings a bit.
Barry Warsaw <barry@python.org>
parents:
18345
diff
changeset
|
63 the \module{Cookie} module exports a class named \class{Cookie} which |
|
bea92c3d77a3
Toughen up the security warnings a bit.
Barry Warsaw <barry@python.org>
parents:
18345
diff
changeset
|
64 is just an alias for \class{SmartCookie}. This is probably a mistake |
|
bea92c3d77a3
Toughen up the security warnings a bit.
Barry Warsaw <barry@python.org>
parents:
18345
diff
changeset
|
65 and will likely be removed in a future version. You should not use |
|
bea92c3d77a3
Toughen up the security warnings a bit.
Barry Warsaw <barry@python.org>
parents:
18345
diff
changeset
|
66 the \class{Cookie} class in your applications, for the same reason why |
|
bea92c3d77a3
Toughen up the security warnings a bit.
Barry Warsaw <barry@python.org>
parents:
18345
diff
changeset
|
67 you should not use the \class{SerialCookie} class. |
|
bea92c3d77a3
Toughen up the security warnings a bit.
Barry Warsaw <barry@python.org>
parents:
18345
diff
changeset
|
68 |
| 14075 | 69 |
| 70 \begin{seealso} | |
| 71 \seerfc{2109}{HTTP State Management Mechanism}{This is the state | |
| 72 management specification implemented by this module.} | |
| 73 \end{seealso} | |
| 74 | |
| 75 | |
| 76 \subsection{Cookie Objects \label{cookie-objects}} | |
| 77 | |
|
14071
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
78 \begin{methoddesc}[BaseCookie]{value_decode}{val} |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
79 Return a decoded value from a string representation. Return value can |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
80 be any type. This method does nothing in \class{BaseCookie} --- it exists |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
81 so it can be overridden. |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
82 \end{methoddesc} |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
83 |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
84 \begin{methoddesc}[BaseCookie]{value_encode}{val} |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
85 Return an encoded value. \var{val} can be any type, but return value |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
86 must be a string. This method does nothing in \class{BaseCookie} --- it exists |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
87 so it can be overridden |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
88 |
|
18345
0200cd22492e
Removed some stray periods, and fix up a number of visible markup
Fred Drake <fdrake@acm.org>
parents:
15981
diff
changeset
|
89 In general, it should be the case that \method{value_encode()} and |
|
0200cd22492e
Removed some stray periods, and fix up a number of visible markup
Fred Drake <fdrake@acm.org>
parents:
15981
diff
changeset
|
90 \method{value_decode()} are inverses on the range of \var{value_decode}. |
|
0200cd22492e
Removed some stray periods, and fix up a number of visible markup
Fred Drake <fdrake@acm.org>
parents:
15981
diff
changeset
|
91 \end{methoddesc} |
|
14071
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
92 |
| 14075 | 93 \begin{methoddesc}[BaseCookie]{output}{\optional{attrs\optional{, header\optional{, sep}}}} |
|
14071
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
94 Return a string representation suitable to be sent as HTTP headers. |
|
18345
0200cd22492e
Removed some stray periods, and fix up a number of visible markup
Fred Drake <fdrake@acm.org>
parents:
15981
diff
changeset
|
95 \var{attrs} and \var{header} are sent to each \class{Morsel}'s |
|
0200cd22492e
Removed some stray periods, and fix up a number of visible markup
Fred Drake <fdrake@acm.org>
parents:
15981
diff
changeset
|
96 \method{output()} method. \var{sep} is used to join the headers |
|
0200cd22492e
Removed some stray periods, and fix up a number of visible markup
Fred Drake <fdrake@acm.org>
parents:
15981
diff
changeset
|
97 together, and is by default a newline. |
|
14071
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
98 \end{methoddesc} |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
99 |
| 14075 | 100 \begin{methoddesc}[BaseCookie]{js_output}{\optional{attrs}} |
|
14071
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
101 Return an embeddable JavaScript snippet, which, if run on a browser which |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
102 supports JavaScript, will act the same as if the HTTP headers was sent. |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
103 |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
104 The meaning for \var{attrs} is the same as in \method{output()}. |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
105 \end{methoddesc} |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
106 |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
107 \begin{methoddesc}[BaseCookie]{load}{rawdata} |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
108 If \var{rawdata} is a string, parse it as an \code{HTTP_COOKIE} and add |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
109 the values found there as \class{Morsel}s. If it is a dictionary, it |
| 14075 | 110 is equivalent to: |
|
14071
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
111 |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
112 \begin{verbatim} |
| 14075 | 113 for k, v in rawdata.items(): |
| 114 cookie[k] = v | |
| 115 \end{verbatim} | |
|
14071
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
116 \end{methoddesc} |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
117 |
| 14075 | 118 |
| 119 \subsection{Morsel Objects \label{morsel-objects}} | |
| 120 | |
| 121 \begin{classdesc}{Morsel}{} | |
| 122 Abstract a key/value pair, which has some \rfc{2109} attributes. | |
| 123 | |
| 124 Morsels are dictionary-like objects, whose set of keys is constant --- | |
| 125 the valid \rfc{2109} attributes, which are | |
| 126 | |
| 127 \begin{itemize} | |
| 128 \item \code{expires} | |
| 129 \item \code{path} | |
| 130 \item \code{comment} | |
| 131 \item \code{domain} | |
| 132 \item \code{max-age} | |
| 133 \item \code{secure} | |
| 134 \item \code{version} | |
| 135 \end{itemize} | |
| 136 | |
| 137 The keys are case-insensitive. | |
|
14071
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
138 \end{classdesc} |
|
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
139 |
| 14075 | 140 \begin{memberdesc}[Morsel]{value} |
| 141 The value of the cookie. | |
| 142 \end{memberdesc} | |
| 143 | |
| 144 \begin{memberdesc}[Morsel]{coded_value} | |
| 145 The encoded value of the cookie --- this is what should be sent. | |
| 146 \end{memberdesc} | |
| 147 | |
| 148 \begin{memberdesc}[Morsel]{key} | |
| 149 The name of the cookie. | |
| 150 \end{memberdesc} | |
| 151 | |
| 152 \begin{methoddesc}[Morsel]{set}{key, value, coded_value} | |
| 153 Set the \var{key}, \var{value} and \var{coded_value} members. | |
| 154 \end{methoddesc} | |
| 155 | |
| 156 \begin{methoddesc}[Morsel]{isReservedKey}{K} | |
| 157 Whether \var{K} is a member of the set of keys of a \class{Morsel}. | |
| 158 \end{methoddesc} | |
| 159 | |
| 160 \begin{methoddesc}[Morsel]{output}{\optional{attrs\optional{, header}}} | |
| 161 Return a string representation of the Morsel, suitable | |
| 162 to be sent as an HTTP header. By default, all the attributes are included, | |
| 163 unless \var{attrs} is given, in which case it should be a list of attributes | |
| 164 to use. \var{header} is by default \code{"Set-Cookie:"}. | |
| 165 \end{methoddesc} | |
| 166 | |
| 167 \begin{methoddesc}[Morsel]{js_output}{\optional{attrs}} | |
| 168 Return an embeddable JavaScript snippet, which, if run on a browser which | |
| 169 supports JavaScript, will act the same as if the HTTP header was sent. | |
| 170 | |
| 171 The meaning for \var{attrs} is the same as in \method{output()}. | |
|
18345
0200cd22492e
Removed some stray periods, and fix up a number of visible markup
Fred Drake <fdrake@acm.org>
parents:
15981
diff
changeset
|
172 \end{methoddesc} |
| 14075 | 173 |
| 174 \begin{methoddesc}[Morsel]{OutputString}{\optional{attrs}} | |
| 175 Return a string representing the Morsel, without any surrounding HTTP | |
| 176 or JavaScript. | |
| 177 | |
| 178 The meaning for \var{attrs} is the same as in \method{output()}. | |
| 179 \end{methoddesc} | |
| 180 | |
| 181 | |
| 182 \subsection{Example \label{cookie-example}} | |
| 183 | |
|
15981
d1cb4138fd34
Fix the example (it didn't seem to reflect reality).
Ka-Ping Yee <ping@zesty.ca>
parents:
15800
diff
changeset
|
184 The following example demonstrates how to use the \module{Cookie} module. |
|
14071
1fcf7b438cab
Initial revision. Markup unchecked.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
diff
changeset
|
185 |
| 14075 | 186 \begin{verbatim} |
| 187 >>> import Cookie | |
| 188 >>> C = Cookie.SimpleCookie() | |
| 189 >>> C = Cookie.SerialCookie() | |
| 190 >>> C = Cookie.SmartCookie() | |
| 191 >>> C["fig"] = "newton" | |
| 192 >>> C["sugar"] = "wafer" | |
|
15981
d1cb4138fd34
Fix the example (it didn't seem to reflect reality).
Ka-Ping Yee <ping@zesty.ca>
parents:
15800
diff
changeset
|
193 >>> print C # generate HTTP headers |
|
d1cb4138fd34
Fix the example (it didn't seem to reflect reality).
Ka-Ping Yee <ping@zesty.ca>
parents:
15800
diff
changeset
|
194 Set-Cookie: sugar=wafer; |
|
d1cb4138fd34
Fix the example (it didn't seem to reflect reality).
Ka-Ping Yee <ping@zesty.ca>
parents:
15800
diff
changeset
|
195 Set-Cookie: fig=newton; |
|
d1cb4138fd34
Fix the example (it didn't seem to reflect reality).
Ka-Ping Yee <ping@zesty.ca>
parents:
15800
diff
changeset
|
196 >>> print C.output() # same thing |
| 14075 | 197 Set-Cookie: sugar=wafer; |
| 198 Set-Cookie: fig=newton; | |
| 199 >>> C = Cookie.SmartCookie() | |
| 200 >>> C["rocky"] = "road" | |
| 201 >>> C["rocky"]["path"] = "/cookie" | |
| 202 >>> print C.output(header="Cookie:") | |
| 203 Cookie: rocky=road; Path=/cookie; | |
| 204 >>> print C.output(attrs=[], header="Cookie:") | |
| 205 Cookie: rocky=road; | |
| 206 >>> C = Cookie.SmartCookie() | |
| 207 >>> C.load("chips=ahoy; vienna=finger") # load from a string (HTTP header) | |
|
15981
d1cb4138fd34
Fix the example (it didn't seem to reflect reality).
Ka-Ping Yee <ping@zesty.ca>
parents:
15800
diff
changeset
|
208 >>> print C |
| 14075 | 209 Set-Cookie: vienna=finger; |
| 210 Set-Cookie: chips=ahoy; | |
| 211 >>> C = Cookie.SmartCookie() | |
|
15981
d1cb4138fd34
Fix the example (it didn't seem to reflect reality).
Ka-Ping Yee <ping@zesty.ca>
parents:
15800
diff
changeset
|
212 >>> C.load('keebler="E=everybody; L=\\"Loves\\"; fudge=\\012;";') |
|
d1cb4138fd34
Fix the example (it didn't seem to reflect reality).
Ka-Ping Yee <ping@zesty.ca>
parents:
15800
diff
changeset
|
213 >>> print C |
| 14075 | 214 Set-Cookie: keebler="E=everybody; L=\"Loves\"; fudge=\012;"; |
| 215 >>> C = Cookie.SmartCookie() | |
| 216 >>> C["oreo"] = "doublestuff" | |
| 217 >>> C["oreo"]["path"] = "/" | |
|
15981
d1cb4138fd34
Fix the example (it didn't seem to reflect reality).
Ka-Ping Yee <ping@zesty.ca>
parents:
15800
diff
changeset
|
218 >>> print C |
|
d1cb4138fd34
Fix the example (it didn't seem to reflect reality).
Ka-Ping Yee <ping@zesty.ca>
parents:
15800
diff
changeset
|
219 Set-Cookie: oreo=doublestuff; Path=/; |
| 14075 | 220 >>> C = Cookie.SmartCookie() |
| 221 >>> C["twix"] = "none for you" | |
| 222 >>> C["twix"].value | |
| 223 'none for you' | |
| 224 >>> C = Cookie.SimpleCookie() | |
| 225 >>> C["number"] = 7 # equivalent to C["number"] = str(7) | |
| 226 >>> C["string"] = "seven" | |
| 227 >>> C["number"].value | |
| 228 '7' | |
| 229 >>> C["string"].value | |
| 230 'seven' | |
|
15981
d1cb4138fd34
Fix the example (it didn't seem to reflect reality).
Ka-Ping Yee <ping@zesty.ca>
parents:
15800
diff
changeset
|
231 >>> print C |
| 14075 | 232 Set-Cookie: number=7; |
| 233 Set-Cookie: string=seven; | |
| 234 >>> C = Cookie.SerialCookie() | |
| 235 >>> C["number"] = 7 | |
| 236 >>> C["string"] = "seven" | |
| 237 >>> C["number"].value | |
| 238 7 | |
| 239 >>> C["string"].value | |
| 240 'seven' | |
|
15981
d1cb4138fd34
Fix the example (it didn't seem to reflect reality).
Ka-Ping Yee <ping@zesty.ca>
parents:
15800
diff
changeset
|
241 >>> print C |
| 14075 | 242 Set-Cookie: number="I7\012."; |
| 243 Set-Cookie: string="S'seven'\012p1\012."; | |
| 244 >>> C = Cookie.SmartCookie() | |
| 245 >>> C["number"] = 7 | |
| 246 >>> C["string"] = "seven" | |
| 247 >>> C["number"].value | |
| 248 7 | |
| 249 >>> C["string"].value | |
| 250 'seven' | |
|
15981
d1cb4138fd34
Fix the example (it didn't seem to reflect reality).
Ka-Ping Yee <ping@zesty.ca>
parents:
15800
diff
changeset
|
251 >>> print C |
| 14075 | 252 Set-Cookie: number="I7\012."; |
| 253 Set-Cookie: string=seven; | |
| 254 \end{verbatim} |
