| | |
| | | def bytes_(s, encoding='latin-1', errors='strict'): |
| | | """ If ``s`` is an instance of ``text_type``, return |
| | | ``s.encode(encoding, errors)``, otherwise return ``s``""" |
| | | if isinstance(s, text_type): |
| | | if isinstance(s, text_type): # pragma: no cover |
| | | return s.encode(encoding, errors) |
| | | return s |
| | | |
| | |
| | | from urllib import unquote as url_unquote |
| | | from urllib import urlencode as url_encode |
| | | from urllib2 import urlopen as url_open |
| | | def url_unquote_text(v, encoding='utf-8', errors='replace'): |
| | | def url_unquote_text(v, encoding='utf-8', errors='replace'): # pragma: no cover |
| | | v = url_unquote(v) |
| | | return v.decode(encoding, errors) |
| | | def url_unquote_native(v, encoding='utf-8', errors='replace'): |
| | | def url_unquote_native(v, encoding='utf-8', errors='replace'): # pragma: no cover |
| | | return native_(url_unquote_text(v, encoding, errors)) |
| | | |
| | | |
| | |
| | | foo = DummyContext(None, text_(b'Qu\xc3\xa9bec', 'utf-8')) |
| | | root = DummyContext(foo, 'root') |
| | | policy = self._makeOne(root) |
| | | if PY3: |
| | | if PY3: # pragma: no cover |
| | | path_info = b'/Qu\xc3\xa9bec'.decode('latin-1') |
| | | else: |
| | | path_info = b'/Qu\xc3\xa9bec' |
| | |
| | | foo = DummyContext(bar, text_(b'Qu\xc3\xa9bec', 'utf-8')) |
| | | root = DummyContext(foo, 'root') |
| | | policy = self._makeOne(root) |
| | | if PY3: |
| | | if PY3: # pragma: no cover |
| | | vhm_root = b'/Qu\xc3\xa9bec'.decode('latin-1') |
| | | else: |
| | | vhm_root = b'/Qu\xc3\xa9bec' |
| | |
| | | self.assertEqual(mapper.routelist[0].pattern, |
| | | 'archives/:action/:article2') |
| | | |
| | | def test___call__pathinfo_cant_be_decoded(self): |
| | | from pyramid.exceptions import URLDecodeError |
| | | mapper = self._makeOne() |
| | | request = self._getRequest(PATH_INFO=b'\xff\xfe\xe6\x00') |
| | | self.assertRaises(URLDecodeError, mapper, request) |
| | | |
| | | def test___call__route_matches(self): |
| | | mapper = self._makeOne() |
| | | mapper.connect('foo', 'archives/:action/:article') |
| | |
| | | string_types, |
| | | binary_type, |
| | | is_nonstr_iter, |
| | | url_quote, |
| | | ) |
| | | |
| | | from pyramid.exceptions import URLDecodeError |
| | |
| | | def generator(dict): |
| | | newdict = {} |
| | | for k, v in dict.items(): |
| | | if PY3: |
| | | if PY3: # pragma: no cover |
| | | if v.__class__ is binary_type: |
| | | # url_quote below needs a native string, not bytes on Py3 |
| | | v = v.decode('utf-8') |