summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-04-23 23:51:05 +0200
committerVictor Stinner <victor.stinner@gmail.com>2015-04-23 23:51:05 +0200
commita775eab8eb3c3f4d30783eaa112f80f3f4ac5fd5 (patch)
tree8e48f2ca42296087c5ac41a6c75f284d6db54aa1
parent5cf29d01122ae50736bb2e088e4696bf168fc77e (diff)
downloadpaste-git-a775eab8eb3c3f4d30783eaa112f80f3f4ac5fd5.tar.gz
Revert change on paste.util.quoting.html_quote()
On Python 2, html_quote(unicode) returns again bytes to restore backward compatibility.
-rw-r--r--docs/news.txt3
-rw-r--r--paste/util/quoting.py5
-rw-r--r--tests/test_util/test_quoting.py8
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!>'),
'&lt;hey!&gt;')
- self.assertEqual(quoting.html_quote(u'<\u1029>'),
- u'&lt;\u1029&gt;')
+ if six.PY3:
+ self.assertEqual(quoting.html_quote(u'<\u1029>'),
+ u'&lt;\u1029&gt;')
+ else:
+ self.assertEqual(quoting.html_quote(u'<\u1029>'),
+ '&lt;\xe1\x80\xa9&gt;')