summaryrefslogtreecommitdiff
path: root/repoze/bfg/traversal.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-06-22 04:59:31 +0000
committerChris McDonough <chrism@agendaless.com>2009-06-22 04:59:31 +0000
commit7fc6a3c63676637018c922e6f997b174639466f0 (patch)
tree9dc0fd27543e098bc27e8b47b9a176835976b27a /repoze/bfg/traversal.py
parentd70fd93e4b76369edea80ac1ded9da9ac0a93289 (diff)
downloadpyramid-7fc6a3c63676637018c922e6f997b174639466f0.tar.gz
pyramid-7fc6a3c63676637018c922e6f997b174639466f0.tar.bz2
pyramid-7fc6a3c63676637018c922e6f997b174639466f0.zip
We weren't computing the virtual root correctly in a corner case.
Diffstat (limited to 'repoze/bfg/traversal.py')
-rw-r--r--repoze/bfg/traversal.py63
1 files changed, 31 insertions, 32 deletions
diff --git a/repoze/bfg/traversal.py b/repoze/bfg/traversal.py
index 59ad9115d..2b9a0e611 100644
--- a/repoze/bfg/traversal.py
+++ b/repoze/bfg/traversal.py
@@ -502,69 +502,68 @@ class ModelGraphTraverser(object):
# this request did not match a Routes route
subpath = ()
try:
- path = environ['PATH_INFO']
+ path = environ['PATH_INFO'] or '/'
except KeyError:
path = '/'
try:
- vroot_path_string = environ[VH_ROOT_KEY]
+ vroot_path = environ[VH_ROOT_KEY]
except KeyError:
- vroot_path = ()
- vroot_idx = 0
+ vroot_tuple = ()
+ vpath = path
+ vroot_idx = -1
else:
- vroot_path = traversal_path(vroot_path_string)
- vroot_idx = len(vroot_path)
- path = vroot_path_string + path
+ vroot_tuple = traversal_path(vroot_path)
+ vpath = vroot_path + path
+ vroot_idx = len(vroot_tuple) -1
ob = vroot = self.root
- if (not path) or path == '/':
- # save a call to traversal_path if we know it's going to return
- # the empty tuple
- path = ()
+ if vpath == '/' or (not vpath):
+ # prevent a call to traversal_path if we know it's going
+ # to return the empty tuple
+ vpath_tuple = ()
else:
- path = traversal_path(path)
-
- # in case you're wondering, we do dead reckoning here instead
- # of pushing and popping temporary lists for speed purposes
-
- i = 1
- j = vroot_idx
-
- for segment in path:
+ # we do dead reckoning here via tuple slicing instead of
+ # pushing and popping temporary lists for speed purposes
+ # and this hurts readability; apologies
+ i = 0
+ vpath_tuple = traversal_path(vpath)
+ for segment in vpath_tuple:
if segment[:2] =='@@':
return dict(context=ob, view_name=segment[2:],
- subpath=path[i:], traversed=path[:j],
+ subpath=vpath_tuple[i+1:],
+ traversed=vpath_tuple[:vroot_idx+i+1],
virtual_root=vroot,
- virtual_root_path=vroot_path,
+ virtual_root_path=vroot_tuple,
root=self.root)
try:
getitem = ob.__getitem__
except AttributeError:
return dict(context=ob, view_name=segment,
- subpath=path[i:], traversed=path[:j],
+ subpath=vpath_tuple[i+1:],
+ traversed=vpath_tuple[:vroot_idx+i+1],
virtual_root=vroot,
- virtual_root_path=vroot_path,
+ virtual_root_path=vroot_tuple,
root=self.root)
try:
next = getitem(segment)
except KeyError:
return dict(context=ob, view_name=segment,
- subpath=path[i:], traversed=path[:j],
+ subpath=vpath_tuple[i+1:],
+ traversed=vpath_tuple[:vroot_idx+i+1],
virtual_root=vroot,
- virtual_root_path=vroot_path,
+ virtual_root_path=vroot_tuple,
root=self.root)
-
- if vroot_idx == i-1:
- vroot = ob
+ if i == vroot_idx:
+ vroot = next
ob = next
i += 1
- j += 1
return dict(context=ob, view_name=u'', subpath=subpath,
- traversed=path, virtual_root=vroot,
- virtual_root_path=vroot_path, root=self.root)
+ traversed=vpath_tuple, virtual_root=vroot,
+ virtual_root_path=vroot_tuple, root=self.root)
class TraversalContextURL(object):
""" The IContextURL adapter used to generate URLs for a context