- Backport fix from master: ``request.static_url`` now generates URL-quoted
URLs when fed a ``path`` argument which contains characters that are
unsuitable for URLs. See https://github.com/Pylons/pyramid/issues/349 for
more information.
- Backport from master: fix ``request.json_body`` to deal with alternate
request charsets.
Ref: issue #349.
| | |
| | | and can still be used when a path is encoded. See |
| | | https://github.com/Pylons/pyramid/issues/349 for more information. |
| | | |
| | | - Backport fix from master: ``request.static_url`` now generates URL-quoted |
| | | URLs when fed a ``path`` argument which contains characters that are |
| | | unsuitable for URLs. See https://github.com/Pylons/pyramid/issues/349 for |
| | | more information. |
| | | |
| | | - Backport from master: fix ``request.json_body`` to deal with alternate |
| | | request charsets. |
| | | |
| | | Testing |
| | | ------- |
| | | |
| | | - Make tox use WebOb 1.1 for Python 2.5-based systems (WebOb 1.2 is 2.6+). |
| | | |
| | | 1.2.1 (2011-09-28) |
| | | ================== |
| | | |
| | |
| | | import inspect |
| | | from urlparse import urljoin |
| | | from urlparse import urlparse |
| | | import urllib |
| | | |
| | | from zope.interface import Interface |
| | | from zope.interface import classProvides |
| | |
| | | registry = get_current_registry() |
| | | for (url, spec, route_name) in self._get_registrations(registry): |
| | | if path.startswith(spec): |
| | | subpath = path[len(spec):] |
| | | subpath = urllib.quote(path[len(spec):]) |
| | | if url is None: |
| | | kw['subpath'] = subpath |
| | | return request.route_url(route_name, **kw) |
| | |
| | | |
| | | @property |
| | | def json_body(self): |
| | | return json.loads(self.body, encoding=self.charset) |
| | | return json.loads(self.body.decode(self.charset)) |
| | | |
| | | def route_request_iface(name, bases=()): |
| | | # zope.interface treats the __name__ as the __doc__ and changes __name__ |
| | |
| | | result = inst.generate('package:path/abc', request, a=1) |
| | | self.assertEqual(result, 'url') |
| | | |
| | | def test_generate_url_quoted_local(self): |
| | | inst = self._makeOne() |
| | | registrations = [(None, 'package:path/', '__viewname/')] |
| | | inst._get_registrations = lambda *x: registrations |
| | | def route_url(n, **kw): |
| | | self.assertEqual(n, '__viewname/') |
| | | self.assertEqual(kw, {'subpath':'abc%20def', 'a':1}) |
| | | return 'url' |
| | | request = self._makeRequest() |
| | | request.route_url = route_url |
| | | result = inst.generate('package:path/abc def', request, a=1) |
| | | self.assertEqual(result, 'url') |
| | | |
| | | def test_generate_url_quoted_remote(self): |
| | | inst = self._makeOne() |
| | | registrations = [('http://example.com/', 'package:path/', None)] |
| | | inst._get_registrations = lambda *x: registrations |
| | | request = self._makeRequest() |
| | | result = inst.generate('package:path/abc def', request, a=1) |
| | | self.assertEqual(result, 'http://example.com/abc%20def') |
| | | |
| | | def test_add_already_exists(self): |
| | | inst = self._makeOne() |
| | | config = self._makeConfig( |
| | |
| | | def test_json_body_alternate_charset(self): |
| | | from pyramid.compat import json |
| | | request = self._makeOne({'REQUEST_METHOD':'POST'}) |
| | | request.charset = 'latin-1' |
| | | la = unicode('La Pe\xc3\xb1a', 'utf-8') |
| | | body = json.dumps({'a':la}, encoding='latin-1') |
| | | inp ='/\xe6\xb5\x81\xe8\xa1\x8c\xe8\xb6\x8b\xe5\x8a\xbf'.decode('utf-8') |
| | | body = json.dumps({'a':inp}).decode('utf-8').encode('utf-16') |
| | | request.body = body |
| | | self.assertEqual(request.json_body, {'a':la}) |
| | | request.content_type = 'application/json; charset=utf-16' |
| | | self.assertEqual(request.json_body, {'a':inp}) |
| | | |
| | | def test_json_body_GET_request(self): |
| | | request = self._makeOne({'REQUEST_METHOD':'GET'}) |
| | |
| | | """ |
| | | try: |
| | | path = path.decode('utf-8') |
| | | except UnicodeDecodeError as e: |
| | | except UnicodeDecodeError, e: |
| | | raise URLDecodeError(e.encoding, e.object, e.start, e.end, e.reason) |
| | | path = path.strip('/') |
| | | clean = [] |
| | |
| | | repoze.sphinx.autointerface |
| | | virtualenv |
| | | |
| | | [testenv:py25] |
| | | commands = |
| | | python setup.py test -q |
| | | deps = |
| | | https://github.com/Pylons/webob/zipball/1.1-branch |
| | | Sphinx |
| | | WebTest |
| | | repoze.sphinx.autointerface |
| | | virtualenv |
| | | |
| | | [testenv:jython] |
| | | commands = |
| | | jython setup.py test -q |
| | | jython setup.py test -q |
| | | deps = |
| | | https://github.com/Pylons/webob/zipball/1.1-branch |
| | | Sphinx |
| | | WebTest |
| | | repoze.sphinx.autointerface |
| | | virtualenv |
| | | |
| | | [testenv:cover] |
| | | basepython = |