diff options
| author | Chris McDonough <chrism@plope.com> | 2012-01-04 20:01:57 -0500 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2012-01-04 20:01:57 -0500 |
| commit | 95df3ac0fc92e882997997dac97b7ba86e19e963 (patch) | |
| tree | ac5bcc0e5c2b2c251c2ee06c3b320d9b2fe79c6b | |
| parent | 6212db897aa5cb61615f9fdefc08adf4cb7f7476 (diff) | |
| download | pyramid-95df3ac0fc92e882997997dac97b7ba86e19e963.tar.gz pyramid-95df3ac0fc92e882997997dac97b7ba86e19e963.tar.bz2 pyramid-95df3ac0fc92e882997997dac97b7ba86e19e963.zip | |
more usage of traversal_path_info fixed
| -rw-r--r-- | pyramid/config/testing.py | 10 | ||||
| -rw-r--r-- | pyramid/config/util.py | 6 | ||||
| -rw-r--r-- | pyramid/traversal.py | 13 |
3 files changed, 17 insertions, 12 deletions
diff --git a/pyramid/config/testing.py b/pyramid/config/testing.py index 3cdc1aa24..f40cf25a7 100644 --- a/pyramid/config/testing.py +++ b/pyramid/config/testing.py @@ -8,7 +8,11 @@ from pyramid.interfaces import ( ) from pyramid.renderers import RendererHelper -from pyramid.traversal import traversal_path_info + +from pyramid.traversal import ( + decode_path_info, + split_path_info, + ) from pyramid.config.util import action_method @@ -66,9 +70,9 @@ class TestingConfiguratorMixin(object): self.context = context def __call__(self, request): - path = request.environ['PATH_INFO'] + path = decode_path_info(request.environ['PATH_INFO']) ob = resources[path] - traversed = traversal_path_info(path) + traversed = split_path_info(path) return {'context':ob, 'view_name':'','subpath':(), 'traversed':traversed, 'virtual_root':ob, 'virtual_root_path':(), 'root':ob} diff --git a/pyramid/config/util.py b/pyramid/config/util.py index b0e873de3..79f13e4a0 100644 --- a/pyramid/config/util.py +++ b/pyramid/config/util.py @@ -15,7 +15,7 @@ from pyramid.exceptions import ConfigurationError from pyramid.traversal import ( find_interface, - traversal_path_info, + traversal_path, ) from hashlib import md5 @@ -268,8 +268,8 @@ def make_predicates(xhr=None, request_method=None, path_info=None, if 'traverse' in context: return True m = context['match'] - tvalue = tgenerate(m) - m['traverse'] = traversal_path_info(tvalue) + tvalue = tgenerate(m) # tvalue will be urlquoted string + m['traverse'] = traversal_path(tvalue) # will be seq of unicode return True # This isn't actually a predicate, it's just a infodict # modifier that injects ``traverse`` into the matchdict. As a diff --git a/pyramid/traversal.py b/pyramid/traversal.py index 2443e2d1c..ffc40fa60 100644 --- a/pyramid/traversal.py +++ b/pyramid/traversal.py @@ -438,11 +438,12 @@ def traversal_path(path): not. A :exc:`UnicodeEncodeError` will be raised if the Unicode cannot be encoded directly to ASCII. """ - # we unquote this path exactly like a PEP 3333 server would if isinstance(path, text_type): + # must not possess characters outside ascii path = path.encode('ascii') + # we unquote this path exactly like a PEP 3333 server would path = unquote_bytes_to_wsgi(path) # result will be a native string - return traversal_path_info(path) + return traversal_path_info(path) # result will be a tuple of unicode @lru_cache(1000) def traversal_path_info(path): @@ -516,15 +517,15 @@ def traversal_path_info(path): applications in :app:`Pyramid`. """ try: - path = decode_path_info(path) + path = decode_path_info(path) # result will be Unicode except UnicodeDecodeError as e: raise URLDecodeError(e.encoding, e.object, e.start, e.end, e.reason) - return split_path_info(path) + return split_path_info(path) # result will be tuple of Unicode @lru_cache(1000) def split_path_info(path): - # suitable for splitting an already-unquoted-already-decoded path_info - # string + # suitable for splitting an already-unquoted-already-decoded (unicode) + # path value path = path.strip('/') clean = [] for segment in path.split('/'): |
