summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CONTRIBUTORS.txt2
-rw-r--r--pyramid/encode.py26
2 files changed, 15 insertions, 13 deletions
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
index 445536e9e..32c0833b4 100644
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -304,3 +304,5 @@ Contributors
- Fang-Pen Lin, 2017/05/22
- Volker Diels-Grabsch, 2017/06/09
+
+- Denis Rykov, 2017/06/15
diff --git a/pyramid/encode.py b/pyramid/encode.py
index 0be0107b3..62f96938b 100644
--- a/pyramid/encode.py
+++ b/pyramid/encode.py
@@ -14,7 +14,16 @@ def url_quote(val, safe=''): # bw compat api
val = str(val).encode('utf-8')
return _url_quote(val, safe=safe)
-def urlencode(query, doseq=True):
+# bw compat api (dnr)
+def quote_plus(val, safe=''):
+ 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 _quote_plus(val, safe=safe)
+
+def urlencode(query, doseq=True, quote_via=quote_plus):
"""
An alternate implementation of Python's stdlib `urllib.urlencode
function <http://docs.python.org/library/urllib.html>`_ which
@@ -52,28 +61,19 @@ def urlencode(query, doseq=True):
prefix = ''
for (k, v) in query:
- k = quote_plus(k)
+ k = quote_via(k)
if is_nonstr_iter(v):
for x in v:
- x = quote_plus(x)
+ x = quote_via(x)
result += '%s%s=%s' % (prefix, k, x)
prefix = '&'
elif v is None:
result += '%s%s=' % (prefix, k)
else:
- v = quote_plus(v)
+ v = quote_via(v)
result += '%s%s=%s' % (prefix, k, v)
prefix = '&'
return result
-
-# bw compat api (dnr)
-def quote_plus(val, safe=''):
- 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 _quote_plus(val, safe=safe)