/usr/share/doc/python-werkzeug-doc/html/http.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 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 | <!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>HTTP Utilities — 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="next" title="Data Structures" href="datastructures.html" />
<link rel="prev" title="WSGI Helpers" href="wsgi.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="datastructures.html" title="Data Structures"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="wsgi.html" title="WSGI Helpers"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Werkzeug 0.10.4 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="module-werkzeug.http">
<span id="http-utilities"></span><h1>HTTP Utilities<a class="headerlink" href="#module-werkzeug.http" title="Permalink to this headline">¶</a></h1>
<p>Werkzeug provides a couple of functions to parse and generate HTTP headers
that are useful when implementing WSGI middlewares or whenever you are
operating on a lower level layer. All this functionality is also exposed
from request and response objects.</p>
<div class="section" id="date-functions">
<h2>Date Functions<a class="headerlink" href="#date-functions" title="Permalink to this headline">¶</a></h2>
<p>The following functions simplify working with times in an HTTP context.
Werkzeug uses offset-naive <code class="xref py py-class docutils literal"><span class="pre">datetime</span></code> objects internally
that store the time in UTC. If you’re working with timezones in your
application make sure to replace the tzinfo attribute with a UTC timezone
information before processing the values.</p>
<dl class="function">
<dt id="werkzeug.http.cookie_date">
<code class="descclassname">werkzeug.http.</code><code class="descname">cookie_date</code><span class="sig-paren">(</span><em>expires=None</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.cookie_date" title="Permalink to this definition">¶</a></dt>
<dd><p>Formats the time to ensure compatibility with Netscape’s cookie
standard.</p>
<p>Accepts a floating point number expressed in seconds since the epoch in, a
datetime object or a timetuple. All times in UTC. The <a class="reference internal" href="#werkzeug.http.parse_date" title="werkzeug.http.parse_date"><code class="xref py py-func docutils literal"><span class="pre">parse_date()</span></code></a>
function can be used to parse such a date.</p>
<p>Outputs a string in the format <code class="docutils literal"><span class="pre">Wdy,</span> <span class="pre">DD-Mon-YYYY</span> <span class="pre">HH:MM:SS</span> <span class="pre">GMT</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"><strong>expires</strong> – If provided that date is used, otherwise the current.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="werkzeug.http.http_date">
<code class="descclassname">werkzeug.http.</code><code class="descname">http_date</code><span class="sig-paren">(</span><em>timestamp=None</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.http_date" title="Permalink to this definition">¶</a></dt>
<dd><p>Formats the time to match the RFC1123 date format.</p>
<p>Accepts a floating point number expressed in seconds since the epoch in, a
datetime object or a timetuple. All times in UTC. The <a class="reference internal" href="#werkzeug.http.parse_date" title="werkzeug.http.parse_date"><code class="xref py py-func docutils literal"><span class="pre">parse_date()</span></code></a>
function can be used to parse such a date.</p>
<p>Outputs a string in the format <code class="docutils literal"><span class="pre">Wdy,</span> <span class="pre">DD</span> <span class="pre">Mon</span> <span class="pre">YYYY</span> <span class="pre">HH:MM:SS</span> <span class="pre">GMT</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"><strong>timestamp</strong> – If provided that date is used, otherwise the current.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="werkzeug.http.parse_date">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_date</code><span class="sig-paren">(</span><em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_date" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse one of the following date formats into a datetime object:</p>
<div class="highlight-text"><div class="highlight"><pre>Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
</pre></div>
</div>
<p>If parsing fails the return value is <cite>None</cite>.</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> – a string with a supported date format.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">a <code class="xref py py-class docutils literal"><span class="pre">datetime.datetime</span></code> object.</td>
</tr>
</tbody>
</table>
</dd></dl>
</div>
<div class="section" id="header-parsing">
<h2>Header Parsing<a class="headerlink" href="#header-parsing" title="Permalink to this headline">¶</a></h2>
<p>The following functions can be used to parse incoming HTTP headers.
Because Python does not provide data structures with the semantics required
by <span class="target" id="index-0"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2616.html"><strong>RFC 2616</strong></a>, Werkzeug implements some custom data structures that are
<a class="reference internal" href="datastructures.html#http-datastructures"><span>documented separately</span></a>.</p>
<dl class="function">
<dt id="werkzeug.http.parse_options_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_options_header</code><span class="sig-paren">(</span><em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_options_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse a <code class="docutils literal"><span class="pre">Content-Type</span></code> like header into a tuple with the content
type and the options:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">parse_options_header</span><span class="p">(</span><span class="s1">'text/html; charset=utf8'</span><span class="p">)</span>
<span class="go">('text/html', {'charset': 'utf8'})</span>
</pre></div>
</div>
<p>This should not be used to parse <code class="docutils literal"><span class="pre">Cache-Control</span></code> like headers that use
a slightly different format. For these headers use the
<a class="reference internal" href="#werkzeug.http.parse_dict_header" title="werkzeug.http.parse_dict_header"><code class="xref py py-func docutils literal"><span class="pre">parse_dict_header()</span></code></a> function.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</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"><strong>value</strong> – the header to parse.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">(str, options)</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="werkzeug.http.parse_set_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_set_header</code><span class="sig-paren">(</span><em>value</em>, <em>on_update=None</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_set_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse a set-like header and return a
<a class="reference internal" href="datastructures.html#werkzeug.datastructures.HeaderSet" title="werkzeug.datastructures.HeaderSet"><code class="xref py py-class docutils literal"><span class="pre">HeaderSet</span></code></a> object:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">hs</span> <span class="o">=</span> <span class="n">parse_set_header</span><span class="p">(</span><span class="s1">'token, "quoted value"'</span><span class="p">)</span>
</pre></div>
</div>
<p>The return value is an object that treats the items case-insensitively
and keeps the order of the items:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="s1">'TOKEN'</span> <span class="ow">in</span> <span class="n">hs</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="n">hs</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="s1">'quoted value'</span><span class="p">)</span>
<span class="go">1</span>
<span class="gp">>>> </span><span class="n">hs</span>
<span class="go">HeaderSet(['token', 'quoted value'])</span>
</pre></div>
</div>
<p>To create a header from the <code class="xref py py-class docutils literal"><span class="pre">HeaderSet</span></code> again, use the
<a class="reference internal" href="#werkzeug.http.dump_header" title="werkzeug.http.dump_header"><code class="xref py py-func docutils literal"><span class="pre">dump_header()</span></code></a> function.</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>value</strong> – a set header to be parsed.</li>
<li><strong>on_update</strong> – an optional callable that is called every time a
value on the <a class="reference internal" href="datastructures.html#werkzeug.datastructures.HeaderSet" title="werkzeug.datastructures.HeaderSet"><code class="xref py py-class docutils literal"><span class="pre">HeaderSet</span></code></a>
object is changed.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a <a class="reference internal" href="datastructures.html#werkzeug.datastructures.HeaderSet" title="werkzeug.datastructures.HeaderSet"><code class="xref py py-class docutils literal"><span class="pre">HeaderSet</span></code></a></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="werkzeug.http.parse_list_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_list_header</code><span class="sig-paren">(</span><em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_list_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse lists as described by RFC 2068 Section 2.</p>
<p>In particular, parse comma-separated lists where the elements of
the list may include quoted-strings. A quoted-string could
contain a comma. A non-quoted string could have quotes in the
middle. Quotes are removed automatically after parsing.</p>
<p>It basically works like <a class="reference internal" href="#werkzeug.http.parse_set_header" title="werkzeug.http.parse_set_header"><code class="xref py py-func docutils literal"><span class="pre">parse_set_header()</span></code></a> just that items
may appear multiple times and case sensitivity is preserved.</p>
<p>The return value is a standard <code class="xref py py-class docutils literal"><span class="pre">list</span></code>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">parse_list_header</span><span class="p">(</span><span class="s1">'token, "quoted value"'</span><span class="p">)</span>
<span class="go">['token', 'quoted value']</span>
</pre></div>
</div>
<p>To create a header from the <code class="xref py py-class docutils literal"><span class="pre">list</span></code> again, use the
<a class="reference internal" href="#werkzeug.http.dump_header" title="werkzeug.http.dump_header"><code class="xref py py-func docutils literal"><span class="pre">dump_header()</span></code></a> function.</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> – a string with a list header.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><code class="xref py py-class docutils literal"><span class="pre">list</span></code></td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="werkzeug.http.parse_dict_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_dict_header</code><span class="sig-paren">(</span><em>value</em>, <em>cls=<type 'dict'></em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_dict_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse lists of key, value pairs as described by RFC 2068 Section 2 and
convert them into a python dict (or any other mapping object created from
the type with a dict like interface provided by the <cite>cls</cite> arugment):</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">d</span> <span class="o">=</span> <span class="n">parse_dict_header</span><span class="p">(</span><span class="s1">'foo="is a fish", bar="as well"'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="nb">type</span><span class="p">(</span><span class="n">d</span><span class="p">)</span> <span class="ow">is</span> <span class="nb">dict</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="nb">sorted</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">items</span><span class="p">())</span>
<span class="go">[('bar', 'as well'), ('foo', 'is a fish')]</span>
</pre></div>
</div>
<p>If there is no value for a key it will be <cite>None</cite>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">parse_dict_header</span><span class="p">(</span><span class="s1">'key_without_value'</span><span class="p">)</span>
<span class="go">{'key_without_value': None}</span>
</pre></div>
</div>
<p>To create a header from the <code class="xref py py-class docutils literal"><span class="pre">dict</span></code> again, use the
<a class="reference internal" href="#werkzeug.http.dump_header" title="werkzeug.http.dump_header"><code class="xref py py-func docutils literal"><span class="pre">dump_header()</span></code></a> function.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.9: </span>Added support for <cite>cls</cite> argument.</p>
</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 simple">
<li><strong>value</strong> – a string with a dict header.</li>
<li><strong>cls</strong> – callable to use for storage of parsed results.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">an instance of <cite>cls</cite></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="werkzeug.http.parse_accept_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_accept_header</code><span class="sig-paren">(</span><em>value</em><span class="optional">[</span>, <em>class</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_accept_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Parses an HTTP Accept-* header. This does not implement a complete
valid algorithm but one that supports at least value and quality
extraction.</p>
<p>Returns a new <code class="xref py py-class docutils literal"><span class="pre">Accept</span></code> object (basically a list of <code class="docutils literal"><span class="pre">(value,</span> <span class="pre">quality)</span></code>
tuples sorted by the quality with some additional accessor methods).</p>
<p>The second parameter can be a subclass of <code class="xref py py-class docutils literal"><span class="pre">Accept</span></code> that is created
with the parsed values and 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 simple">
<li><strong>value</strong> – the accept header string to be parsed.</li>
<li><strong>cls</strong> – the wrapper class for the return value (can be
<code class="xref py py-class docutils literal"><span class="pre">Accept</span></code> or a subclass thereof)</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">an instance of <cite>cls</cite>.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="werkzeug.http.parse_cache_control_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_cache_control_header</code><span class="sig-paren">(</span><em>value</em>, <em>on_update=None</em>, <em>cls=None</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_cache_control_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse a cache control header. The RFC differs between response and
request cache control, this method does not. It’s your responsibility
to not use the wrong control statements.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.5: </span>The <cite>cls</cite> was added. If not specified an immutable
<a class="reference internal" href="datastructures.html#werkzeug.datastructures.RequestCacheControl" title="werkzeug.datastructures.RequestCacheControl"><code class="xref py py-class docutils literal"><span class="pre">RequestCacheControl</span></code></a> is returned.</p>
</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 simple">
<li><strong>value</strong> – a cache control header to be parsed.</li>
<li><strong>on_update</strong> – an optional callable that is called every time a value
on the <code class="xref py py-class docutils literal"><span class="pre">CacheControl</span></code>
object is changed.</li>
<li><strong>cls</strong> – the class for the returned object. By default
<a class="reference internal" href="datastructures.html#werkzeug.datastructures.RequestCacheControl" title="werkzeug.datastructures.RequestCacheControl"><code class="xref py py-class docutils literal"><span class="pre">RequestCacheControl</span></code></a> is used.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a <cite>cls</cite> object.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="werkzeug.http.parse_authorization_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_authorization_header</code><span class="sig-paren">(</span><em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_authorization_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse an HTTP basic/digest authorization header transmitted by the web
browser. The return value is either <cite>None</cite> if the header was invalid or
not given, otherwise an <a class="reference internal" href="datastructures.html#werkzeug.datastructures.Authorization" title="werkzeug.datastructures.Authorization"><code class="xref py py-class docutils literal"><span class="pre">Authorization</span></code></a>
object.</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 authorization header to parse.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">a <a class="reference internal" href="datastructures.html#werkzeug.datastructures.Authorization" title="werkzeug.datastructures.Authorization"><code class="xref py py-class docutils literal"><span class="pre">Authorization</span></code></a> object or <cite>None</cite>.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="werkzeug.http.parse_www_authenticate_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_www_authenticate_header</code><span class="sig-paren">(</span><em>value</em>, <em>on_update=None</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_www_authenticate_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse an HTTP WWW-Authenticate header into a
<a class="reference internal" href="datastructures.html#werkzeug.datastructures.WWWAuthenticate" title="werkzeug.datastructures.WWWAuthenticate"><code class="xref py py-class docutils literal"><span class="pre">WWWAuthenticate</span></code></a> object.</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>value</strong> – a WWW-Authenticate header to parse.</li>
<li><strong>on_update</strong> – an optional callable that is called every time a value
on the <a class="reference internal" href="datastructures.html#werkzeug.datastructures.WWWAuthenticate" title="werkzeug.datastructures.WWWAuthenticate"><code class="xref py py-class docutils literal"><span class="pre">WWWAuthenticate</span></code></a>
object is changed.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a <a class="reference internal" href="datastructures.html#werkzeug.datastructures.WWWAuthenticate" title="werkzeug.datastructures.WWWAuthenticate"><code class="xref py py-class docutils literal"><span class="pre">WWWAuthenticate</span></code></a> object.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="werkzeug.http.parse_if_range_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_if_range_header</code><span class="sig-paren">(</span><em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_if_range_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Parses an if-range header which can be an etag or a date. Returns
a <a class="reference internal" href="datastructures.html#werkzeug.datastructures.IfRange" title="werkzeug.datastructures.IfRange"><code class="xref py py-class docutils literal"><span class="pre">IfRange</span></code></a> object.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.</span></p>
</div>
</dd></dl>
<dl class="function">
<dt id="werkzeug.http.parse_range_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_range_header</code><span class="sig-paren">(</span><em>value</em>, <em>make_inclusive=True</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_range_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Parses a range header into a <a class="reference internal" href="datastructures.html#werkzeug.datastructures.Range" title="werkzeug.datastructures.Range"><code class="xref py py-class docutils literal"><span class="pre">Range</span></code></a>
object. If the header is missing or malformed <cite>None</cite> is returned.
<cite>ranges</cite> is a list of <code class="docutils literal"><span class="pre">(start,</span> <span class="pre">stop)</span></code> tuples where the ranges are
non-inclusive.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.</span></p>
</div>
</dd></dl>
<dl class="function">
<dt id="werkzeug.http.parse_content_range_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_content_range_header</code><span class="sig-paren">(</span><em>value</em>, <em>on_update=None</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_content_range_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Parses a range header into a
<a class="reference internal" href="datastructures.html#werkzeug.datastructures.ContentRange" title="werkzeug.datastructures.ContentRange"><code class="xref py py-class docutils literal"><span class="pre">ContentRange</span></code></a> object or <cite>None</cite> if
parsing is not possible.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.</span></p>
</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>value</strong> – a content range header to be parsed.</li>
<li><strong>on_update</strong> – an optional callable that is called every time a value
on the <a class="reference internal" href="datastructures.html#werkzeug.datastructures.ContentRange" title="werkzeug.datastructures.ContentRange"><code class="xref py py-class docutils literal"><span class="pre">ContentRange</span></code></a>
object is changed.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</div>
<div class="section" id="header-utilities">
<h2>Header Utilities<a class="headerlink" href="#header-utilities" title="Permalink to this headline">¶</a></h2>
<p>The following utilities operate on HTTP headers well but do not parse
them. They are useful if you’re dealing with conditional responses or if
you want to proxy arbitrary requests but want to remove WSGI-unsupported
hop-by-hop headers. Also there is a function to create HTTP header
strings from the parsed data.</p>
<dl class="function">
<dt id="werkzeug.http.is_entity_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">is_entity_header</code><span class="sig-paren">(</span><em>header</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.is_entity_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Check if a header is an entity header.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</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"><strong>header</strong> – the header to test.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><cite>True</cite> if it’s an entity header, <cite>False</cite> otherwise.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="werkzeug.http.is_hop_by_hop_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">is_hop_by_hop_header</code><span class="sig-paren">(</span><em>header</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.is_hop_by_hop_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Check if a header is an HTTP/1.1 “Hop-by-Hop” header.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</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"><strong>header</strong> – the header to test.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><cite>True</cite> if it’s an entity header, <cite>False</cite> otherwise.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="werkzeug.http.remove_entity_headers">
<code class="descclassname">werkzeug.http.</code><code class="descname">remove_entity_headers</code><span class="sig-paren">(</span><em>headers</em>, <em>allowed=('expires'</em>, <em>'content-location')</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.remove_entity_headers" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove all entity headers from a list or <code class="xref py py-class docutils literal"><span class="pre">Headers</span></code> object. This
operation works in-place. <cite>Expires</cite> and <cite>Content-Location</cite> headers are
by default not removed. The reason for this is <span class="target" id="index-1"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2616.html"><strong>RFC 2616</strong></a> section
10.3.5 which specifies some entity headers that should be sent.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.5: </span>added <cite>allowed</cite> parameter.</p>
</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>headers</strong> – a list or <code class="xref py py-class docutils literal"><span class="pre">Headers</span></code> object.</li>
<li><strong>allowed</strong> – a list of headers that should still be allowed even though
they are entity headers.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="werkzeug.http.remove_hop_by_hop_headers">
<code class="descclassname">werkzeug.http.</code><code class="descname">remove_hop_by_hop_headers</code><span class="sig-paren">(</span><em>headers</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.remove_hop_by_hop_headers" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove all HTTP/1.1 “Hop-by-Hop” headers from a list or
<code class="xref py py-class docutils literal"><span class="pre">Headers</span></code> object. This operation works in-place.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</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"><strong>headers</strong> – a list or <code class="xref py py-class docutils literal"><span class="pre">Headers</span></code> object.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="werkzeug.http.is_byte_range_valid">
<code class="descclassname">werkzeug.http.</code><code class="descname">is_byte_range_valid</code><span class="sig-paren">(</span><em>start</em>, <em>stop</em>, <em>length</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.is_byte_range_valid" title="Permalink to this definition">¶</a></dt>
<dd><p>Checks if a given byte content range is valid for the given length.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.</span></p>
</div>
</dd></dl>
<dl class="function">
<dt id="werkzeug.http.quote_header_value">
<code class="descclassname">werkzeug.http.</code><code class="descname">quote_header_value</code><span class="sig-paren">(</span><em>value</em>, <em>extra_chars=''</em>, <em>allow_token=True</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.quote_header_value" title="Permalink to this definition">¶</a></dt>
<dd><p>Quote a header value if necessary.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</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>value</strong> – the value to quote.</li>
<li><strong>extra_chars</strong> – a list of extra characters to skip quoting.</li>
<li><strong>allow_token</strong> – if this is enabled token values are returned
unchanged.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="werkzeug.http.unquote_header_value">
<code class="descclassname">werkzeug.http.</code><code class="descname">unquote_header_value</code><span class="sig-paren">(</span><em>value</em>, <em>is_filename=False</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.unquote_header_value" title="Permalink to this definition">¶</a></dt>
<dd><p>Unquotes a header value. (Reversal of <a class="reference internal" href="#werkzeug.http.quote_header_value" title="werkzeug.http.quote_header_value"><code class="xref py py-func docutils literal"><span class="pre">quote_header_value()</span></code></a>).
This does not use the real unquoting but what browsers are actually
using for quoting.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.5.</span></p>
</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"><strong>value</strong> – the header value to unquote.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="werkzeug.http.dump_header">
<code class="descclassname">werkzeug.http.</code><code class="descname">dump_header</code><span class="sig-paren">(</span><em>iterable</em>, <em>allow_token=True</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.dump_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Dump an HTTP header again. This is the reversal of
<a class="reference internal" href="#werkzeug.http.parse_list_header" title="werkzeug.http.parse_list_header"><code class="xref py py-func docutils literal"><span class="pre">parse_list_header()</span></code></a>, <a class="reference internal" href="#werkzeug.http.parse_set_header" title="werkzeug.http.parse_set_header"><code class="xref py py-func docutils literal"><span class="pre">parse_set_header()</span></code></a> and
<a class="reference internal" href="#werkzeug.http.parse_dict_header" title="werkzeug.http.parse_dict_header"><code class="xref py py-func docutils literal"><span class="pre">parse_dict_header()</span></code></a>. This also quotes strings that include an
equals sign unless you pass it as dict of key, value pairs.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">dump_header</span><span class="p">({</span><span class="s1">'foo'</span><span class="p">:</span> <span class="s1">'bar baz'</span><span class="p">})</span>
<span class="go">'foo="bar baz"'</span>
<span class="gp">>>> </span><span class="n">dump_header</span><span class="p">((</span><span class="s1">'foo'</span><span class="p">,</span> <span class="s1">'bar baz'</span><span class="p">))</span>
<span class="go">'foo, "bar baz"'</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>iterable</strong> – the iterable or dict of values to quote.</li>
<li><strong>allow_token</strong> – if set to <cite>False</cite> tokens as values are disallowed.
See <a class="reference internal" href="#werkzeug.http.quote_header_value" title="werkzeug.http.quote_header_value"><code class="xref py py-func docutils literal"><span class="pre">quote_header_value()</span></code></a> for more details.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</div>
<div class="section" id="cookies">
<h2>Cookies<a class="headerlink" href="#cookies" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="werkzeug.http.parse_cookie">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_cookie</code><span class="sig-paren">(</span><em>header</em>, <em>charset='utf-8'</em>, <em>errors='replace'</em>, <em>cls=None</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_cookie" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse a cookie. Either from a string or WSGI environ.</p>
<p>Per default encoding errors are ignored. If you want a different behavior
you can set <cite>errors</cite> to <code class="docutils literal"><span class="pre">'replace'</span></code> or <code class="docutils literal"><span class="pre">'strict'</span></code>. In strict mode a
<code class="xref py py-exc docutils literal"><span class="pre">HTTPUnicodeError</span></code> is raised.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.5: </span>This function now returns a <code class="xref py py-class docutils literal"><span class="pre">TypeConversionDict</span></code> instead of a
regular dict. The <cite>cls</cite> parameter was added.</p>
</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>header</strong> – the header to be used to parse the cookie. Alternatively
this can be a WSGI environment.</li>
<li><strong>charset</strong> – the charset for the cookie values.</li>
<li><strong>errors</strong> – the error behavior for the charset decoding.</li>
<li><strong>cls</strong> – an optional dict class to use. If this is not specified
or <cite>None</cite> the default <code class="xref py py-class docutils literal"><span class="pre">TypeConversionDict</span></code> is
used.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="werkzeug.http.dump_cookie">
<code class="descclassname">werkzeug.http.</code><code class="descname">dump_cookie</code><span class="sig-paren">(</span><em>key</em>, <em>value=''</em>, <em>max_age=None</em>, <em>expires=None</em>, <em>path='/'</em>, <em>domain=None</em>, <em>secure=False</em>, <em>httponly=False</em>, <em>charset='utf-8'</em>, <em>sync_expires=True</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.dump_cookie" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a new Set-Cookie header without the <code class="docutils literal"><span class="pre">Set-Cookie</span></code> prefix
The parameters are the same as in the cookie Morsel object in the
Python standard library but it accepts unicode data, too.</p>
<p>On Python 3 the return value of this function will be a unicode
string, on Python 2 it will be a native string. In both cases the
return value is usually restricted to ascii as the vast majority of
values are properly escaped, but that is no guarantee. If a unicode
string is returned it’s tunneled through latin1 as required by
PEP 3333.</p>
<p>The return value is not ASCII safe if the key contains unicode
characters. This is technically against the specification but
happens in the wild. It’s strongly recommended to not use
non-ASCII values for the keys.</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>max_age</strong> – should be a number of seconds, or <cite>None</cite> (default) if
the cookie should last only as long as the client’s
browser session. Additionally <cite>timedelta</cite> objects
are accepted, too.</li>
<li><strong>expires</strong> – should be a <cite>datetime</cite> object or unix timestamp.</li>
<li><strong>path</strong> – limits the cookie to a given path, per default it will
span the whole domain.</li>
<li><strong>domain</strong> – Use this if you want to set a cross-domain cookie. For
example, <code class="docutils literal"><span class="pre">domain=".example.com"</span></code> will set a cookie
that is readable by the domain <code class="docutils literal"><span class="pre">www.example.com</span></code>,
<code class="docutils literal"><span class="pre">foo.example.com</span></code> etc. Otherwise, a cookie will only
be readable by the domain that set it.</li>
<li><strong>secure</strong> – The cookie will only be available via HTTPS</li>
<li><strong>httponly</strong> – disallow JavaScript to access the cookie. This is an
extension to the cookie standard and probably not
supported by all browsers.</li>
<li><strong>charset</strong> – the encoding for unicode values.</li>
<li><strong>sync_expires</strong> – automatically set expires if max_age is defined
but expires not.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</div>
<div class="section" id="conditional-response-helpers">
<h2>Conditional Response Helpers<a class="headerlink" href="#conditional-response-helpers" title="Permalink to this headline">¶</a></h2>
<p>For conditional responses the following functions might be useful:</p>
<dl class="function">
<dt id="werkzeug.http.parse_etags">
<code class="descclassname">werkzeug.http.</code><code class="descname">parse_etags</code><span class="sig-paren">(</span><em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.parse_etags" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse an etag header.</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 tag header to parse</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">an <a class="reference internal" href="datastructures.html#werkzeug.datastructures.ETags" title="werkzeug.datastructures.ETags"><code class="xref py py-class docutils literal"><span class="pre">ETags</span></code></a> object.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="werkzeug.http.quote_etag">
<code class="descclassname">werkzeug.http.</code><code class="descname">quote_etag</code><span class="sig-paren">(</span><em>etag</em>, <em>weak=False</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.quote_etag" title="Permalink to this definition">¶</a></dt>
<dd><p>Quote an etag.</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>etag</strong> – the etag to quote.</li>
<li><strong>weak</strong> – set to <cite>True</cite> to tag it “weak”.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="werkzeug.http.unquote_etag">
<code class="descclassname">werkzeug.http.</code><code class="descname">unquote_etag</code><span class="sig-paren">(</span><em>etag</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.unquote_etag" title="Permalink to this definition">¶</a></dt>
<dd><p>Unquote a single etag:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">unquote_etag</span><span class="p">(</span><span class="s1">'w/"bar"'</span><span class="p">)</span>
<span class="go">('bar', True)</span>
<span class="gp">>>> </span><span class="n">unquote_etag</span><span class="p">(</span><span class="s1">'"bar"'</span><span class="p">)</span>
<span class="go">('bar', False)</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"><strong>etag</strong> – the etag identifier to unquote.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">a <code class="docutils literal"><span class="pre">(etag,</span> <span class="pre">weak)</span></code> tuple.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="werkzeug.http.generate_etag">
<code class="descclassname">werkzeug.http.</code><code class="descname">generate_etag</code><span class="sig-paren">(</span><em>data</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.generate_etag" title="Permalink to this definition">¶</a></dt>
<dd><p>Generate an etag for some data.</p>
</dd></dl>
<dl class="function">
<dt id="werkzeug.http.is_resource_modified">
<code class="descclassname">werkzeug.http.</code><code class="descname">is_resource_modified</code><span class="sig-paren">(</span><em>environ</em>, <em>etag=None</em>, <em>data=None</em>, <em>last_modified=None</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.http.is_resource_modified" title="Permalink to this definition">¶</a></dt>
<dd><p>Convenience method for conditional requests.</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>environ</strong> – the WSGI environment of the request to be checked.</li>
<li><strong>etag</strong> – the etag for the response for comparison.</li>
<li><strong>data</strong> – or alternatively the data of the response to automatically
generate an etag using <a class="reference internal" href="#werkzeug.http.generate_etag" title="werkzeug.http.generate_etag"><code class="xref py py-func docutils literal"><span class="pre">generate_etag()</span></code></a>.</li>
<li><strong>last_modified</strong> – an optional date of the last modification.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"><cite>True</cite> if the resource was modified, otherwise <cite>False</cite>.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</div>
<div class="section" id="constants">
<h2>Constants<a class="headerlink" href="#constants" title="Permalink to this headline">¶</a></h2>
<dl class="data">
<dt id="werkzeug.http.HTTP_STATUS_CODES">
<code class="descclassname">werkzeug.http.</code><code class="descname">HTTP_STATUS_CODES</code><a class="headerlink" href="#werkzeug.http.HTTP_STATUS_CODES" title="Permalink to this definition">¶</a></dt>
<dd><p>A dict of status code -> default status message pairs. This is used
by the wrappers and other places where an integer status code is expanded
to a string throughout Werkzeug.</p>
</dd></dl>
</div>
<div class="section" id="module-werkzeug.formparser">
<span id="form-data-parsing"></span><h2>Form Data Parsing<a class="headerlink" href="#module-werkzeug.formparser" title="Permalink to this headline">¶</a></h2>
<p>Werkzeug provides the form parsing functions separately from the request
object so that you can access form data from a plain WSGI environment.</p>
<p>The following formats are currently supported by the form data parser:</p>
<ul class="simple">
<li><cite>application/x-www-form-urlencoded</cite></li>
<li><cite>multipart/form-data</cite></li>
</ul>
<p>Nested multipart is not currently supported (Werkzeug 0.9), but it isn’t used
by any of the modern web browsers.</p>
<p>Usage example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">cStringIO</span> <span class="kn">import</span> <span class="n">StringIO</span>
<span class="gp">>>> </span><span class="n">data</span> <span class="o">=</span> <span class="s1">'--foo</span><span class="se">\r\n</span><span class="s1">Content-Disposition: form-data; name="test"</span><span class="se">\r\n</span><span class="s1">'</span> \
<span class="gp">... </span><span class="s1">'</span><span class="se">\r\n</span><span class="s1">Hello World!</span><span class="se">\r\n</span><span class="s1">--foo--'</span>
<span class="gp">>>> </span><span class="n">environ</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'wsgi.input'</span><span class="p">:</span> <span class="n">StringIO</span><span class="p">(</span><span class="n">data</span><span class="p">),</span> <span class="s1">'CONTENT_LENGTH'</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)),</span>
<span class="gp">... </span> <span class="s1">'CONTENT_TYPE'</span><span class="p">:</span> <span class="s1">'multipart/form-data; boundary=foo'</span><span class="p">,</span>
<span class="gp">... </span> <span class="s1">'REQUEST_METHOD'</span><span class="p">:</span> <span class="s1">'POST'</span><span class="p">}</span>
<span class="gp">>>> </span><span class="n">stream</span><span class="p">,</span> <span class="n">form</span><span class="p">,</span> <span class="n">files</span> <span class="o">=</span> <span class="n">parse_form_data</span><span class="p">(</span><span class="n">environ</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">stream</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="go">''</span>
<span class="gp">>>> </span><span class="n">form</span><span class="p">[</span><span class="s1">'test'</span><span class="p">]</span>
<span class="go">u'Hello World!'</span>
<span class="gp">>>> </span><span class="ow">not</span> <span class="n">files</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Normally the WSGI environment is provided by the WSGI gateway with the
incoming data as part of it. If you want to generate such fake-WSGI
environments for unittesting you might want to use the
<code class="xref py py-func docutils literal"><span class="pre">create_environ()</span></code> function or the <code class="xref py py-class docutils literal"><span class="pre">EnvironBuilder</span></code> instead.</p>
<dl class="class">
<dt id="werkzeug.formparser.FormDataParser">
<em class="property">class </em><code class="descclassname">werkzeug.formparser.</code><code class="descname">FormDataParser</code><span class="sig-paren">(</span><em>stream_factory=None</em>, <em>charset='utf-8'</em>, <em>errors='replace'</em>, <em>max_form_memory_size=None</em>, <em>max_content_length=None</em>, <em>cls=None</em>, <em>silent=True</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.formparser.FormDataParser" title="Permalink to this definition">¶</a></dt>
<dd><p>This class implements parsing of form data for Werkzeug. By itself
it can parse multipart and url encoded form data. It can be subclassed
and extended but for most mimetypes it is a better idea to use the
untouched stream and expose it as separate attributes on a request
object.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.8.</span></p>
</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>stream_factory</strong> – An optional callable that returns a new read and
writeable file descriptor. This callable works
the same as <code class="xref py py-meth docutils literal"><span class="pre">_get_file_stream()</span></code>.</li>
<li><strong>charset</strong> – The character set for URL and url encoded form data.</li>
<li><strong>errors</strong> – The encoding error behavior.</li>
<li><strong>max_form_memory_size</strong> – the maximum number of bytes to be accepted for
in-memory stored form data. If the data
exceeds the value specified an
<code class="xref py py-exc docutils literal"><span class="pre">RequestEntityTooLarge</span></code>
exception is raised.</li>
<li><strong>max_content_length</strong> – If this is provided and the transmitted data
is longer than this value an
<code class="xref py py-exc docutils literal"><span class="pre">RequestEntityTooLarge</span></code>
exception is raised.</li>
<li><strong>cls</strong> – an optional dict class to use. If this is not specified
or <cite>None</cite> the default <code class="xref py py-class docutils literal"><span class="pre">MultiDict</span></code> is used.</li>
<li><strong>silent</strong> – If set to False parsing errors will not be caught.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="werkzeug.formparser.parse_form_data">
<code class="descclassname">werkzeug.formparser.</code><code class="descname">parse_form_data</code><span class="sig-paren">(</span><em>environ</em>, <em>stream_factory=None</em>, <em>charset='utf-8'</em>, <em>errors='replace'</em>, <em>max_form_memory_size=None</em>, <em>max_content_length=None</em>, <em>cls=None</em>, <em>silent=True</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.formparser.parse_form_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Parse the form data in the environ and return it as tuple in the form
<code class="docutils literal"><span class="pre">(stream,</span> <span class="pre">form,</span> <span class="pre">files)</span></code>. You should only call this method if the
transport method is <cite>POST</cite>, <cite>PUT</cite>, or <cite>PATCH</cite>.</p>
<p>If the mimetype of the data transmitted is <cite>multipart/form-data</cite> the
files multidict will be filled with <cite>FileStorage</cite> objects. If the
mimetype is unknown the input stream is wrapped and returned as first
argument, else the stream is empty.</p>
<p>This is a shortcut for the common usage of <a class="reference internal" href="#werkzeug.formparser.FormDataParser" title="werkzeug.formparser.FormDataParser"><code class="xref py py-class docutils literal"><span class="pre">FormDataParser</span></code></a>.</p>
<p>Have a look at <a class="reference internal" href="request_data.html#dealing-with-request-data"><span>Dealing with Request Data</span></a> for more details.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.5: </span>The <cite>max_form_memory_size</cite>, <cite>max_content_length</cite> and
<cite>cls</cite> parameters were added.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.5.1: </span>The optional <cite>silent</cite> flag was added.</p>
</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 simple">
<li><strong>environ</strong> – the WSGI environment to be used for parsing.</li>
<li><strong>stream_factory</strong> – An optional callable that returns a new read and
writeable file descriptor. This callable works
the same as <code class="xref py py-meth docutils literal"><span class="pre">_get_file_stream()</span></code>.</li>
<li><strong>charset</strong> – The character set for URL and url encoded form data.</li>
<li><strong>errors</strong> – The encoding error behavior.</li>
<li><strong>max_form_memory_size</strong> – the maximum number of bytes to be accepted for
in-memory stored form data. If the data
exceeds the value specified an
<code class="xref py py-exc docutils literal"><span class="pre">RequestEntityTooLarge</span></code>
exception is raised.</li>
<li><strong>max_content_length</strong> – If this is provided and the transmitted data
is longer than this value an
<code class="xref py py-exc docutils literal"><span class="pre">RequestEntityTooLarge</span></code>
exception is raised.</li>
<li><strong>cls</strong> – an optional dict class to use. If this is not specified
or <cite>None</cite> the default <code class="xref py py-class docutils literal"><span class="pre">MultiDict</span></code> is used.</li>
<li><strong>silent</strong> – If set to False parsing errors will not be caught.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">A tuple in the form <code class="docutils literal"><span class="pre">(stream,</span> <span class="pre">form,</span> <span class="pre">files)</span></code>.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="werkzeug.formparser.parse_multipart_headers">
<code class="descclassname">werkzeug.formparser.</code><code class="descname">parse_multipart_headers</code><span class="sig-paren">(</span><em>iterable</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.formparser.parse_multipart_headers" title="Permalink to this definition">¶</a></dt>
<dd><p>Parses multipart headers from an iterable that yields lines (including
the trailing newline symbol). The iterable has to be newline terminated.</p>
<p>The iterable will stop at the line where the headers ended so it can be
further consumed.</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>iterable</strong> – iterable of strings that are newline terminated</td>
</tr>
</tbody>
</table>
</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="#">HTTP Utilities</a><ul>
<li><a class="reference internal" href="#date-functions">Date Functions</a></li>
<li><a class="reference internal" href="#header-parsing">Header Parsing</a></li>
<li><a class="reference internal" href="#header-utilities">Header Utilities</a></li>
<li><a class="reference internal" href="#cookies">Cookies</a></li>
<li><a class="reference internal" href="#conditional-response-helpers">Conditional Response Helpers</a></li>
<li><a class="reference internal" href="#constants">Constants</a></li>
<li><a class="reference internal" href="#module-werkzeug.formparser">Form Data Parsing</a></li>
</ul>
</li>
</ul>
<h3>Related Topics</h3>
<ul>
<li><a href="index.html">Documentation overview</a><ul>
<li>Previous: <a href="wsgi.html" title="previous chapter">WSGI Helpers</a></li>
<li>Next: <a href="datastructures.html" title="next chapter">Data Structures</a></li>
</ul></li>
</ul>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/http.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>
|