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.
In addition, it rewrites both incoming and outgoing URLs based on the
(optional) user-supplied routes.py, which also allows for rewriting of
certain error messages.
routes.py supports two styles of URL rewriting, depending on whether
'routers' is defined. Refer to router.example.py and routes.example.py
for additional documentation.
|
_router_default()
return new copy of default base router |
source code
|
|
|
_params_default(app=1)
return new copy of default parameters |
source code
|
|
|
url_in(request,
environ)
parse and rewrite incoming URL |
source code
|
|
|
url_out(request,
env,
application,
controller,
function,
args,
other,
scheme,
host,
port)
assemble and rewrite outgoing URL |
source code
|
|
|
try_rewrite_on_error(http_response,
request,
environ,
ticket=1)
called from main.wsgibase to rewrite the http response. |
source code
|
|
|
try_redirect_on_error(http_object,
request,
ticket=1)
called from main.wsgibase to rewrite the http response |
source code
|
|
|
load(routes=' routes.py ' ,
app=1,
data=1,
rdict=1)
load: read (if file) and parse routes store results in params
(called from main.py at web2py initialization time) If data is
present, it's used instead of the routes.py contents. |
source code
|
|
|
compile_regex(k,
v)
Preprocess and compile the regular expressions in routes_app/in/out
The resulting regex will match a pattern of the form:
[remote address]:[protocol]://[host]:[method] [path]
We allow abbreviated regexes on input; here we try to complete them. |
source code
|
|
|
load_routers(all_apps)
load-time post-processing of routers |
source code
|
|
|
regex_uri(e,
regexes,
tag,
default=1)
filter incoming URI against a list of regexes |
source code
|
|
|
regex_select(env=1,
app=1,
request=1)
select a set of regex rewrite params for the current request |
source code
|
|
|
regex_filter_in(e)
regex rewrite incoming URL |
source code
|
|
|
regex_url_in(request,
environ)
rewrite and parse incoming URL |
source code
|
|
|
regex_filter_out(url,
e=1)
regex rewrite outgoing URL |
source code
|
|
|
filter_url(url,
method=' get ' ,
remote=' 0.0.0.0 ' ,
out=True,
app=True,
lang=1,
domain=( None, None) ,
env=True,
scheme=1,
host=1,
port=1)
doctest/unittest interface to regex_filter_in() and
regex_filter_out() |
source code
|
|
|
filter_err(status,
application=' app ' ,
ticket=' tkt ' )
doctest/unittest interface to routes_onerror |
source code
|
|
|
map_url_in(request,
env,
app=True)
route incoming URL |
source code
|
|
|
map_url_out(request,
env,
application,
controller,
function,
args,
other,
scheme,
host,
port)
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. |
source code
|
|
|
get_effective_router(appname)
return a private copy of the effective router for the specified
application |
source code
|
|
|
logger = logging.getLogger('web2py.rewrite')
|
|
thread = threading.local()
|
|
params_apps = { }
|
|
params = <Storage {'routes_out': [], 'name': 'BASE', 'routes_a...
|
|
routers = 1
PyMySQL: A pure-Python drop-in replacement for MySQLdb.
|
|
ROUTER_KEYS = set([ ' acfe_match ' , ' applications ' , ' args_match ' , ...
|
|
ROUTER_BASE_KEYS = set([ ' applications ' , ' default_application ' , ...
|
|
regex_at = re.compile(r'(?<! \\) \$[ a- zA- Z] \w* ')
|
|
regex_anything = re.compile(r'(?<! \\) \$anything')
|
|
regex_space = re.compile(r'( \+| \s| %20) + ')
|
|
regex_static = re.compile(r'(?x) ( ^/(?P< b > \w+ ) /static/(?P< x > ( \w...
|
|
regex_url = re.compile(r'(?x) ( ^( /(?P< a > [ \w\s\+] + ) ( /(?P< c > [ \w\s...
|
|
regex_args = re.compile(r'(?x) ( ^(?P< s > ( [ \w@/-] [ =\.] ? ) * ) ? /? $) ')
|