/usr/share/doc/python-webob-doc/index.html is in python-webob-doc 1:1.6.2-2.
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 | <!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>WebOb — WebOb 1.6.2 documentation</title>
<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '1.6.2',
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="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="top" title="WebOb 1.6.2 documentation" href="#" />
<link rel="next" title="WebOb Reference" href="reference.html" />
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
</head>
<body role="document">
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="webob">
<span id="index"></span><h1>WebOb<a class="headerlink" href="#webob" title="Permalink to this headline">¶</a></h1>
<p>WebOb provides objects for HTTP requests and responses. Specifically
it does this by wrapping the <a class="reference external" href="http://wsgi.org">WSGI</a> request
environment and response status/headers/app_iter(body).</p>
<p>The request and response objects provide many conveniences for parsing
HTTP request and forming HTTP responses. Both objects are read/write:
as a result, WebOb is also a nice way to create HTTP requests and
parse HTTP responses; however, we won’t cover that use case in this
document. The <a class="reference external" href="reference.html">reference documentation</a> shows many
examples of creating requests.</p>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="reference.html">WebOb Reference</a><ul>
<li class="toctree-l2"><a class="reference internal" href="reference.html#introduction">Introduction</a></li>
<li class="toctree-l2"><a class="reference internal" href="reference.html#request">Request</a></li>
<li class="toctree-l2"><a class="reference internal" href="reference.html#response">Response</a></li>
<li class="toctree-l2"><a class="reference internal" href="reference.html#exceptions">Exceptions</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="differences.html">Differences Between WebOb and Other Systems</a><ul>
<li class="toctree-l2"><a class="reference internal" href="differences.html#paste-wsgiwrappers-and-pylons">paste.wsgiwrappers and Pylons</a></li>
<li class="toctree-l2"><a class="reference internal" href="differences.html#django">Django</a></li>
<li class="toctree-l2"><a class="reference internal" href="differences.html#cherrypy-turbogears">CherryPy/TurboGears</a></li>
<li class="toctree-l2"><a class="reference internal" href="differences.html#yaro">Yaro</a></li>
<li class="toctree-l2"><a class="reference internal" href="differences.html#werkzeug">Werkzeug</a></li>
<li class="toctree-l2"><a class="reference internal" href="differences.html#zope-3">Zope 3</a></li>
<li class="toctree-l2"><a class="reference internal" href="differences.html#mod-python">mod_python</a></li>
<li class="toctree-l2"><a class="reference internal" href="differences.html#webapp-response">webapp Response</a></li>
<li class="toctree-l2"><a class="reference internal" href="differences.html#php">PHP</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="license.html">License</a></li>
</ul>
</div>
<div class="section" id="api-documentation">
<h2>API Documentation<a class="headerlink" href="#api-documentation" title="Permalink to this headline">¶</a></h2>
<p>Reference material for every public API exposed by WebOb:</p>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="api/client.html"><code class="docutils literal"><span class="pre">webob.client</span></code> – Send WSGI requests over HTTP</a></li>
<li class="toctree-l1"><a class="reference internal" href="api/cookies.html"><code class="docutils literal"><span class="pre">webob.cookies</span></code> – Cookies</a></li>
<li class="toctree-l1"><a class="reference internal" href="api/dec.html"><code class="docutils literal"><span class="pre">webob.dec</span></code> – WSGIfy decorator</a></li>
<li class="toctree-l1"><a class="reference internal" href="api/exceptions.html"><code class="docutils literal"><span class="pre">webob.exc</span></code> – WebOb Exceptions</a></li>
<li class="toctree-l1"><a class="reference internal" href="api/multidict.html"><code class="docutils literal"><span class="pre">webob.multidict</span></code> – multi-value dictionary object</a></li>
<li class="toctree-l1"><a class="reference internal" href="api/request.html"><code class="docutils literal"><span class="pre">webob.request</span></code> – Request</a></li>
<li class="toctree-l1"><a class="reference internal" href="api/response.html"><code class="docutils literal"><span class="pre">webob.response</span></code> – Response</a></li>
<li class="toctree-l1"><a class="reference internal" href="api/static.html"><code class="docutils literal"><span class="pre">webob.static</span></code> – Serving static files</a></li>
<li class="toctree-l1"><a class="reference internal" href="api/webob.html"><code class="docutils literal"><span class="pre">webob</span></code> – Request/Response objects</a></li>
</ul>
</div>
</div>
<div class="section" id="request">
<h2>Request<a class="headerlink" href="#request" title="Permalink to this headline">¶</a></h2>
<p>The request object is a wrapper around the <a class="reference external" href="http://www.python.org/dev/peps/pep-0333/#environ-variables">WSGI environ dictionary</a>. This
dictionary contains keys for each header, keys that describe the
request (including the path and query string), a file-like object for
the request body, and a variety of custom keys. You can always access
the environ with <code class="docutils literal"><span class="pre">req.environ</span></code>.</p>
<p>Some of the most important/interesting attributes of a request
object:</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">req.method</span></code>:</dt>
<dd>The request method, e.g., <code class="docutils literal"><span class="pre">'GET'</span></code>, <code class="docutils literal"><span class="pre">'POST'</span></code></dd>
<dt><code class="docutils literal"><span class="pre">req.GET</span></code>:</dt>
<dd>A <a class="reference external" href="#multidict">dictionary-like object</a> with all the variables in the query
string.</dd>
<dt><code class="docutils literal"><span class="pre">req.POST</span></code>:</dt>
<dd>A <a class="reference external" href="#multidict">dictionary-like object</a> with all the variables in the request
body. This only has variables if the request was a <code class="docutils literal"><span class="pre">POST</span></code> and
it is a form submission.</dd>
<dt><code class="docutils literal"><span class="pre">req.params</span></code>:</dt>
<dd>A <a class="reference external" href="#multidict">dictionary-like object</a> with a combination of everything in
<code class="docutils literal"><span class="pre">req.GET</span></code> and <code class="docutils literal"><span class="pre">req.POST</span></code>.</dd>
<dt><code class="docutils literal"><span class="pre">req.body</span></code>:</dt>
<dd>The contents of the body of the request. This contains the entire
request body as a string. This is useful when the request is a
<code class="docutils literal"><span class="pre">POST</span></code> that is <em>not</em> a form submission, or a request like a
<code class="docutils literal"><span class="pre">PUT</span></code>. You can also get <code class="docutils literal"><span class="pre">req.body_file</span></code> for a file-like
object.</dd>
<dt><code class="docutils literal"><span class="pre">req.cookies</span></code>:</dt>
<dd>A simple dictionary of all the cookies.</dd>
<dt><code class="docutils literal"><span class="pre">req.headers</span></code>:</dt>
<dd>A dictionary of all the headers. This is dictionary is case-insensitive.</dd>
<dt><code class="docutils literal"><span class="pre">req.urlvars</span></code> and <code class="docutils literal"><span class="pre">req.urlargs</span></code>:</dt>
<dd><code class="docutils literal"><span class="pre">req.urlvars</span></code> is the keyword parameters associated with the
request URL. <code class="docutils literal"><span class="pre">req.urlargs</span></code> are the positional parameters.
These are set by products like <a class="reference external" href="http://routes.groovie.org/">Routes</a> and <a class="reference external" href="http://lukearno.com/projects/selector/">Selector</a>.</dd>
</dl>
<p>Also, for standard HTTP request headers there are usually attributes,
for instance: <code class="docutils literal"><span class="pre">req.accept_language</span></code>, <code class="docutils literal"><span class="pre">req.content_length</span></code>,
<code class="docutils literal"><span class="pre">req.user_agent</span></code>, as an example. These properties expose the
<em>parsed</em> form of each header, for whatever parsing makes sense. For
instance, <code class="docutils literal"><span class="pre">req.if_modified_since</span></code> returns a <a class="reference external" href="http://python.org/doc/current/lib/datetime-datetime.html">datetime</a> object
(or None if the header is was not provided). Details are in the
<a class="reference external" href="class-webob.Request.html">Request reference</a>.</p>
<div class="section" id="urls">
<h3>URLs<a class="headerlink" href="#urls" title="Permalink to this headline">¶</a></h3>
<p>In addition to these attributes, there are several ways to get the URL
of the request. I’ll show various values for an example URL
<code class="docutils literal"><span class="pre">http://localhost/app-root/doc?article_id=10</span></code>, where the application
is mounted at <code class="docutils literal"><span class="pre">http://localhost/app-root</span></code>.</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">req.url</span></code>:</dt>
<dd>The full request URL, with query string, e.g.,
<code class="docutils literal"><span class="pre">'http://localhost/app-root/doc?article_id=10'</span></code></dd>
<dt><code class="docutils literal"><span class="pre">req.application_url</span></code>:</dt>
<dd>The URL of the application (just the SCRIPT_NAME portion of the
path, not PATH_INFO). E.g., <code class="docutils literal"><span class="pre">'http://localhost/app-root'</span></code></dd>
<dt><code class="docutils literal"><span class="pre">req.host_url</span></code>:</dt>
<dd>The URL with the host, e.g., <code class="docutils literal"><span class="pre">'http://localhost'</span></code></dd>
<dt><code class="docutils literal"><span class="pre">req.relative_url(url,</span> <span class="pre">to_application=False)</span></code>:</dt>
<dd>Gives a URL, relative to the current URL. If <code class="docutils literal"><span class="pre">to_application</span></code>
is True, then resolves it relative to <code class="docutils literal"><span class="pre">req.application_url</span></code>.</dd>
</dl>
</div>
<div class="section" id="methods">
<h3>Methods<a class="headerlink" href="#methods" title="Permalink to this headline">¶</a></h3>
<p>There are several methods in <code class="xref py py-class docutils literal"><span class="pre">webob.Request</span></code> but only a few you’ll use
often:</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">Request.blank(base_url)</span></code>:</dt>
<dd>Creates a new request with blank information, based at the given
URL. This can be useful for subrequests and artificial requests.
You can also use <code class="docutils literal"><span class="pre">req.copy()</span></code> to copy an existing request, or
for subrequests <code class="docutils literal"><span class="pre">req.copy_get()</span></code> which copies the request but
always turns it into a GET (which is safer to share for
subrequests).</dd>
<dt><code class="docutils literal"><span class="pre">req.get_response(wsgi_application)</span></code>:</dt>
<dd>This method calls the given WSGI application with this request,
and returns a <a class="reference internal" href="#response">Response</a> object. You can also use this for
subrequests or testing.</dd>
</dl>
</div>
<div class="section" id="unicode">
<h3>Unicode<a class="headerlink" href="#unicode" title="Permalink to this headline">¶</a></h3>
<p>Many of the properties in the request object will return unicode
values if the request encoding/charset is provided. The client <em>can</em>
indicate the charset with something like <code class="docutils literal"><span class="pre">Content-Type:</span>
<span class="pre">application/x-www-form-urlencoded;</span> <span class="pre">charset=utf8</span></code>, but browsers seldom
set this. You can set the charset with <code class="docutils literal"><span class="pre">req.charset</span> <span class="pre">=</span> <span class="pre">'utf8'</span></code>, or
during instantiation with <code class="docutils literal"><span class="pre">Request(environ,</span> <span class="pre">charset='utf8')</span></code>. If
you subclass <code class="docutils literal"><span class="pre">Request</span></code> you can also set <code class="docutils literal"><span class="pre">charset</span></code> as a class-level
attribute.</p>
<p>If it is set, then <code class="docutils literal"><span class="pre">req.POST</span></code>, <code class="docutils literal"><span class="pre">req.GET</span></code>, <code class="docutils literal"><span class="pre">req.params</span></code>, and
<code class="docutils literal"><span class="pre">req.cookies</span></code> will contain unicode strings.</p>
</div>
</div>
<div class="section" id="response">
<h2>Response<a class="headerlink" href="#response" title="Permalink to this headline">¶</a></h2>
<p>The response object looks a lot like the request object, though with
some differences. The request object wraps a single <code class="docutils literal"><span class="pre">environ</span></code>
object; the response object has three fundamental parts (based on
WSGI):</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">response.status</span></code>:</dt>
<dd>The response code plus message, like <code class="docutils literal"><span class="pre">'200</span> <span class="pre">OK'</span></code>. To set the
code without the reason, use <code class="docutils literal"><span class="pre">response.status_code</span> <span class="pre">=</span> <span class="pre">200</span></code>.</dd>
<dt><code class="docutils literal"><span class="pre">response.headerlist</span></code>:</dt>
<dd>A list of all the headers, like <code class="docutils literal"><span class="pre">[('Content-Type',</span>
<span class="pre">'text/html')]</span></code>. There’s a case-insensitive <a class="reference external" href="#multidict">dictionary-like
object</a> in <code class="docutils literal"><span class="pre">response.headers</span></code> that also allows you to access
these same headers.</dd>
<dt><code class="docutils literal"><span class="pre">response.app_iter</span></code>:</dt>
<dd>An iterable (such as a list or generator) that will produce the
content of the response. This is also accessible as
<code class="docutils literal"><span class="pre">response.body</span></code> (a string), <code class="docutils literal"><span class="pre">response.unicode_body</span></code> (a
unicode object, informed by <code class="docutils literal"><span class="pre">response.charset</span></code>), and
<code class="docutils literal"><span class="pre">response.body_file</span></code> (a file-like object; writing to it appends
to <code class="docutils literal"><span class="pre">app_iter</span></code>).</dd>
</dl>
<p>Everything else in the object derives from this underlying state.
Here’s the highlights:</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">response.content_type</span></code>:</dt>
<dd>The content type <em>not</em> including the <code class="docutils literal"><span class="pre">charset</span></code> parameter.
Typical use: <code class="docutils literal"><span class="pre">response.content_type</span> <span class="pre">=</span> <span class="pre">'text/html'</span></code>. You can
subclass <code class="docutils literal"><span class="pre">Response</span></code> and add a class-level attribute
<code class="docutils literal"><span class="pre">default_content_type</span></code> to set this automatically on
instantiation.</dd>
<dt><code class="docutils literal"><span class="pre">response.charset</span></code>:</dt>
<dd>The <code class="docutils literal"><span class="pre">charset</span></code> parameter of the content-type, it also informs
encoding in <code class="docutils literal"><span class="pre">response.unicode_body</span></code>.
<code class="docutils literal"><span class="pre">response.content_type_params</span></code> is a dictionary of all the
parameters.</dd>
<dt><code class="docutils literal"><span class="pre">response.request</span></code>:</dt>
<dd>This optional attribute can point to the request object associated
with this response object.</dd>
<dt><code class="docutils literal"><span class="pre">response.set_cookie(key,</span> <span class="pre">value,</span> <span class="pre">max_age=None,</span> <span class="pre">path='/',</span> <span class="pre">domain=None,</span> <span class="pre">secure=None,</span> <span class="pre">httponly=False,</span> <span class="pre">version=None,</span> <span class="pre">comment=None)</span></code>:</dt>
<dd>Set a cookie. The keyword arguments control the various cookie
parameters. The <code class="docutils literal"><span class="pre">max_age</span></code> argument is the length for the cookie
to live in seconds (you may also use a timedelta object). The
<cite>Expires`</cite> key will also be set based on the value of <code class="docutils literal"><span class="pre">max_age</span></code>.</dd>
<dt><code class="docutils literal"><span class="pre">response.delete_cookie(key,</span> <span class="pre">path='/',</span> <span class="pre">domain=None)</span></code>:</dt>
<dd>Delete a cookie from the client. This sets <code class="docutils literal"><span class="pre">max_age</span></code> to 0 and
the cookie value to <code class="docutils literal"><span class="pre">''</span></code>.</dd>
<dt><code class="docutils literal"><span class="pre">response.cache_expires(seconds=0)</span></code>:</dt>
<dd>This makes this response cachable for the given number of seconds,
or if <code class="docutils literal"><span class="pre">seconds</span></code> is 0 then the response is uncacheable (this also
sets the <code class="docutils literal"><span class="pre">Expires</span></code> header).</dd>
<dt><code class="docutils literal"><span class="pre">response(environ,</span> <span class="pre">start_response)</span></code>: The response object is a WSGI</dt>
<dd>application. As an application, it acts according to how you
create it. It <em>can</em> do conditional responses if you pass
<code class="docutils literal"><span class="pre">conditional_response=True</span></code> when instantiating (or set that
attribute later). It can also do HEAD and Range requests.</dd>
</dl>
<div class="section" id="headers">
<h3>Headers<a class="headerlink" href="#headers" title="Permalink to this headline">¶</a></h3>
<p>Like the request, most HTTP response headers are available as
properties. These are parsed, so you can do things like
<code class="docutils literal"><span class="pre">response.last_modified</span> <span class="pre">=</span> <span class="pre">os.path.getmtime(filename)</span></code>.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="api/response.html#webob.response.Response" title="webob.response.Response"><code class="xref py py-class docutils literal"><span class="pre">webob.response.Response</span></code></a></p>
</div>
</div>
<div class="section" id="instantiating-the-response">
<h3>Instantiating the Response<a class="headerlink" href="#instantiating-the-response" title="Permalink to this headline">¶</a></h3>
<p>Of course most of the time you just want to <em>make</em> a response.
Generally any attribute of the response can be passed in as a keyword
argument to the class; e.g.:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">response</span> <span class="o">=</span> <span class="n">Response</span><span class="p">(</span><span class="n">body</span><span class="o">=</span><span class="s1">'hello world!'</span><span class="p">,</span> <span class="n">content_type</span><span class="o">=</span><span class="s1">'text/plain'</span><span class="p">)</span>
</pre></div>
</div>
<p>The status defaults to <code class="docutils literal"><span class="pre">'200</span> <span class="pre">OK'</span></code>. The content_type does not
default to anything, though if you subclass <code class="docutils literal"><span class="pre">Response</span></code> and set
<code class="docutils literal"><span class="pre">default_content_type</span></code> you can override this behavior.</p>
</div>
</div>
<div class="section" id="exceptions">
<h2>Exceptions<a class="headerlink" href="#exceptions" title="Permalink to this headline">¶</a></h2>
<p>To facilitate error responses like 404 Not Found, the module
<code class="docutils literal"><span class="pre">webob.exc</span></code> contains classes for each kind of error response. These
include boring but appropriate error bodies.</p>
<p>Each class is named <code class="docutils literal"><span class="pre">webob.exc.HTTP*</span></code>, where <code class="docutils literal"><span class="pre">*</span></code> is the reason for
the error. For instance, <code class="docutils literal"><span class="pre">webob.exc.HTTPNotFound</span></code>. It subclasses
<code class="docutils literal"><span class="pre">Response</span></code>, so you can manipulate the instances in the same way. A
typical example is:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">response</span> <span class="o">=</span> <span class="n">HTTPNotFound</span><span class="p">(</span><span class="s1">'There is no such resource'</span><span class="p">)</span>
<span class="c1"># or:</span>
<span class="n">response</span> <span class="o">=</span> <span class="n">HTTPMovedPermanently</span><span class="p">(</span><span class="n">location</span><span class="o">=</span><span class="n">new_url</span><span class="p">)</span>
</pre></div>
</div>
<p>You can use this like:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">try</span><span class="p">:</span>
<span class="o">...</span> <span class="n">stuff</span> <span class="o">...</span>
<span class="k">raise</span> <span class="n">HTTPNotFound</span><span class="p">(</span><span class="s1">'No such resource'</span><span class="p">)</span>
<span class="k">except</span> <span class="n">HTTPException</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span>
<span class="k">return</span> <span class="n">e</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>The exceptions are still WSGI applications, but you cannot set
attributes like <code class="docutils literal"><span class="pre">content_type</span></code>, <code class="docutils literal"><span class="pre">charset</span></code>, etc. on these exception
objects.</p>
</div>
<div class="section" id="multidict">
<h2>Multidict<a class="headerlink" href="#multidict" title="Permalink to this headline">¶</a></h2>
<p>Several parts of WebOb use a “multidict”; this is a dictionary where a
key can have multiple values. The quintessential example is a query
string like <code class="docutils literal"><span class="pre">?pref=red&pref=blue</span></code>; the <code class="docutils literal"><span class="pre">pref</span></code> variable has two
values: <code class="docutils literal"><span class="pre">red</span></code> and <code class="docutils literal"><span class="pre">blue</span></code>.</p>
<p>In a multidict, when you do <code class="docutils literal"><span class="pre">request.GET['pref']</span></code> you’ll get back
only <code class="docutils literal"><span class="pre">'blue'</span></code> (the last value of <code class="docutils literal"><span class="pre">pref</span></code>). Sometimes returning a
string, and sometimes returning a list, is the cause of frequent
exceptions. If you want <em>all</em> the values back, use
<code class="docutils literal"><span class="pre">request.GET.getall('pref')</span></code>. If you want to be sure there is <em>one
and only one</em> value, use <code class="docutils literal"><span class="pre">request.GET.getone('pref')</span></code>, which will
raise an exception if there is zero or more than one value for
<code class="docutils literal"><span class="pre">pref</span></code>.</p>
<p>When you use operations like <code class="docutils literal"><span class="pre">request.GET.items()</span></code> you’ll get back
something like <code class="docutils literal"><span class="pre">[('pref',</span> <span class="pre">'red'),</span> <span class="pre">('pref',</span> <span class="pre">'blue')]</span></code>. All the
key/value pairs will show up. Similarly <code class="docutils literal"><span class="pre">request.GET.keys()</span></code>
returns <code class="docutils literal"><span class="pre">['pref',</span> <span class="pre">'pref']</span></code>. Multidict is a view on a list of
tuples; all the keys are ordered, and all the values are ordered.</p>
</div>
<div class="section" id="example">
<h2>Example<a class="headerlink" href="#example" title="Permalink to this headline">¶</a></h2>
<p>The <a class="reference external" href="file-example.html">file-serving example</a> shows how to do more
advanced HTTP techniques, while the <a class="reference external" href="comment-example.html">comment middleware example</a> shows middleware. For applications it’s more
reasonable to use WebOb in the context of a larger framework. <a class="reference external" href="http://pylonshq.com">Pylons</a> uses WebOb in 0.9.7+.</p>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="file-example.html">WebOb File-Serving Example</a></li>
<li class="toctree-l1"><a class="reference internal" href="wiki-example.html">Wiki Example</a></li>
<li class="toctree-l1"><a class="reference internal" href="comment-example.html">Comment Example</a></li>
<li class="toctree-l1"><a class="reference internal" href="jsonrpc-example.html">JSON-RPC Example</a></li>
<li class="toctree-l1"><a class="reference internal" href="do-it-yourself.html">Another Do-It-Yourself Framework</a></li>
</ul>
</div>
</div>
<div class="section" id="change-history">
<h2>Change History<a class="headerlink" href="#change-history" title="Permalink to this headline">¶</a></h2>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="whatsnew-1.5.html">What’s New in WebOb 1.5</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatsnew-1.6.html">What’s New in WebOb 1.6</a></li>
<li class="toctree-l1"><a class="reference internal" href="changes.html">WebOb Change History</a></li>
</ul>
</div>
</div>
<div class="section" id="status-license">
<h2>Status & License<a class="headerlink" href="#status-license" title="Permalink to this headline">¶</a></h2>
<p>WebOb is an extraction and refinement of pieces from <a class="reference external" href="http://pythonpaste.org/">Paste</a>. It is under active development. Discussion
should happen on the <a class="reference external" href="http://groups.google.com/group/pylons-discuss">Pylons-discuss maillist</a>, and bugs can go on the
<a class="reference external" href="https://github.com/Pylons/webob/issues">issue tracker</a>. It was originally
written by <a class="reference external" href="http://ianbicking.org/">Ian Bicking</a>, and is being maintained by
the <a class="reference external" href="http://www.pylonsproject.org/">Pylons Project</a>.</p>
<p>If you’ve got questions that aren’t answered by this documentation, contact the
<a class="reference external" href="http://groups.google.com/group/pylons-discuss">Pylons-discuss maillist</a> or
join the <a class="reference external" href="irc://irc.freenode.net/#pyramid">#pyramid IRC channel</a>.</p>
<p>WebOb is released under an <a class="reference internal" href="license.html"><span class="doc">MIT-style license</span></a>.</p>
<p>WebOb development happens on <a class="reference external" href="https://github.com/Pylons/webob">GitHub</a>.
Development version is installable via <a class="reference external" href="https://github.com/Pylons/webob/zipball/master">easy_install
webob==dev</a>. You
can clone the source code with:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>$ git clone https://github.com/Pylons/webob.git
</pre></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="#">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">WebOb</a><ul>
<li><a class="reference internal" href="#api-documentation">API Documentation</a></li>
<li><a class="reference internal" href="#request">Request</a><ul>
<li><a class="reference internal" href="#urls">URLs</a></li>
<li><a class="reference internal" href="#methods">Methods</a></li>
<li><a class="reference internal" href="#unicode">Unicode</a></li>
</ul>
</li>
<li><a class="reference internal" href="#response">Response</a><ul>
<li><a class="reference internal" href="#headers">Headers</a></li>
<li><a class="reference internal" href="#instantiating-the-response">Instantiating the Response</a></li>
</ul>
</li>
<li><a class="reference internal" href="#exceptions">Exceptions</a></li>
<li><a class="reference internal" href="#multidict">Multidict</a></li>
<li><a class="reference internal" href="#example">Example</a></li>
<li><a class="reference internal" href="#change-history">Change History</a></li>
<li><a class="reference internal" href="#status-license">Status & License</a></li>
</ul>
</li>
</ul>
<div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="#">Documentation overview</a><ul>
<li>Next: <a href="reference.html" title="next chapter">WebOb Reference</a></li>
</ul></li>
</ul>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/index.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">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
©2017, Ian Bicking and contributors.
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 1.4.9</a>
& <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.8</a>
|
<a href="_sources/index.txt"
rel="nofollow">Page source</a>
</div>
</body>
</html>
|