application: Rewrite URL-processing for readability.

This commit is contained in:
Fredrik Thulin
2013-05-17 15:22:50 +02:00
parent 1458048b81
commit 389986d125

View File

@@ -832,40 +832,27 @@ def application(environ, start_response):
except KeyError:
user = None
url_patterns = AUTHN_URLS
if not user:
logger.info("-- No USER --")
for regex, callback in NON_AUTHN_URLS:
match = re.search(regex, path)
if match is not None:
try:
environ['myapp.url_args'] = match.groups()[0]
except IndexError:
environ['myapp.url_args'] = path
# insert NON_AUTHN_URLS first in case there is no user
url_patterns = NON_AUTHN_URLS + url_patterns
logger.debug("Callback: %s" % (callback,))
if isinstance(callback, tuple):
cls = callback[0](environ, start_response, user)
func = getattr(cls, callback[1])
return func()
else:
return callback(environ, start_response, user)
for regex, callback in AUTHN_URLS:
match = re.search(regex, path)
if match is not None:
cls = callback[0](environ, start_response, user)
func = getattr(cls, callback[1])
return func()
else:
for regex, callback in AUTHN_URLS:
match = re.search(regex, path)
if match is not None:
try:
environ['myapp.url_args'] = match.groups()[0]
except IndexError:
environ['myapp.url_args'] = path
for regex, callback in url_patterns:
match = re.search(regex, path)
if match is not None:
try:
environ['myapp.url_args'] = match.groups()[0]
except IndexError:
environ['myapp.url_args'] = path
logger.debug("Callback: %s" % (callback,))
if isinstance(callback, tuple):
cls = callback[0](environ, start_response, user)
func = getattr(cls, callback[1])
return func()
return callback(environ, start_response, user)
return not_found(environ, start_response)
# ----------------------------------------------------------------------------
@@ -900,4 +887,4 @@ if __name__ == '__main__':
SRV = make_server('', PORT, application)
print "IdP listening on port: %s" % PORT
SRV.serve_forever()
SRV.serve_forever()