some minor simplifications in rewrite.py
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.1.0 (2012-10-12 11:32:45) dev
|
Version 2.1.0 (2012-10-12 11:48:21) dev
|
||||||
|
|||||||
+9
-20
@@ -179,39 +179,28 @@ def url_in(request, environ):
|
|||||||
return map_url_in(request, environ)
|
return map_url_in(request, environ)
|
||||||
return regex_url_in(request, environ)
|
return regex_url_in(request, environ)
|
||||||
|
|
||||||
def url_out(request, env, application, controller, function,
|
def url_out(request, environ, application, controller, function,
|
||||||
args, other, scheme, host, port):
|
args, other, scheme, host, port):
|
||||||
"assemble and rewrite outgoing URL"
|
"assemble and rewrite outgoing URL"
|
||||||
if routers:
|
if routers:
|
||||||
acf = map_url_out(request, env, application, controller,
|
acf = map_url_out(request, environ, application, controller,
|
||||||
function, args, other, scheme, host, port)
|
function, args, other, scheme, host, port)
|
||||||
url = '%s%s' % (acf, other)
|
url = '%s%s' % (acf, other)
|
||||||
else:
|
else:
|
||||||
url = '/%s/%s/%s%s' % (application, controller, function, other)
|
url = '/%s/%s/%s%s' % (application, controller, function, other)
|
||||||
url = regex_filter_out(url, env)
|
url = regex_filter_out(url, environ)
|
||||||
#
|
#
|
||||||
# fill in scheme and host if absolute URL is requested
|
# fill in scheme and host if absolute URL is requested
|
||||||
# scheme can be a string, eg 'http', 'https', 'ws', 'wss'
|
# scheme can be a string, eg 'http', 'https', 'ws', 'wss'
|
||||||
#
|
#
|
||||||
|
if host is True or (host is None and (scheme or port!=None)):
|
||||||
if scheme or port is not None:
|
host = request.env.http_host
|
||||||
if host is None: # scheme or port implies host
|
|
||||||
host = True
|
|
||||||
if not scheme or scheme is True:
|
if not scheme or scheme is True:
|
||||||
if request and request.env:
|
scheme = request.env.get('wsgi_url_scheme', 'http').lower() \
|
||||||
scheme = request.env.get('wsgi_url_scheme', 'http').lower()
|
if request else 'http'
|
||||||
else:
|
|
||||||
scheme = 'http' # some reasonable default in case we need it
|
|
||||||
if host is not None:
|
|
||||||
if host is True:
|
|
||||||
host = request.env.http_host
|
|
||||||
if host:
|
if host:
|
||||||
if port is None:
|
host_port = host if not port else host.split(':',1)[0]+':%s'%port
|
||||||
port = ''
|
url = '%s://%s%s' % (scheme, host_port, url)
|
||||||
else:
|
|
||||||
port = ':%s' % port
|
|
||||||
host = host.split(':')[0]
|
|
||||||
url = '%s://%s%s%s' % (scheme, host, port, url)
|
|
||||||
return url
|
return url
|
||||||
|
|
||||||
def try_rewrite_on_error(http_response, request, environ, ticket=None):
|
def try_rewrite_on_error(http_response, request, environ, ticket=None):
|
||||||
|
|||||||
Reference in New Issue
Block a user