diff options
| author | Chris McDonough <chrism@plope.com> | 2011-03-01 23:20:28 -0500 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2011-03-01 23:20:28 -0500 |
| commit | a7405ee4dd15337ccbc502b13a8743b37c0dd32a (patch) | |
| tree | 44e776accb7d8c921d7aec73ec6086a157d976ef | |
| parent | 773dea01777d3f15160c3ea19db7d064687d11b2 (diff) | |
| parent | 8cf91a73beb31df98617fbe5ce98bdd0c0180ab7 (diff) | |
| download | pyramid-a7405ee4dd15337ccbc502b13a8743b37c0dd32a.tar.gz pyramid-a7405ee4dd15337ccbc502b13a8743b37c0dd32a.tar.bz2 pyramid-a7405ee4dd15337ccbc502b13a8743b37c0dd32a.zip | |
Merge branch 'master' of https://github.com/dnouri/pyramid into dnouri-master
| -rw-r--r-- | pyramid/tests/test_url.py | 8 | ||||
| -rw-r--r-- | pyramid/traversal.py | 14 | ||||
| -rw-r--r-- | pyramid/url.py | 2 |
3 files changed, 18 insertions, 6 deletions
diff --git a/pyramid/tests/test_url.py b/pyramid/tests/test_url.py index 3c70e9028..e13fbbb91 100644 --- a/pyramid/tests/test_url.py +++ b/pyramid/tests/test_url.py @@ -49,6 +49,14 @@ class ResourceURLTests(unittest.TestCase): self.assertEqual(result, 'http://example.com/context/La%20Pe%C3%B1a') + def test_at_sign_in_element_names(self): + request = _makeRequest() + self._registerContextURL(request.registry) + context = DummyContext() + result = self._callFUT(context, request, '@@myview') + self.assertEqual(result, + 'http://example.com/context/@@myview') + def test_element_names_url_quoted(self): request = _makeRequest() self._registerContextURL(request.registry) diff --git a/pyramid/traversal.py b/pyramid/traversal.py index 0953ef313..c69892854 100644 --- a/pyramid/traversal.py +++ b/pyramid/traversal.py @@ -510,7 +510,7 @@ def traversal_path(path): _segment_cache = {} -def quote_path_segment(segment): +def quote_path_segment(segment, safe=''): """ Return a quoted representation of a 'path segment' (such as the string ``__name__`` attribute of a resource) as a string. If the ``segment`` passed in is a unicode object, it is converted to a @@ -521,6 +521,10 @@ def quote_path_segment(segment): raised. The return value of ``quote_path_segment`` is always a string, never Unicode. + You may pass a string of characters that need not be encoded as + the ``safe`` argument to this function. This corresponds to the + ``safe`` argument to :mod:`urllib.quote`. + .. note:: The return value for each segment passed to this function is cached in a module-scope dictionary for speed: the cached version is returned when possible @@ -537,15 +541,15 @@ def quote_path_segment(segment): # unicode value) as the key, so we can look it up later without # needing to reencode or re-url-quote it try: - return _segment_cache[segment] + return _segment_cache[(segment, safe)] except KeyError: if segment.__class__ is unicode: # isinstance slighly slower (~15%) - result = url_quote(segment.encode('utf-8')) + result = url_quote(segment.encode('utf-8'), safe) else: - result = url_quote(str(segment)) + result = url_quote(str(segment), safe) # we don't need a lock to mutate _segment_cache, as the below # will generate exactly one Python bytecode (STORE_SUBSCR) - _segment_cache[segment] = result + _segment_cache[(segment, safe)] = result return result class ResourceTreeTraverser(object): diff --git a/pyramid/url.py b/pyramid/url.py index cb60684e2..ebf0402d8 100644 --- a/pyramid/url.py +++ b/pyramid/url.py @@ -432,4 +432,4 @@ def current_route_url(request, *elements, **kw): @lru_cache(1000) def _join_elements(elements): - return '/'.join([quote_path_segment(s) for s in elements]) + return '/'.join([quote_path_segment(s, safe=':@&+$,') for s in elements]) |
