[Python-checkins] cpython: #19688: add back and deprecate the internal HTMLParser.unescape() method.

ezio.melotti python-checkins at python.org
Fri Nov 22 04:49:43 CET 2013


http://hg.python.org/cpython/rev/0534b882f9ce
changeset:   87334:0534b882f9ce
user:        Ezio Melotti <ezio.melotti at gmail.com>
date:        Fri Nov 22 05:49:29 2013 +0200
summary:
  #19688: add back and deprecate the internal HTMLParser.unescape() method.

files:
  Lib/html/parser.py          |  7 +++++++
  Lib/test/test_htmlparser.py |  7 +++++++
  2 files changed, 14 insertions(+), 0 deletions(-)


diff --git a/Lib/html/parser.py b/Lib/html/parser.py
--- a/Lib/html/parser.py
+++ b/Lib/html/parser.py
@@ -513,3 +513,10 @@
     def unknown_decl(self, data):
         if self.strict:
             self.error("unknown declaration: %r" % (data,))
+
+    # Internal -- helper to remove special character quoting
+    def unescape(self, s):
+        warnings.warn('The unescape method is deprecated and will be removed '
+                      'in 3.5, use html.unescape() instead.',
+                      DeprecationWarning, stacklevel=2)
+        return unescape(s)
diff --git a/Lib/test/test_htmlparser.py b/Lib/test/test_htmlparser.py
--- a/Lib/test/test_htmlparser.py
+++ b/Lib/test/test_htmlparser.py
@@ -569,6 +569,13 @@
         for html, expected in data:
             self._run_check(html, expected)
 
+    def test_unescape_method(self):
+        from html import unescape
+        p = self.get_collector()
+        with self.assertWarns(DeprecationWarning):
+            s = '""&#x22;&quot&#34&#x22&#bad;'
+            self.assertEqual(p.unescape(s), unescape(s))
+
     def test_broken_comments(self):
         html = ('<! not really a comment >'
                 '<! not a comment either -->'

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list