Subclass WebOb Request and override relative_url (see #3)

master
Dustin C. Hatch 2012-11-03 19:03:13 -05:00
parent 3b6571623f
commit 2980b438da
4 changed files with 62 additions and 16 deletions

View File

@ -25,7 +25,8 @@ import sys, os
# Add any Sphinx extension module names here, as strings. They can be extensions # Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.todo', 'sphinx.ext.coverage', 'sphinx.ext.viewcode'] extensions = ['sphinx.ext.autodoc', 'sphinx.ext.todo', 'sphinx.ext.coverage',
'sphinx.ext.viewcode', 'sphinx.ext.intersphinx']
# Add any paths that contain templates here, relative to this directory. # Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates'] templates_path = ['_templates']
@ -86,6 +87,9 @@ pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting. # A list of ignored prefixes for module index sorting.
#modindex_common_prefix = [] #modindex_common_prefix = []
intersphinx_mapping = {
'webob': ('http://docs.webob.org/en/latest/', None)
}
# -- Options for HTML output --------------------------------------------------- # -- Options for HTML output ---------------------------------------------------

7
doc/reference/milla.rst Normal file
View File

@ -0,0 +1,7 @@
=====
milla
=====
.. automodule:: milla
:members:
:inherited-members:

View File

@ -20,6 +20,8 @@ from webob.exc import *
from webob.request import * from webob.request import *
from webob.response import * from webob.response import *
from auth.decorators import * from auth.decorators import *
import urllib
import urlparse
def allow(*methods): def allow(*methods):
'''Specify the allowed HTTP verbs for a controller callable '''Specify the allowed HTTP verbs for a controller callable
@ -35,3 +37,36 @@ def allow(*methods):
func.allowed_methods = methods func.allowed_methods = methods
return func return func
return wrapper return wrapper
class Response(Response):
''':py:class:`WebOb Response <webob.response.Response>` with minor tweaks
'''
class Request(Request):
''':py:class:`WebOb Request <webob.request.BaseRequest>` with minor tweaks
'''
ResponseClass = Response
def relative_url(self, other_url, to_application=True, path_only=True,
**vars):
'''Create a new URL relative to the request URL
:param other_url: relative path to join with the request URL
:param to_application: If true, generated URL will be relative
to the application's root path, otherwise relative to the
server root
:param path_only: If true, scheme and host will be omitted
Any other keyword arguments will be encoded and appended to the URL
as querystring arguments.
'''
url = super(Request, self).relative_url(other_url, to_application)
if path_only:
url = urlparse.urlsplit(url).path
if vars:
url += '?' + urllib.urlencode(vars)
return url

View File

@ -65,7 +65,7 @@ class Application(object):
else: else:
return HTTPNotFound()(environ, start_response) return HTTPNotFound()(environ, start_response)
request = webob.Request(environ) request = milla.Request(environ)
request.config = self.config.copy() request.config = self.config.copy()
# Sometimes, hacky applications will try to "emulate" some HTTP # Sometimes, hacky applications will try to "emulate" some HTTP