sphinx-compatible docstrings

This commit is contained in:
niphlod
2014-03-12 22:03:42 +01:00
parent eb435e785c
commit e209dcc8d3
5 changed files with 86 additions and 82 deletions
+53 -54
View File
@@ -2,9 +2,9 @@
# -*- coding: utf-8 -*-
"""
This file is part of the web2py Web Framework
Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)
| This file is part of the web2py Web Framework
| Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
| License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)
gluon.rewrite parses incoming URLs and formats outgoing URLs for gluon.html.URL.
@@ -57,7 +57,7 @@ regex_args = re.compile('[^\w/.@=-]')
def _router_default():
"return new copy of default base router"
"Returns new copy of default base router"
router = Storage(
default_application='init',
applications='ALL',
@@ -85,7 +85,7 @@ def _router_default():
def _params_default(app=None):
"return new copy of default parameters"
"Returns a new copy of default parameters"
p = Storage()
p.name = app or "BASE"
p.default_application = app or "init"
@@ -181,7 +181,7 @@ def fixup_missing_path_info(environ):
def url_in(request, environ):
"parse and rewrite incoming URL"
"Parses and rewrites incoming URL"
if routers:
return map_url_in(request, environ)
return regex_url_in(request, environ)
@@ -189,7 +189,7 @@ def url_in(request, environ):
def url_out(request, environ, application, controller, function,
args, other, scheme, host, port, language=None):
"assemble and rewrite outgoing URL"
"Assembles and rewrites outgoing URL"
if routers:
acf = map_url_out(request, environ, application, controller,
function, args, other, scheme, host, port, language)
@@ -214,7 +214,7 @@ def url_out(request, environ, application, controller, function,
def try_rewrite_on_error(http_response, request, environ, ticket=None):
"""
called from main.wsgibase to rewrite the http response.
Called from main.wsgibase to rewrite the http response.
"""
status = int(str(http_response.status).split()[0])
if status >= 399 and THREAD_LOCAL.routes.routes_onerror:
@@ -255,7 +255,7 @@ def try_rewrite_on_error(http_response, request, environ, ticket=None):
def try_redirect_on_error(http_object, request, ticket=None):
"called from main.wsgibase to rewrite the http response"
"Called from main.wsgibase to rewrite the http response"
status = int(str(http_object.status).split()[0])
if status > 399 and THREAD_LOCAL.routes.routes_onerror:
keys = set(('%s/%s' % (request.application, status),
@@ -392,7 +392,7 @@ def load(routes='routes.py', app=None, data=None, rdict=None):
def compile_regex(k, v, env=None):
"""
Preprocess and compile the regular expressions in routes_app/in/out
The resulting regex will match a pattern of the form:
The resulting regex will match a pattern of the form::
[remote address]:[protocol]://[host]:[method] [path]
@@ -427,7 +427,7 @@ def compile_regex(k, v, env=None):
def load_routers(all_apps):
"load-time post-processing of routers"
"Load-time post-processing of routers"
for app in routers:
# initialize apps with routers that aren't present,
@@ -533,7 +533,7 @@ def load_routers(all_apps):
def regex_uri(e, regexes, tag, default=None):
"filter incoming URI against a list of regexes"
"Filters incoming URI against a list of regexes"
path = e['PATH_INFO']
host = e.get('HTTP_HOST', e.get('SERVER_NAME', 'localhost')).lower()
i = host.find(':')
@@ -555,7 +555,7 @@ def regex_uri(e, regexes, tag, default=None):
def regex_select(env=None, app=None, request=None):
"""
select a set of regex rewrite params for the current request
Selects a set of regex rewrite params for the current request
"""
if app:
THREAD_LOCAL.routes = params_apps.get(app, params)
@@ -572,7 +572,7 @@ def regex_select(env=None, app=None, request=None):
def regex_filter_in(e):
"regex rewrite incoming URL"
"Regex rewrite incoming URL"
routes = THREAD_LOCAL.routes
query = e.get('QUERY_STRING', None)
e['WEB2PY_ORIGINAL_URI'] = e['PATH_INFO'] + (query and ('?' + query) or '')
@@ -603,7 +603,7 @@ def invalid_url(routes):
web2py_error='invalid path')
def regex_url_in(request, environ):
"rewrite and parse incoming URL"
"Rewrites and parses incoming URL"
# ##################################################
# select application
@@ -667,7 +667,7 @@ def regex_url_in(request, environ):
def regex_filter_out(url, e=None):
"regex rewrite outgoing URL"
"Regex rewrite outgoing URL"
if not hasattr(THREAD_LOCAL, 'routes'):
regex_select() # ensure routes is set (for application threads)
routes = THREAD_LOCAL.routes
@@ -810,10 +810,10 @@ def filter_err(status, application='app', ticket='tkt'):
class MapUrlIn(object):
"logic for mapping incoming URLs"
"Logic for mapping incoming URLs"
def __init__(self, request=None, env=None):
"initialize a map-in object"
"Initializes a map-in object"
self.request = request
self.env = env
@@ -861,7 +861,7 @@ class MapUrlIn(object):
self.port = '443' if self.scheme == 'https' else '80'
def map_prefix(self):
"strip path prefix, if present in its entirety"
"Strips path prefix, if present in its entirety"
prefix = routers.BASE.path_prefix
if prefix:
prefixlen = len(prefix)
@@ -873,7 +873,7 @@ class MapUrlIn(object):
self.args = List(self.args[prefixlen:]) # strip the prefix
def map_app(self):
"determine application name"
"Determines application name"
base = routers.BASE # base router
self.domain_application = None
self.domain_controller = None
@@ -935,12 +935,12 @@ class MapUrlIn(object):
self._args_match = self.router._args_match
def map_root_static(self):
'''
handle root-static files (no hyphen mapping)
"""
Handles root-static files (no hyphen mapping)
a root-static file is one whose incoming URL expects it to be at the root,
typically robots.txt & favicon.ico
'''
"""
if len(self.args) == 1 and self.arg0 in self.router.root_static:
self.controller = self.request.controller = 'static'
@@ -952,7 +952,7 @@ class MapUrlIn(object):
return None, None
def map_language(self):
"handle language (no hyphen mapping)"
"Handles language (no hyphen mapping)"
arg0 = self.arg0 # no hyphen mapping
if arg0 and self.languages and arg0 in self.languages:
self.language = arg0
@@ -964,7 +964,7 @@ class MapUrlIn(object):
arg0 = self.arg0
def map_controller(self):
"identify controller"
"Identifies controller"
# handle controller
#
arg0 = self.harg0 # map hyphens
@@ -981,7 +981,7 @@ class MapUrlIn(object):
def map_static(self):
'''
handle static files
Handles static files
file_match but no hyphen mapping
'''
if self.controller != 'static':
@@ -1025,7 +1025,7 @@ class MapUrlIn(object):
return static_file, version
def map_function(self):
"handle function.extension"
"Handles function.extension"
arg0 = self.harg0 # map hyphens
functions = self.functions.get(self.controller, set())
if isinstance(self.router.default_function, dict):
@@ -1058,9 +1058,9 @@ class MapUrlIn(object):
web2py_error='invalid extension')
def validate_args(self):
'''
check args against validation pattern
'''
"""
Checks args against validation pattern
"""
for arg in self.args:
if not self.router._args_match.match(arg):
raise HTTP(
@@ -1068,16 +1068,15 @@ class MapUrlIn(object):
web2py_error='invalid arg <%s>' % arg)
def sluggify(self):
""
self.request.env.update(
(k.lower().replace('.', '_'), v) for k, v in self.env.iteritems())
def update_request(self):
'''
update request from self
build env.request_uri
make lower-case versions of http headers in env
'''
"""
Updates request from self
Builds env.request_uri
Makes lower-case versions of http headers in env
"""
self.request.application = self.application
self.request.controller = self.controller
self.request.function = self.function
@@ -1105,24 +1104,24 @@ class MapUrlIn(object):
@property
def arg0(self):
"return first arg"
"Returns first arg"
return self.args(0)
@property
def harg0(self):
"return first arg with optional hyphen mapping"
"Returns first arg with optional hyphen mapping"
if self.map_hyphen and self.args(0):
return self.args(0).replace('-', '_')
return self.args(0)
def pop_arg_if(self, dopop):
"conditionally remove first arg and return new first arg"
"Conditionally removes first arg and returns new first arg"
if dopop:
self.args.pop(0)
class MapUrlOut(object):
"logic for mapping outgoing URLs"
"Logic for mapping outgoing URLs"
def __init__(self, request, env, application, controller,
function, args, other, scheme, host, port, language):
@@ -1179,13 +1178,13 @@ class MapUrlOut(object):
self.omit_function = False
def omit_lang(self):
"omit language if possible"
"Omits language if possible"
if not self.language or self.language == self.default_language:
self.omit_language = True
def omit_acf(self):
"omit what we can of a/c/f"
"Omits what we can of a/c/f"
router = self.router
@@ -1254,7 +1253,7 @@ class MapUrlOut(object):
self.omit_function = False
def build_acf(self):
"build acf from components"
"Builds a/c/f from components"
acf = ''
if self.map_hyphen:
self.application = self.application.replace('_', '-')
@@ -1280,7 +1279,7 @@ class MapUrlOut(object):
return acf or '/'
def acf(self):
"convert components to /app/lang/controller/function"
"Converts components to /app/lang/controller/function"
if not routers:
return None # use regex filter
@@ -1290,7 +1289,7 @@ class MapUrlOut(object):
def map_url_in(request, env, app=False):
"route incoming URL"
"Routes incoming URL"
# initialize router-url object
#
@@ -1333,8 +1332,8 @@ def map_url_in(request, env, app=False):
def map_url_out(request, env, application, controller,
function, args, other, scheme, host, port, language=None):
'''
supply /a/c/f (or /a/lang/c/f) portion of outgoing url
"""
Supply /a/c/f (or /a/lang/c/f) portion of outgoing url
The basic rule is that we can only make transformations
that map_url_in can reverse.
@@ -1342,14 +1341,14 @@ def map_url_out(request, env, application, controller,
Suppose that the incoming arguments are a,c,f,args,lang
and that the router defaults are da, dc, df, dl.
We can perform these transformations trivially if args=[] and lang=None or dl:
We can perform these transformations trivially if args=[] and lang=None or dl::
/da/dc/df => /
/a/dc/df => /a
/a/c/df => /a/c
/da/dc/df => /
/a/dc/df => /a
/a/c/df => /a/c
We would also like to be able to strip the default application or application/controller
from URLs with function/args present, thus:
from URLs with function/args present, thus::
/da/c/f/args => /c/f/args
/da/dc/f/args => /f/args
@@ -1357,14 +1356,14 @@ def map_url_out(request, env, application, controller,
We use [applications] and [controllers] and {functions} to suppress ambiguous omissions.
We assume that language names do not collide with a/c/f names.
'''
"""
map = MapUrlOut(request, env, application, controller,
function, args, other, scheme, host, port, language)
return map.acf()
def get_effective_router(appname):
"return a private copy of the effective router for the specified application"
"Returns a private copy of the effective router for the specified application"
if not routers or appname not in routers:
return None
return Storage(routers[appname]) # return a copy