summaryrefslogtreecommitdiff
path: root/paste
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-04-22 03:37:20 +0200
committerVictor Stinner <victor.stinner@gmail.com>2015-04-22 03:37:20 +0200
commitb19f4f27189a29d3a1c4cf036ae51d35db83ea5a (patch)
tree2f5cf8da68e1222998285300b1bad4d8d8027994 /paste
parentaadcd3e4f4ac5c8251db1a7899d96c8ee279e04d (diff)
downloadpaste-b19f4f27189a29d3a1c4cf036ae51d35db83ea5a.tar.gz
Fix paste.util.html_quote(unicode): don't encode the string to escape it
Diffstat (limited to 'paste')
-rw-r--r--paste/util/quoting.py26
1 files changed, 1 insertions, 25 deletions
diff --git a/paste/util/quoting.py b/paste/util/quoting.py
index 2e26434..9bd50c8 100644
--- a/paste/util/quoting.py
+++ b/paste/util/quoting.py
@@ -17,15 +17,6 @@ def html_quote(v, encoding=None):
r"""
Quote the value (turned to a string) as HTML. This quotes <, >,
and quotes:
-
- >>> html_quote(1)
- '1'
- >>> html_quote(None)
- ''
- >>> html_quote('<hey!>')
- '&lt;hey!&gt;'
- >>> html_quote(u'\u1029')
- '\xe1\x80\xa9'
"""
encoding = encoding or default_encoding
if v is None:
@@ -33,10 +24,7 @@ def html_quote(v, encoding=None):
elif isinstance(v, six.binary_type):
return cgi.escape(v, 1)
elif isinstance(v, six.text_type):
- if six.PY3:
- return cgi.escape(v, 1)
- else:
- return cgi.escape(v.encode(encoding), 1)
+ return cgi.escape(v, 1)
else:
if six.PY3:
return cgi.escape(six.text_type(v), 1)
@@ -55,20 +43,8 @@ def html_unquote(s, encoding=None):
r"""
Decode the value.
- >>> html_unquote('&lt;hey&nbsp;you&gt;')
- u'<hey\xa0you>'
- >>> html_unquote('')
- u''
- >>> html_unquote('&blahblah;')
- u'&blahblah;'
- >>> html_unquote('\xe1\x80\xa9')
- u'\u1029'
"""
if isinstance(s, six.binary_type):
- if s == '':
- # workaround re.sub('', '', u'') returning '' < 2.5.2
- # instead of u'' >= 2.5.2
- return u''
s = s.decode(encoding or default_encoding)
return _unquote_re.sub(_entity_subber, s)