From 64f24fe3e7ac7a1beb1f0fbb80c355e39127182c Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Thu, 12 Nov 2015 13:26:15 +0100 Subject: Python 3: let html_quote() and url() always return the same type Mixing binary and text types causes errors later on. --- paste/util/template.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'paste') 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) -- cgit v1.2.1