/usr/share/doc/python-werkzeug-doc/html/levels.html is in python-werkzeug-doc 0.9.4+dfsg-1.1ubuntu1.
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 | <!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>API Levels — Werkzeug 0.9.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.9.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.9.4 documentation" href="index.html" />
<link rel="next" title="Quickstart" href="quickstart.html" />
<link rel="prev" title="Werkzeug Tutorial" href="tutorial.html" />
</head>
<body>
<div class="related">
<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="quickstart.html" title="Quickstart"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="tutorial.html" title="Werkzeug Tutorial"
accesskey="P">previous</a> |</li>
<li><a href="index.html">Werkzeug 0.9.4 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="module-werkzeug">
<span id="api-levels"></span><h1>API Levels<a class="headerlink" href="#module-werkzeug" title="Permalink to this headline">¶</a></h1>
<p>Werkzeug is intended to be a utility rather than a framework. Because of that
the user-friendly API is separated from the lower-level API so that Werkzeug
can easily be used to extend another system.</p>
<p>All the functionality the <tt class="xref py py-class docutils literal"><span class="pre">Request</span></tt> and <tt class="xref py py-class docutils literal"><span class="pre">Response</span></tt> objects (aka
the “wrappers”) provide is also available in small utility functions.</p>
<div class="section" id="example">
<h2>Example<a class="headerlink" href="#example" title="Permalink to this headline">¶</a></h2>
<p>This example implements a small <cite>Hello World</cite> application that greets the
user with the name entered:</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">escape</span>
<span class="kn">from</span> <span class="nn">werkzeug.wrappers</span> <span class="kn">import</span> <span class="n">Request</span><span class="p">,</span> <span class="n">Response</span>
<span class="nd">@Request.application</span>
<span class="k">def</span> <span class="nf">hello_world</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
<span class="n">result</span> <span class="o">=</span> <span class="p">[</span><span class="s">'<title>Greeter</title>'</span><span class="p">]</span>
<span class="k">if</span> <span class="n">request</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s">'POST'</span><span class="p">:</span>
<span class="n">result</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">'<h1>Hello </span><span class="si">%s</span><span class="s">!</h1>'</span> <span class="o">%</span> <span class="n">escape</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">form</span><span class="p">[</span><span class="s">'name'</span><span class="p">]))</span>
<span class="n">result</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">'''</span>
<span class="s"> <form action="" method="post"></span>
<span class="s"> <p>Name: <input type="text" name="name" size="20"></span>
<span class="s"> <input type="submit" value="Greet me"></span>
<span class="s"> </form></span>
<span class="s"> '''</span><span class="p">)</span>
<span class="k">return</span> <span class="n">Response</span><span class="p">(</span><span class="s">''</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">result</span><span class="p">),</span> <span class="n">mimetype</span><span class="o">=</span><span class="s">'text/html'</span><span class="p">)</span>
</pre></div>
</div>
<p>Alternatively the same application could be used without request and response
objects but by taking advantage of the parsing functions werkzeug provides:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">werkzeug.formparser</span> <span class="kn">import</span> <span class="n">parse_form_data</span>
<span class="kn">from</span> <span class="nn">werkzeug.utils</span> <span class="kn">import</span> <span class="n">escape</span>
<span class="k">def</span> <span class="nf">hello_world</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">result</span> <span class="o">=</span> <span class="p">[</span><span class="s">'<title>Greeter</title>'</span><span class="p">]</span>
<span class="k">if</span> <span class="n">environ</span><span class="p">[</span><span class="s">'REQUEST_METHOD'</span><span class="p">]</span> <span class="o">==</span> <span class="s">'POST'</span><span class="p">:</span>
<span class="n">form</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="mi">1</span><span class="p">]</span>
<span class="n">result</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">'<h1>Hello </span><span class="si">%s</span><span class="s">!</h1>'</span> <span class="o">%</span> <span class="n">escape</span><span class="p">(</span><span class="n">form</span><span class="p">[</span><span class="s">'name'</span><span class="p">]))</span>
<span class="n">result</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">'''</span>
<span class="s"> <form action="" method="post"></span>
<span class="s"> <p>Name: <input type="text" name="name" size="20"></span>
<span class="s"> <input type="submit" value="Greet me"></span>
<span class="s"> </form></span>
<span class="s"> '''</span><span class="p">)</span>
<span class="n">start_response</span><span class="p">(</span><span class="s">'200 OK'</span><span class="p">,</span> <span class="p">[(</span><span class="s">'Content-Type'</span><span class="p">,</span> <span class="s">'text/html; charset=utf-8'</span><span class="p">)])</span>
<span class="k">return</span> <span class="p">[</span><span class="s">''</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">result</span><span class="p">)]</span>
</pre></div>
</div>
</div>
<div class="section" id="high-or-low">
<h2>High or Low?<a class="headerlink" href="#high-or-low" title="Permalink to this headline">¶</a></h2>
<p>Usually you want to use the high-level layer (the request and response
objects). But there are situations where this might not be what you want.</p>
<p>For example you might be maintaining code for an application written in
Django or another framework and you have to parse HTTP headers. You can
utilize Werkzeug for that by accessing the lower-level HTTP header parsing
functions.</p>
<p>Another situation where the low level parsing functions can be useful are
custom WSGI frameworks, unit-testing or modernizing an old CGI/mod_python
application to WSGI as well as WSGI middlewares where you want to keep the
overhead low.</p>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<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="#">API Levels</a><ul>
<li><a class="reference internal" href="#example">Example</a></li>
<li><a class="reference internal" href="#high-or-low">High or Low?</a></li>
</ul>
</li>
</ul>
<h3>Related Topics</h3>
<ul>
<li><a href="index.html">Documentation overview</a><ul>
<li>Previous: <a href="tutorial.html" title="previous chapter">Werkzeug Tutorial</a></li>
<li>Next: <a href="quickstart.html" title="next chapter">Quickstart</a></li>
</ul></li>
</ul>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/levels.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<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>
|