drnextgis
2017-06-15 804232f6ea90a5e537ccd46d87b66a976f736c0c
quote_via urlencode argument
2 files modified
28 ■■■■ changed files
CONTRIBUTORS.txt 2 ●●●●● patch | view | raw | blame | history
pyramid/encode.py 26 ●●●● patch | view | raw | blame | history
CONTRIBUTORS.txt
@@ -304,3 +304,5 @@
- Fang-Pen Lin, 2017/05/22
- Volker Diels-Grabsch, 2017/06/09
- Denis Rykov, 2017/06/15
pyramid/encode.py
@@ -14,7 +14,16 @@
        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 @@
    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)