diff options
author | Nils Philippsen <nils@redhat.com> | 2015-11-12 13:26:15 +0100 |
---|---|---|
committer | Nils Philippsen <nils@redhat.com> | 2015-11-12 13:26:15 +0100 |
commit | 81ef81c6288a320f7c9f9fd93c0b3f150b5184e8 (patch) | |
tree | 62d60718e48903a839425e65821a1991247eba97 | |
parent | 2ffc9c023fe2dc8ea4f29941dd4a0d9c62aead7b (diff) | |
download | paste-git-81ef81c6288a320f7c9f9fd93c0b3f150b5184e8.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.py | 8 |
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) |