summaryrefslogtreecommitdiff
path: root/paste/util
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-04-21 23:54:40 +0200
committerVictor Stinner <victor.stinner@gmail.com>2015-04-21 23:54:40 +0200
commit8e1d95b7b37fe5047d3a5e0389c2b8ab3238f9eb (patch)
tree8c696b1acbb1007f475ca2773c5300125f2575f3 /paste/util
parent75a2eb7ded57746641f10174ac79f0f6be2a34db (diff)
downloadpaste-8e1d95b7b37fe5047d3a5e0389c2b8ab3238f9eb.tar.gz
Fix html_unquote() on Python 3
* String must be a bytes string: replace str with six.binary_type * Port util.quoting to Python 3
Diffstat (limited to 'paste/util')
-rw-r--r--paste/util/quoting.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/paste/util/quoting.py b/paste/util/quoting.py
index 8c4c749..2e26434 100644
--- a/paste/util/quoting.py
+++ b/paste/util/quoting.py
@@ -30,18 +30,24 @@ def html_quote(v, encoding=None):
encoding = encoding or default_encoding
if v is None:
return ''
- elif isinstance(v, str):
+ elif isinstance(v, six.binary_type):
return cgi.escape(v, 1)
elif isinstance(v, six.text_type):
- return cgi.escape(v.encode(encoding), 1)
+ if six.PY3:
+ return cgi.escape(v, 1)
+ else:
+ return cgi.escape(v.encode(encoding), 1)
else:
- return cgi.escape(six.text_type(v).encode(encoding), 1)
+ if six.PY3:
+ return cgi.escape(six.text_type(v), 1)
+ else:
+ return cgi.escape(six.text_type(v).encode(encoding), 1)
_unquote_re = re.compile(r'&([a-zA-Z]+);')
def _entity_subber(match, name2c=html_entities.name2codepoint):
code = name2c.get(match.group(1))
if code:
- return unichr(code)
+ return six.unichr(code)
else:
return match.group(0)
@@ -58,7 +64,7 @@ def html_unquote(s, encoding=None):
>>> html_unquote('\xe1\x80\xa9')
u'\u1029'
"""
- if isinstance(s, str):
+ if isinstance(s, six.binary_type):
if s == '':
# workaround re.sub('', '', u'') returning '' < 2.5.2
# instead of u'' >= 2.5.2