summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2013-11-12 01:13:48 -0600
committerMichael Merickel <michael@merickel.org>2013-11-12 01:13:48 -0600
commit22f0ebbc04f1fa03139ca7c99e02e39a2635590f (patch)
tree54fd357a9e5e50196ad59f204907b27d1d27267a
parentaf3134a984a7e9c53d41607dcf4f1feb60282f85 (diff)
downloadpyramid-22f0ebbc04f1fa03139ca7c99e02e39a2635590f.tar.gz
pyramid-22f0ebbc04f1fa03139ca7c99e02e39a2635590f.tar.bz2
pyramid-22f0ebbc04f1fa03139ca7c99e02e39a2635590f.zip
modify quoting to be bare-bones
-rw-r--r--pyramid/encode.py10
-rw-r--r--pyramid/tests/test_config/test_views.py2
-rw-r--r--pyramid/tests/test_url.py8
-rw-r--r--pyramid/url.py11
4 files changed, 17 insertions, 14 deletions
diff --git a/pyramid/encode.py b/pyramid/encode.py
index 15da1c511..0be0107b3 100644
--- a/pyramid/encode.py
+++ b/pyramid/encode.py
@@ -6,8 +6,13 @@ from pyramid.compat import (
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 @@ def quote_plus(val, safe=''):
elif cls is not binary_type:
val = str(val).encode('utf-8')
return _quote_plus(val, safe=safe)
-
diff --git a/pyramid/tests/test_config/test_views.py b/pyramid/tests/test_config/test_views.py
index c722c9166..57bb5e9d0 100644
--- a/pyramid/tests/test_config/test_views.py
+++ b/pyramid/tests/test_config/test_views.py
@@ -3839,7 +3839,7 @@ class TestStaticURLInfo(unittest.TestCase):
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()
diff --git a/pyramid/tests/test_url.py b/pyramid/tests/test_url.py
index 6a8624a9f..22ccd1d0e 100644
--- a/pyramid/tests/test_url.py
+++ b/pyramid/tests/test_url.py
@@ -160,7 +160,7 @@ class TestURLMethodsMixin(unittest.TestCase):
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 @@ class TestURLMethodsMixin(unittest.TestCase):
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 @@ class TestURLMethodsMixin(unittest.TestCase):
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 @@ class TestURLMethodsMixin(unittest.TestCase):
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
diff --git a/pyramid/url.py b/pyramid/url.py
index e760bb356..629c1531a 100644
--- a/pyramid/url.py
+++ b/pyramid/url.py
@@ -14,10 +14,9 @@ from pyramid.interfaces import (
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 @@ def parse_url_overrides(kw):
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 @@ class URLMethodsMixin(object):
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: