From a775eab8eb3c3f4d30783eaa112f80f3f4ac5fd5 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 23 Apr 2015 23:51:05 +0200 Subject: Revert change on paste.util.quoting.html_quote() On Python 2, html_quote(unicode) returns again bytes to restore backward compatibility. --- docs/news.txt | 3 --- paste/util/quoting.py | 5 ++++- tests/test_util/test_quoting.py | 8 ++++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/news.txt b/docs/news.txt index 4bc23a3..80d9287 100644 --- a/docs/news.txt +++ b/docs/news.txt @@ -9,9 +9,6 @@ development version * Fix setup.py for six dependency: move the six dependency from extras_require to install_requires. -* On Python 2, paste.util.quoting.html_quote(unicode) now returns unicode, - instead of bytes. - * Port paste.proxy to Python 3. * Fix paste.exceptions.serial_number_generator.hash_identifier() on Python 3. diff --git a/paste/util/quoting.py b/paste/util/quoting.py index 9bd50c8..df0d9da 100644 --- a/paste/util/quoting.py +++ b/paste/util/quoting.py @@ -24,7 +24,10 @@ def html_quote(v, encoding=None): elif isinstance(v, six.binary_type): return cgi.escape(v, 1) elif isinstance(v, six.text_type): - return cgi.escape(v, 1) + if six.PY3: + return cgi.escape(v, 1) + else: + return cgi.escape(v.encode(encoding), 1) else: if six.PY3: return cgi.escape(six.text_type(v), 1) diff --git a/tests/test_util/test_quoting.py b/tests/test_util/test_quoting.py index 28790a4..5f5e0a8 100644 --- a/tests/test_util/test_quoting.py +++ b/tests/test_util/test_quoting.py @@ -20,5 +20,9 @@ class TestQuoting(unittest.TestCase): '') self.assertEqual(quoting.html_quote(''), '<hey!>') - self.assertEqual(quoting.html_quote(u'<\u1029>'), - u'<\u1029>') + if six.PY3: + self.assertEqual(quoting.html_quote(u'<\u1029>'), + u'<\u1029>') + else: + self.assertEqual(quoting.html_quote(u'<\u1029>'), + '<\xe1\x80\xa9>') -- cgit v1.2.1