summaryrefslogtreecommitdiff
path: root/pecan/routing.py
diff options
context:
space:
mode:
authorJonathan LaCour <jonathan@dreamhost.com>2012-03-11 09:52:25 -0700
committerJonathan LaCour <jonathan@dreamhost.com>2012-03-11 09:52:25 -0700
commitbed5cbfa147a202b2736295c286f567604efcd3e (patch)
treef6dd1d18d72a4acd3b5239a30d424e5513bbc099 /pecan/routing.py
parent20a996b58d741c83e274352a6ad335b5da227efe (diff)
downloadpecan-bed5cbfa147a202b2736295c286f567604efcd3e.tar.gz
After a full-scale scan with pep8.py and pyflakes, identified and
resolved most of our PEP8 compliance issues.
Diffstat (limited to 'pecan/routing.py')
-rw-r--r--pecan/routing.py26
1 files changed, 16 insertions, 10 deletions
diff --git a/pecan/routing.py b/pecan/routing.py
index 9739520..246352f 100644
--- a/pecan/routing.py
+++ b/pecan/routing.py
@@ -1,16 +1,17 @@
from webob import exc
-from inspect import ismethod
from secure import handle_security, cross_boundary
from util import iscontroller
__all__ = ['lookup_controller', 'find_object']
+
class NonCanonicalPath(Exception):
def __init__(self, controller, remainder):
self.controller = controller
self.remainder = remainder
+
def lookup_controller(obj, url_path):
remainder = url_path
notfound_handlers = []
@@ -40,8 +41,9 @@ def lookup_controller(obj, url_path):
break
except TypeError, te:
import warnings
+ msg = 'Got exception calling lookup(): %s (%s)'
warnings.warn(
- 'Got exception calling lookup(): %s (%s)' % (te, te.args),
+ msg % (te, te.args),
RuntimeWarning
)
else:
@@ -51,19 +53,22 @@ def lookup_controller(obj, url_path):
def find_object(obj, remainder, notfound_handlers):
prev_obj = None
while True:
- if obj is None: raise exc.HTTPNotFound
- if iscontroller(obj): return obj, remainder
+ if obj is None:
+ raise exc.HTTPNotFound
+ if iscontroller(obj):
+ return obj, remainder
# are we traversing to another controller
cross_boundary(prev_obj, obj)
-
+
if remainder and remainder[0] == '':
index = getattr(obj, 'index', None)
- if iscontroller(index): return index, remainder[1:]
+ if iscontroller(index):
+ return index, remainder[1:]
elif not remainder:
# the URL has hit an index method without a trailing slash
index = getattr(obj, 'index', None)
- if iscontroller(index):
+ if iscontroller(index):
raise NonCanonicalPath(index, remainder[1:])
default = getattr(obj, '_default', None)
if iscontroller(default):
@@ -72,14 +77,15 @@ def find_object(obj, remainder, notfound_handlers):
lookup = getattr(obj, '_lookup', None)
if iscontroller(lookup):
notfound_handlers.append(('_lookup', lookup, remainder))
-
+
route = getattr(obj, '_route', None)
if iscontroller(route):
next, next_remainder = route(remainder)
cross_boundary(route, next)
return next, next_remainder
-
- if not remainder: raise exc.HTTPNotFound
+
+ if not remainder:
+ raise exc.HTTPNotFound
next, remainder = remainder[0], remainder[1:]
prev_obj = obj
obj = getattr(obj, next, None)