Split PATH_SAFE into PATH_SEGMENT_SAFE in addition to moving it to pyramid.traversal and apply each to the applicable.
| | |
| | | # -*- coding: utf-8 -*- |
| | | import unittest |
| | | import warnings |
| | | |
| | |
| | | def test_string(self): |
| | | s = '/ hello!' |
| | | result = self._callFUT(s) |
| | | self.assertEqual(result, '%2F%20hello%21') |
| | | self.assertEqual(result, '%2F%20hello!') |
| | | |
| | | def test_int(self): |
| | | s = 12345 |
| | |
| | | result = self._callFUT(('x',)) |
| | | self.assertEqual(result, 'x') |
| | | |
| | | def test_segments_with_unsafes(self): |
| | | safe_segments = tuple(u"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-._~!$&'()*+,;=:@") |
| | | result = self._callFUT(safe_segments) |
| | | self.assertEqual(result, u'/'.join(safe_segments)) |
| | | unsafe_segments = tuple(chr(i) for i in range(0x20, 0x80) if not chr(i) in safe_segments) + (u'あ',) |
| | | result = self._callFUT(unsafe_segments) |
| | | self.assertEqual(result, u'/'.join(''.join('%%%02X' % (ord(c) if isinstance(c, str) else c) for c in unsafe_segment.encode('utf-8')) for unsafe_segment in unsafe_segments)) |
| | | |
| | | |
| | | def make_traverser(result): |
| | | class DummyTraverser(object): |
| | | def __init__(self, context): |
| | |
| | | warnings.filterwarnings('ignore') |
| | | from pyramid.interfaces import IContextURL |
| | | |
| | | PATH_SEGMENT_SAFE = "~!$&'()*+,;=:@" # from webob |
| | | PATH_SAFE = PATH_SEGMENT_SAFE + "/" |
| | | |
| | | empty = text_('') |
| | | |
| | | def find_root(resource): |
| | |
| | | |
| | | if PY2: |
| | | # special-case on Python 2 for speed? unchecked |
| | | def quote_path_segment(segment, safe=''): |
| | | def quote_path_segment(segment, safe=PATH_SEGMENT_SAFE): |
| | | """ %s """ % quote_path_segment_doc |
| | | # The bit of this code that deals with ``_segment_cache`` is an |
| | | # optimization: we cache all the computation of URL path segments |
| | |
| | | _segment_cache[(segment, safe)] = result |
| | | return result |
| | | else: |
| | | def quote_path_segment(segment, safe=''): |
| | | def quote_path_segment(segment, safe=PATH_SEGMENT_SAFE): |
| | | """ %s """ % quote_path_segment_doc |
| | | # The bit of this code that deals with ``_segment_cache`` is an |
| | | # optimization: we cache all the computation of URL path segments |
| | |
| | | from pyramid.traversal import ( |
| | | ResourceURL, |
| | | quote_path_segment, |
| | | PATH_SAFE, |
| | | PATH_SEGMENT_SAFE, |
| | | ) |
| | | |
| | | PATH_SAFE = '/:@&+$,' # from webob |
| | | QUERY_SAFE = '/?:@!$&\'()*+,;=' # RFC 3986 |
| | | QUERY_SAFE = "/?:@!$&'()*+,;=" # RFC 3986 |
| | | ANCHOR_SAFE = QUERY_SAFE |
| | | |
| | | def parse_url_overrides(kw): |
| | |
| | | |
| | | @lru_cache(1000) |
| | | def _join_elements(elements): |
| | | return '/'.join([quote_path_segment(s, safe=':@&+$,') for s in elements]) |
| | | return '/'.join([quote_path_segment(s, safe=PATH_SEGMENT_SAFE) for s in elements]) |
| | |
| | | from pyramid.traversal import ( |
| | | quote_path_segment, |
| | | split_path_info, |
| | | PATH_SAFE, |
| | | ) |
| | | |
| | | _marker = object() |
| | |
| | | gen = ''.join(gen) |
| | | |
| | | def q(v): |
| | | return quote_path_segment(v, safe='/:@&+$,') |
| | | return quote_path_segment(v, safe=PATH_SAFE) |
| | | |
| | | def generator(dict): |
| | | newdict = {} |