summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNils Philippsen <nils@redhat.com>2015-11-12 13:26:15 +0100
committerNils Philippsen <nils@redhat.com>2015-11-12 13:26:15 +0100
commit64f24fe3e7ac7a1beb1f0fbb80c355e39127182c (patch)
tree62d60718e48903a839425e65821a1991247eba97
parent85945f7b5c901e3e6b2a43683abec3003e658c51 (diff)
downloadpaste-64f24fe3e7ac7a1beb1f0fbb80c355e39127182c.tar.gz
Python 3: let html_quote() and url() always return the same type
Mixing binary and text types causes errors later on.
-rw-r--r--paste/util/template.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/paste/util/template.py b/paste/util/template.py
index c0c5ed0..5a63664 100644
--- a/paste/util/template.py
+++ b/paste/util/template.py
@@ -318,22 +318,22 @@ def html_quote(value):
if value is None:
return ''
if not isinstance(value, six.string_types):
- if hasattr(value, '__unicode__'):
+ if six.PY2 and hasattr(value, '__unicode__'):
value = unicode(value)
else:
value = str(value)
value = cgi.escape(value, 1)
- if isinstance(value, unicode):
+ if six.PY2 and isinstance(value, unicode):
value = value.encode('ascii', 'xmlcharrefreplace')
return value
def url(v):
if not isinstance(v, six.string_types):
- if hasattr(v, '__unicode__'):
+ if six.PY2 and hasattr(v, '__unicode__'):
v = unicode(v)
else:
v = str(v)
- if isinstance(v, unicode):
+ if six.PY2 and isinstance(v, unicode):
v = v.encode('utf8')
return quote(v)