View
@@ -11,8 +11,7 @@ Introduction
============
This document covers all the details of the Request and Response
objects. It is written to be testable with `doctest
<http://python.org/doc/current/lib/module-doctest.html>`_ -- this
objects. It is written to be testable with :py:mod:`doctest` -- this
affects the flavor of the documentation, perhaps to its detriment.
But it also means you can feel confident that the documentation is
correct.
@@ -27,7 +26,7 @@ Request
=======
The primary object in WebOb is :py:class:`webob.Request`, a wrapper around a
`WSGI environment <http://www.python.org/dev/peps/pep-0333/>`_.
`WSGI environment <https://www.python.org/dev/peps/pep-0333/>`_.
The basic way you create a request object is simple enough:
@@ -51,9 +50,9 @@ use this exclusively of other libraries. If those other libraries
also keep their state in the environment, multiple wrappers can
coexist. Examples of libraries that can coexist include
`paste.wsgiwrappers.Request
<http://pythonpaste.org/class-paste.wsgiwrappers.WSGIRequest.html>`_
<https://bitbucket.org/ianb/paste/src/0e5a48796ab969d874c6b772c5c33561ac2d1b0d/paste/wsgiwrappers.py?at=default&fileviewer=file-view-default#wsgiwrappers.py-64>`_
(used by Pylons) and `yaro.Request
<http://lukearno.com/projects/yaro/>`_.
<https://pypi.python.org/pypi/yaro>`_.
The WSGI environment has a number of required variables. To make it
easier to test and play around with, the ``Request`` class has a
@@ -486,7 +485,7 @@ unchanged".
For more on this kind of conditional request, see `Detecting the Lost
Update Problem Using Unreserved Checkout
<http://www.w3.org/1999/04/Editing/>`_.
<https://www.w3.org/1999/04/Editing/>`_.
Calling WSGI Applications
-------------------------
@@ -811,8 +810,7 @@ You can also set Cache-Control related attributes with
>>> res.headers['Expires']
'... GMT'
You can also use the `timedelta
<http://python.org/doc/current/lib/datetime-timedelta.html>`_
You can also use the :py:class:`~datetime.timedelta`
constants defined, e.g.:
.. code-block:: python
@@ -955,8 +953,8 @@ request will an HTML response be given:
This is taken from `paste.httpexceptions
<http://pythonpaste.org/modules/httpexceptions.html#module-paste.httpexceptions>`_, and if
you have Paste installed then these exceptions will be subclasses of
<https://bitbucket.org/ianb/paste/src/0e5a48796ab969d874c6b772c5c33561ac2d1b0d/paste/httpexceptions.py?at=default&fileviewer=file-view-default#httpexceptions.py-8>`_,
and if you have Paste installed then these exceptions will be subclasses of
the Paste exceptions.
View
@@ -26,7 +26,7 @@ Code
The finished code for this is available in
`docs/wiki-example-code/example.py
<https://github.com/Pylons/webob/tree/master/docs/wiki-example-code/example.py>`_
<https://github.com/Pylons/webob/blob/master/docs/wiki-example-code/example.py>`_
-- you can run that file as a script to try it out.
Creating an Application
@@ -88,8 +88,7 @@ interface:
There's not much to talk about in this code block. The application is
instantiated and served with the built-in module
`wsgiref.simple_server
<http://www.python.org/doc/current/lib/module-wsgiref.simple_server.html>`_.
:py:mod:`wsgiref.simple_server`.
The WSGI Application
--------------------
@@ -351,9 +350,9 @@ page doesn't exist. ``exc.HTTPTemporaryRedirect`` is a response that
gives a ``307 Temporary Redirect`` response with the given location.
Otherwise we fill in a template. The template language we're going to
use in this example is `Tempita <http://pythonpaste.org/tempita/>`_, a
use in this example is `Tempita <https://pypi.python.org/pypi/Tempita>`_, a
very simple template language with a similar interface to
`string.Template <http://python.org/doc/current/lib/node40.html>`_.
:py:class:`string.Template`.
The template actually looks like this:
@@ -413,8 +412,7 @@ To allow conditional responses we set ``resp.last_modified``. You can
set this attribute to a date, None (effectively removing the header),
a time tuple (like produced by ``time.localtime()``), or as in this
case to an integer timestamp. If you get the value back it will
always be a `datetime
<http://python.org/doc/current/lib/datetime-datetime.html>`_ object
always be a :py:class:`~datetime.datetime` object
(or None). With this header we can process requests with
If-Modified-Since headers, and return ``304 Not Modified`` if
appropriate. It won't actually do that unless you set
@@ -479,7 +477,7 @@ In ``<form action="{{req.path_url}}" method="POST">`` we submit to
POSTing right over the view page. This has the nice side effect of
automatically invalidating any caches of the original page. It also
is vaguely `RESTful
<http://en.wikipedia.org/wiki/Representational_State_Transfer>`_.
<https://en.wikipedia.org/wiki/Representational_State_Transfer>`_.
We save the last modified time in a hidden ``mtime`` field. This way
we can detect concurrent updates. If start editing the page who's
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -159,8 +159,8 @@
References:
.. [1] http://www.python.org/peps/pep-0333.html#error-handling
.. [2] http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5
.. [1] https://www.python.org/dev/peps/pep-0333/#error-handling
.. [2] https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5
"""
@@ -1009,7 +1009,7 @@ class HTTPUnavailableForLegalReasons(HTTPClientError):
From the draft "A New HTTP Status Code for Legally-restricted Resources"
by Tim Bray:
http://tools.ietf.org/html/draft-tbray-http-legally-restricted-status-00
https://tools.ietf.org/html/draft-tbray-http-legally-restricted-status-00
code: 451, title: Unavailable For Legal Reasons
"""
View
@@ -13,12 +13,12 @@
from webob.acceptparse import (
AcceptEncoding,
AcceptLanguage,
AcceptCharset,
MIMEAccept,
MIMENilAccept,
NoAccept,
accept_property,
accept_language_property,
)
from webob.cachecontrol import (
@@ -1044,7 +1044,7 @@ def remove_conditional_headers(self,
accept_encoding = accept_property('Accept-Encoding', '14.3',
AcceptClass=AcceptEncoding,
NilClass=NoAccept)
accept_language = accept_property('Accept-Language', '14.4', AcceptLanguage)
accept_language = accept_language_property()
authorization = converter(
environ_getter('HTTP_AUTHORIZATION', None, '14.8'),
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -11,6 +11,11 @@
import pytest
from webob.acceptparse import (
AcceptLanguageInvalidHeader,
AcceptLanguageNoHeader,
AcceptLanguageValidHeader,
)
from webob.compat import (
bytes_,
native_,
@@ -701,7 +706,29 @@ def test_is_body_readable_special_flag(self):
# accept
# accept_charset
# accept_encoding
# accept_language
def test_accept_language_no_header(self):
req = self._makeOne(environ={})
header = req.accept_language
assert isinstance(header, AcceptLanguageNoHeader)
assert header.header_value is None
@pytest.mark.parametrize('header_value', ['', ', da;q=0.2, en-gb;q =0.3'])
def test_accept_language_invalid_header(self, header_value):
req = self._makeOne(environ={'HTTP_ACCEPT_LANGUAGE': header_value})
header = req.accept_language
assert isinstance(header, AcceptLanguageInvalidHeader)
assert header.header_value == header_value
def test_accept_language_valid_header(self):
header_value = \
'zh-Hant;q=0.372,zh-CN-a-myExt-x-private;q=0.977,de,*;q=0.000'
req = self._makeOne(environ={'HTTP_ACCEPT_LANGUAGE': header_value})
header = req.accept_language
assert isinstance(header, AcceptLanguageValidHeader)
assert header.header_value == header_value
# authorization
# cache_control