Michael Merickel
2013-11-12 22f0ebbc04f1fa03139ca7c99e02e39a2635590f
modify quoting to be bare-bones
4 files modified
31 ■■■■ changed files
pyramid/encode.py 10 ●●●● patch | view | raw | blame | history
pyramid/tests/test_config/test_views.py 2 ●●● patch | view | raw | blame | history
pyramid/tests/test_url.py 8 ●●●● patch | view | raw | blame | history
pyramid/url.py 11 ●●●● patch | view | raw | blame | history
pyramid/encode.py
@@ -6,8 +6,13 @@
    url_quote_plus as _quote_plus,
    )
def url_quote(s, safe=''): # bw compat api
    return _url_quote(s, safe=safe)
def url_quote(val, safe=''): # bw compat api
    cls = val.__class__
    if cls is text_type:
        val = val.encode('utf-8')
    elif cls is not binary_type:
        val = str(val).encode('utf-8')
    return _url_quote(val, safe=safe)
def urlencode(query, doseq=True):
    """
@@ -72,4 +77,3 @@
    elif cls is not binary_type:
        val = str(val).encode('utf-8')
    return _quote_plus(val, safe=safe)
pyramid/tests/test_config/test_views.py
@@ -3839,7 +3839,7 @@
        result = inst.generate('package:path/abc def', request, a=1,
                               _anchor=uc)
        self.assertEqual(result,
                         'http://example.com/abc%20def#La+Pe%C3%B1a')
                         'http://example.com/abc%20def#La%20Pe%C3%B1a')
    def test_add_already_exists(self):
        inst = self._makeOne()
pyramid/tests/test_url.py
@@ -160,7 +160,7 @@
        uc = text_(b'La Pe\xc3\xb1a', 'utf-8')
        result = request.resource_url(context, anchor=uc)
        self.assertEqual(result,
                         'http://example.com:5432/context/#La+Pe%C3%B1a')
                         'http://example.com:5432/context/#La%20Pe%C3%B1a')
    def test_resource_url_anchor_is_urlencoded_safe(self):
        request = self._makeOne()
@@ -168,7 +168,7 @@
        context = DummyContext()
        result = request.resource_url(context, anchor=' /#?&+')
        self.assertEqual(result,
                         'http://example.com:5432/context/#+/%23?&+')
                         'http://example.com:5432/context/#%20/%23?&+')
    def test_resource_url_no_IResourceURL_registered(self):
        # falls back to ResourceURL
@@ -452,7 +452,7 @@
        result = request.route_url('flub', _anchor=b"La Pe\xc3\xb1a")
        self.assertEqual(result,
                         'http://example.com:5432/1/2/3#La+Pe%C3%B1a')
                         'http://example.com:5432/1/2/3#La%20Pe%C3%B1a')
    def test_route_url_with_anchor_unicode(self):
        from pyramid.interfaces import IRoutesMapper
@@ -463,7 +463,7 @@
        result = request.route_url('flub', _anchor=anchor)
        self.assertEqual(result,
                         'http://example.com:5432/1/2/3#La+Pe%C3%B1a')
                         'http://example.com:5432/1/2/3#La%20Pe%C3%B1a')
    def test_route_url_with_query(self):
        from pyramid.interfaces import IRoutesMapper
pyramid/url.py
@@ -14,10 +14,9 @@
from pyramid.compat import (
    bytes_,
    string_types,
    url_quote,
    )
from pyramid.encode import (
    quote_plus,
    url_quote,
    urlencode,
)
from pyramid.path import caller_package
@@ -49,13 +48,13 @@
    if '_query' in kw:
        query = kw.pop('_query')
        if isinstance(query, string_types):
            qs = '?' + quote_plus(query, safe=QUERY_SAFE)
            qs = '?' + url_quote(query, QUERY_SAFE)
        elif query:
            qs = '?' + urlencode(query, doseq=True)
    if '_anchor' in kw:
        anchor = kw.pop('_anchor')
        anchor = quote_plus(anchor, safe=ANCHOR_SAFE)
        anchor = url_quote(anchor, ANCHOR_SAFE)
        anchor = '#' + anchor
    if '_app_url' in kw:
@@ -598,13 +597,13 @@
        if 'query' in kw:
            query = kw['query']
            if isinstance(query, string_types):
                qs = '?' + quote_plus(query, safe=QUERY_SAFE)
                qs = '?' + url_quote(query, QUERY_SAFE)
            elif query:
                qs = '?' + urlencode(query, doseq=True)
        if 'anchor' in kw:
            anchor = kw['anchor']
            anchor = quote_plus(anchor, safe=ANCHOR_SAFE)
            anchor = url_quote(anchor, ANCHOR_SAFE)
            anchor = '#' + anchor
        if elements: