/usr/share/doc/python-werkzeug-doc/html/contrib/securecookie.html is in python-werkzeug-doc 0.10.4+dfsg1-1ubuntu1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Secure Cookie — Werkzeug 0.10.4 documentation</title>
<link rel="stylesheet" href="../_static/werkzeug.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '0.10.4',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="top" title="Werkzeug 0.10.4 documentation" href="../index.html" />
<link rel="up" title="Contributed Modules" href="index.html" />
<link rel="next" title="Cache" href="cache.html" />
<link rel="prev" title="Sessions" href="sessions.html" />
</head>
<body role="document">
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="cache.html" title="Cache"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="sessions.html" title="Sessions"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Werkzeug 0.10.4 documentation</a> »</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Contributed Modules</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="module-werkzeug.contrib.securecookie">
<span id="secure-cookie"></span><h1>Secure Cookie<a class="headerlink" href="#module-werkzeug.contrib.securecookie" title="Permalink to this headline">¶</a></h1>
<p>This module implements a cookie that is not alterable from the client
because it adds a checksum the server checks for. You can use it as
session replacement if all you have is a user id or something to mark
a logged in user.</p>
<p>Keep in mind that the data is still readable from the client as a
normal cookie is. However you don’t have to store and flush the
sessions you have at the server.</p>
<p>Example usage:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">werkzeug.contrib.securecookie</span> <span class="kn">import</span> <span class="n">SecureCookie</span>
<span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">SecureCookie</span><span class="p">({</span><span class="s2">"foo"</span><span class="p">:</span> <span class="mi">42</span><span class="p">,</span> <span class="s2">"baz"</span><span class="p">:</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)},</span> <span class="s2">"deadbeef"</span><span class="p">)</span>
</pre></div>
</div>
<p>Dumping into a string so that one can store it in a cookie:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">value</span> <span class="o">=</span> <span class="n">x</span><span class="o">.</span><span class="n">serialize</span><span class="p">()</span>
</pre></div>
</div>
<p>Loading from that string again:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">SecureCookie</span><span class="o">.</span><span class="n">unserialize</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="s2">"deadbeef"</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">x</span><span class="p">[</span><span class="s2">"baz"</span><span class="p">]</span>
<span class="go">(1, 2, 3)</span>
</pre></div>
</div>
<p>If someone modifies the cookie and the checksum is wrong the unserialize
method will fail silently and return a new empty <cite>SecureCookie</cite> object.</p>
<p>Keep in mind that the values will be visible in the cookie so do not
store data in a cookie you don’t want the user to see.</p>
<div class="section" id="application-integration">
<h2>Application Integration<a class="headerlink" href="#application-integration" title="Permalink to this headline">¶</a></h2>
<p>If you are using the werkzeug request objects you could integrate the
secure cookie into your application like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">werkzeug.utils</span> <span class="kn">import</span> <span class="n">cached_property</span>
<span class="kn">from</span> <span class="nn">werkzeug.wrappers</span> <span class="kn">import</span> <span class="n">BaseRequest</span>
<span class="kn">from</span> <span class="nn">werkzeug.contrib.securecookie</span> <span class="kn">import</span> <span class="n">SecureCookie</span>
<span class="c1"># don't use this key but a different one; you could just use</span>
<span class="c1"># os.urandom(20) to get something random</span>
<span class="n">SECRET_KEY</span> <span class="o">=</span> <span class="s1">'</span><span class="se">\xfa\xdd\xb8</span><span class="s1">z</span><span class="se">\xae\xe0</span><span class="s1">}4</span><span class="se">\x8b\xea</span><span class="s1">'</span>
<span class="k">class</span> <span class="nc">Request</span><span class="p">(</span><span class="n">BaseRequest</span><span class="p">):</span>
<span class="nd">@cached_property</span>
<span class="k">def</span> <span class="nf">client_session</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">cookies</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'session_data'</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">data</span><span class="p">:</span>
<span class="k">return</span> <span class="n">SecureCookie</span><span class="p">(</span><span class="n">secret_key</span><span class="o">=</span><span class="n">SECRET_KEY</span><span class="p">)</span>
<span class="k">return</span> <span class="n">SecureCookie</span><span class="o">.</span><span class="n">unserialize</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">SECRET_KEY</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">application</span><span class="p">(</span><span class="n">environ</span><span class="p">,</span> <span class="n">start_response</span><span class="p">):</span>
<span class="n">request</span> <span class="o">=</span> <span class="n">Request</span><span class="p">(</span><span class="n">environ</span><span class="p">,</span> <span class="n">start_response</span><span class="p">)</span>
<span class="c1"># get a response object here</span>
<span class="n">response</span> <span class="o">=</span> <span class="o">...</span>
<span class="k">if</span> <span class="n">request</span><span class="o">.</span><span class="n">client_session</span><span class="o">.</span><span class="n">should_save</span><span class="p">:</span>
<span class="n">session_data</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">client_session</span><span class="o">.</span><span class="n">serialize</span><span class="p">()</span>
<span class="n">response</span><span class="o">.</span><span class="n">set_cookie</span><span class="p">(</span><span class="s1">'session_data'</span><span class="p">,</span> <span class="n">session_data</span><span class="p">,</span>
<span class="n">httponly</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="k">return</span> <span class="n">response</span><span class="p">(</span><span class="n">environ</span><span class="p">,</span> <span class="n">start_response</span><span class="p">)</span>
</pre></div>
</div>
<p>A less verbose integration can be achieved by using shorthand methods:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">Request</span><span class="p">(</span><span class="n">BaseRequest</span><span class="p">):</span>
<span class="nd">@cached_property</span>
<span class="k">def</span> <span class="nf">client_session</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="n">SecureCookie</span><span class="o">.</span><span class="n">load_cookie</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">secret_key</span><span class="o">=</span><span class="n">COOKIE_SECRET</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">application</span><span class="p">(</span><span class="n">environ</span><span class="p">,</span> <span class="n">start_response</span><span class="p">):</span>
<span class="n">request</span> <span class="o">=</span> <span class="n">Request</span><span class="p">(</span><span class="n">environ</span><span class="p">,</span> <span class="n">start_response</span><span class="p">)</span>
<span class="c1"># get a response object here</span>
<span class="n">response</span> <span class="o">=</span> <span class="o">...</span>
<span class="n">request</span><span class="o">.</span><span class="n">client_session</span><span class="o">.</span><span class="n">save_cookie</span><span class="p">(</span><span class="n">response</span><span class="p">)</span>
<span class="k">return</span> <span class="n">response</span><span class="p">(</span><span class="n">environ</span><span class="p">,</span> <span class="n">start_response</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="security">
<h2>Security<a class="headerlink" href="#security" title="Permalink to this headline">¶</a></h2>
<p>The default implementation uses Pickle as this is the only module that
used to be available in the standard library when this module was created.
If you have simplejson available it’s strongly recommended to create a
subclass and replace the serialization method:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">json</span>
<span class="kn">from</span> <span class="nn">werkzeug.contrib.securecookie</span> <span class="kn">import</span> <span class="n">SecureCookie</span>
<span class="k">class</span> <span class="nc">JSONSecureCookie</span><span class="p">(</span><span class="n">SecureCookie</span><span class="p">):</span>
<span class="n">serialization_method</span> <span class="o">=</span> <span class="n">json</span>
</pre></div>
</div>
<p>The weakness of Pickle is that if someone gains access to the secret key
the attacker can not only modify the session but also execute arbitrary
code on the server.</p>
</div>
<div class="section" id="reference">
<h2>Reference<a class="headerlink" href="#reference" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="werkzeug.contrib.securecookie.SecureCookie">
<em class="property">class </em><code class="descclassname">werkzeug.contrib.securecookie.</code><code class="descname">SecureCookie</code><span class="sig-paren">(</span><em>data=None</em>, <em>secret_key=None</em>, <em>new=True</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.contrib.securecookie.SecureCookie" title="Permalink to this definition">¶</a></dt>
<dd><p>Represents a secure cookie. You can subclass this class and provide
an alternative mac method. The import thing is that the mac method
is a function with a similar interface to the hashlib. Required
methods are update() and digest().</p>
<p>Example usage:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">SecureCookie</span><span class="p">({</span><span class="s2">"foo"</span><span class="p">:</span> <span class="mi">42</span><span class="p">,</span> <span class="s2">"baz"</span><span class="p">:</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)},</span> <span class="s2">"deadbeef"</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">x</span><span class="p">[</span><span class="s2">"foo"</span><span class="p">]</span>
<span class="go">42</span>
<span class="gp">>>> </span><span class="n">x</span><span class="p">[</span><span class="s2">"baz"</span><span class="p">]</span>
<span class="go">(1, 2, 3)</span>
<span class="gp">>>> </span><span class="n">x</span><span class="p">[</span><span class="s2">"blafasel"</span><span class="p">]</span> <span class="o">=</span> <span class="mi">23</span>
<span class="gp">>>> </span><span class="n">x</span><span class="o">.</span><span class="n">should_save</span>
<span class="go">True</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>data</strong> – the initial data. Either a dict, list of tuples or <cite>None</cite>.</li>
<li><strong>secret_key</strong> – the secret key. If not set <cite>None</cite> or not specified
it has to be set before <a class="reference internal" href="#werkzeug.contrib.securecookie.SecureCookie.serialize" title="werkzeug.contrib.securecookie.SecureCookie.serialize"><code class="xref py py-meth docutils literal"><span class="pre">serialize()</span></code></a> is called.</li>
<li><strong>new</strong> – The initial value of the <cite>new</cite> flag.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dl class="attribute">
<dt id="werkzeug.contrib.securecookie.SecureCookie.new">
<code class="descname">new</code><a class="headerlink" href="#werkzeug.contrib.securecookie.SecureCookie.new" title="Permalink to this definition">¶</a></dt>
<dd><p><cite>True</cite> if the cookie was newly created, otherwise <cite>False</cite></p>
</dd></dl>
<dl class="attribute">
<dt id="werkzeug.contrib.securecookie.SecureCookie.modified">
<code class="descname">modified</code><a class="headerlink" href="#werkzeug.contrib.securecookie.SecureCookie.modified" title="Permalink to this definition">¶</a></dt>
<dd><p>Whenever an item on the cookie is set, this attribute is set to <cite>True</cite>.
However this does not track modifications inside mutable objects
in the cookie:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">c</span> <span class="o">=</span> <span class="n">SecureCookie</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">c</span><span class="p">[</span><span class="s2">"foo"</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]</span>
<span class="gp">>>> </span><span class="n">c</span><span class="o">.</span><span class="n">modified</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="n">c</span><span class="o">.</span><span class="n">modified</span> <span class="o">=</span> <span class="bp">False</span>
<span class="gp">>>> </span><span class="n">c</span><span class="p">[</span><span class="s2">"foo"</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">c</span><span class="o">.</span><span class="n">modified</span>
<span class="go">False</span>
</pre></div>
</div>
<p>In that situation it has to be set to <cite>modified</cite> by hand so that
<a class="reference internal" href="#werkzeug.contrib.securecookie.SecureCookie.should_save" title="werkzeug.contrib.securecookie.SecureCookie.should_save"><code class="xref py py-attr docutils literal"><span class="pre">should_save</span></code></a> can pick it up.</p>
</dd></dl>
<dl class="staticmethod">
<dt id="werkzeug.contrib.securecookie.SecureCookie.hash_method">
<em class="property">static </em><code class="descname">hash_method</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.contrib.securecookie.SecureCookie.hash_method" title="Permalink to this definition">¶</a></dt>
<dd><p>The hash method to use. This has to be a module with a new function
or a function that creates a hashlib object. Such as <cite>hashlib.md5</cite>
Subclasses can override this attribute. The default hash is sha1.
Make sure to wrap this in staticmethod() if you store an arbitrary
function there such as hashlib.sha1 which might be implemented
as a function.</p>
</dd></dl>
<dl class="classmethod">
<dt id="werkzeug.contrib.securecookie.SecureCookie.load_cookie">
<em class="property">classmethod </em><code class="descname">load_cookie</code><span class="sig-paren">(</span><em>request</em>, <em>key='session'</em>, <em>secret_key=None</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.contrib.securecookie.SecureCookie.load_cookie" title="Permalink to this definition">¶</a></dt>
<dd><p>Loads a <a class="reference internal" href="#werkzeug.contrib.securecookie.SecureCookie" title="werkzeug.contrib.securecookie.SecureCookie"><code class="xref py py-class docutils literal"><span class="pre">SecureCookie</span></code></a> from a cookie in request. If the
cookie is not set, a new <a class="reference internal" href="#werkzeug.contrib.securecookie.SecureCookie" title="werkzeug.contrib.securecookie.SecureCookie"><code class="xref py py-class docutils literal"><span class="pre">SecureCookie</span></code></a> instanced is
returned.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>request</strong> – a request object that has a <cite>cookies</cite> attribute
which is a dict of all cookie values.</li>
<li><strong>key</strong> – the name of the cookie.</li>
<li><strong>secret_key</strong> – the secret key used to unquote the cookie.
Always provide the value even though it has
no default!</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="classmethod">
<dt id="werkzeug.contrib.securecookie.SecureCookie.quote">
<em class="property">classmethod </em><code class="descname">quote</code><span class="sig-paren">(</span><em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.contrib.securecookie.SecureCookie.quote" title="Permalink to this definition">¶</a></dt>
<dd><p>Quote the value for the cookie. This can be any object supported
by <a class="reference internal" href="#werkzeug.contrib.securecookie.SecureCookie.serialization_method" title="werkzeug.contrib.securecookie.SecureCookie.serialization_method"><code class="xref py py-attr docutils literal"><span class="pre">serialization_method</span></code></a>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>value</strong> – the value to quote.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="attribute">
<dt id="werkzeug.contrib.securecookie.SecureCookie.quote_base64">
<code class="descname">quote_base64</code><em class="property"> = True</em><a class="headerlink" href="#werkzeug.contrib.securecookie.SecureCookie.quote_base64" title="Permalink to this definition">¶</a></dt>
<dd><p>if the contents should be base64 quoted. This can be disabled if the
serialization process returns cookie safe strings only.</p>
</dd></dl>
<dl class="method">
<dt id="werkzeug.contrib.securecookie.SecureCookie.save_cookie">
<code class="descname">save_cookie</code><span class="sig-paren">(</span><em>response</em>, <em>key='session'</em>, <em>expires=None</em>, <em>session_expires=None</em>, <em>max_age=None</em>, <em>path='/'</em>, <em>domain=None</em>, <em>secure=None</em>, <em>httponly=False</em>, <em>force=False</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.contrib.securecookie.SecureCookie.save_cookie" title="Permalink to this definition">¶</a></dt>
<dd><p>Saves the SecureCookie in a cookie on response object. All
parameters that are not described here are forwarded directly
to <code class="xref py py-meth docutils literal"><span class="pre">set_cookie()</span></code>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>response</strong> – a response object that has a
<code class="xref py py-meth docutils literal"><span class="pre">set_cookie()</span></code> method.</li>
<li><strong>key</strong> – the name of the cookie.</li>
<li><strong>session_expires</strong> – the expiration date of the secure cookie
stored information. If this is not provided
the cookie <cite>expires</cite> date is used instead.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="attribute">
<dt id="werkzeug.contrib.securecookie.SecureCookie.serialization_method">
<code class="descname">serialization_method</code><em class="property"> = <module 'pickle' from '/usr/lib/python2.7/pickle.pyc'></em><a class="headerlink" href="#werkzeug.contrib.securecookie.SecureCookie.serialization_method" title="Permalink to this definition">¶</a></dt>
<dd><p>the module used for serialization. Unless overriden by subclasses
the standard pickle module is used.</p>
</dd></dl>
<dl class="method">
<dt id="werkzeug.contrib.securecookie.SecureCookie.serialize">
<code class="descname">serialize</code><span class="sig-paren">(</span><em>expires=None</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.contrib.securecookie.SecureCookie.serialize" title="Permalink to this definition">¶</a></dt>
<dd><p>Serialize the secure cookie into a string.</p>
<p>If expires is provided, the session will be automatically invalidated
after expiration when you unseralize it. This provides better
protection against session cookie theft.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>expires</strong> – an optional expiration date for the cookie (a
<code class="xref py py-class docutils literal"><span class="pre">datetime.datetime</span></code> object)</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="attribute">
<dt id="werkzeug.contrib.securecookie.SecureCookie.should_save">
<code class="descname">should_save</code><a class="headerlink" href="#werkzeug.contrib.securecookie.SecureCookie.should_save" title="Permalink to this definition">¶</a></dt>
<dd><p>True if the session should be saved. By default this is only true
for <a class="reference internal" href="#werkzeug.contrib.securecookie.SecureCookie.modified" title="werkzeug.contrib.securecookie.SecureCookie.modified"><code class="xref py py-attr docutils literal"><span class="pre">modified</span></code></a> cookies, not <a class="reference internal" href="#werkzeug.contrib.securecookie.SecureCookie.new" title="werkzeug.contrib.securecookie.SecureCookie.new"><code class="xref py py-attr docutils literal"><span class="pre">new</span></code></a>.</p>
</dd></dl>
<dl class="classmethod">
<dt id="werkzeug.contrib.securecookie.SecureCookie.unquote">
<em class="property">classmethod </em><code class="descname">unquote</code><span class="sig-paren">(</span><em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.contrib.securecookie.SecureCookie.unquote" title="Permalink to this definition">¶</a></dt>
<dd><p>Unquote the value for the cookie. If unquoting does not work a
<a class="reference internal" href="#werkzeug.contrib.securecookie.UnquoteError" title="werkzeug.contrib.securecookie.UnquoteError"><code class="xref py py-exc docutils literal"><span class="pre">UnquoteError</span></code></a> is raised.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>value</strong> – the value to unquote.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="classmethod">
<dt id="werkzeug.contrib.securecookie.SecureCookie.unserialize">
<em class="property">classmethod </em><code class="descname">unserialize</code><span class="sig-paren">(</span><em>string</em>, <em>secret_key</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.contrib.securecookie.SecureCookie.unserialize" title="Permalink to this definition">¶</a></dt>
<dd><p>Load the secure cookie from a serialized string.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>string</strong> – the cookie value to unserialize.</li>
<li><strong>secret_key</strong> – the secret key used to serialize the cookie.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a new <a class="reference internal" href="#werkzeug.contrib.securecookie.SecureCookie" title="werkzeug.contrib.securecookie.SecureCookie"><code class="xref py py-class docutils literal"><span class="pre">SecureCookie</span></code></a>.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="exception">
<dt id="werkzeug.contrib.securecookie.UnquoteError">
<em class="property">exception </em><code class="descclassname">werkzeug.contrib.securecookie.</code><code class="descname">UnquoteError</code><a class="headerlink" href="#werkzeug.contrib.securecookie.UnquoteError" title="Permalink to this definition">¶</a></dt>
<dd><p>Internal exception used to signal failures on quoting.</p>
</dd></dl>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper"><p class="logo"><a href="../index.html">
<img class="logo" src="../_static/werkzeug.png" alt="Logo"/>
</a></p>
<h3><a href="../index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Secure Cookie</a><ul>
<li><a class="reference internal" href="#application-integration">Application Integration</a></li>
<li><a class="reference internal" href="#security">Security</a></li>
<li><a class="reference internal" href="#reference">Reference</a></li>
</ul>
</li>
</ul>
<h3>Related Topics</h3>
<ul>
<li><a href="../index.html">Documentation overview</a><ul>
<li><a href="index.html">Contributed Modules</a><ul>
<li>Previous: <a href="sessions.html" title="previous chapter">Sessions</a></li>
<li>Next: <a href="cache.html" title="next chapter">Cache</a></li>
</ul></li>
</ul></li>
</ul>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/contrib/securecookie.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="../search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
© Copyright 2011, The Werkzeug Team.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
</div>
</body>
</html>
|