]> granicus.if.org Git - python/commitdiff
rename HTMLParser to html.parser and htmlentitydefs to html.entities;
authorFred Drake <fdrake@acm.org>
Sat, 17 May 2008 22:02:32 +0000 (22:02 +0000)
committerFred Drake <fdrake@acm.org>
Sat, 17 May 2008 22:02:32 +0000 (22:02 +0000)
includes merge of trunk revision 63432

Doc/library/htmllib.rst
Doc/library/htmlparser.rst
Lib/html/__init__.py [new file with mode: 0644]
Lib/html/entities.py [moved from Lib/htmlentitydefs.py with 100% similarity]
Lib/html/parser.py [moved from Lib/HTMLParser.py with 97% similarity]
Lib/htmllib.py
Lib/test/test_codeccallbacks.py
Lib/test/test_multibytecodec_support.py
Lib/test/test_sundry.py

index e1f2447fbdd3920df23568ea4d3e1e945983a942..34423a044715edfdab2310e882e18a3eef77078e 100644 (file)
@@ -75,12 +75,12 @@ The module defines a parser class and an exception:
       Interface definition for transforming an abstract flow of formatting events into
       specific output events on writer objects.
 
-   Module :mod:`HTMLParser`
+   Module :mod:`html.parser`
       Alternate HTML parser that offers a slightly lower-level view of the input, but
       is designed to work with XHTML, and does not implement some of the SGML syntax
       not used in "HTML as deployed" and which isn't legal for XHTML.
 
-   Module :mod:`htmlentitydefs`
+   Module :mod:`html.entities`
       Definition of replacement text for XHTML 1.0  entities.
 
    Module :mod:`sgmllib`
@@ -147,10 +147,10 @@ additional methods and instance variables for use within tag methods.
    :meth:`save_bgn` will raise a :exc:`TypeError` exception.
 
 
-:mod:`htmlentitydefs` --- Definitions of HTML general entities
-==============================================================
+:mod:`html.entities` --- Definitions of HTML general entities
+=============================================================
 
-.. module:: htmlentitydefs
+.. module:: html.entities
    :synopsis: Definitions of HTML general entities.
 .. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
 
index 5cfe04ef1a4f3f36c9f4dbde9710064ce9c26010..4bfb2878403eb044cd57f613803a5c95d342c0c6 100644 (file)
@@ -1,8 +1,8 @@
 
-:mod:`HTMLParser` --- Simple HTML and XHTML parser
-==================================================
+:mod:`html.parser` --- Simple HTML and XHTML parser
+===================================================
 
-.. module:: HTMLParser
+.. module:: html.parser
    :synopsis: A simple parser that can handle HTML and XHTML.
 
 
@@ -18,7 +18,7 @@ in :mod:`sgmllib`.
 
    The :class:`HTMLParser` class is instantiated without arguments.
 
-   An HTMLParser instance is fed HTML data and calls handler functions when tags
+   An :class:`HTMLParser` instance is fed HTML data and calls handler functions when tags
    begin and end.  The :class:`HTMLParser` class is meant to be overridden by the
    user to provide a desired behavior.
 
@@ -87,8 +87,8 @@ An exception is defined as well:
    HREF="http://www.cwi.nl/">``, this method would be called as
    ``handle_starttag('a', [('href', 'http://www.cwi.nl/')])``.
 
-   All entity references from htmlentitydefs are replaced in the attribute
-   values.
+   All entity references from :mod:`html.entities` are replaced in the
+   attribute values.
 
 
 .. method:: HTMLParser.handle_startendtag(tag, attrs)
@@ -166,7 +166,7 @@ Example HTML Parser Application
 As a basic example, below is a very basic HTML parser that uses the
 :class:`HTMLParser` class to print out tags as they are encountered::
 
-   from HTMLParser import HTMLParser
+   from html.parser import HTMLParser
 
    class MyHTMLParser(HTMLParser):
 
diff --git a/Lib/html/__init__.py b/Lib/html/__init__.py
new file mode 100644 (file)
index 0000000..196d378
--- /dev/null
@@ -0,0 +1 @@
+# This directory is a Python package.
similarity index 100%
rename from Lib/htmlentitydefs.py
rename to Lib/html/entities.py
similarity index 97%
rename from Lib/HTMLParser.py
rename to Lib/html/parser.py
index 99791955f31d25af00c45831152221d2d186db61..352a78841c0648afc0d356fc4fe95102a9b264a5 100644 (file)
@@ -372,16 +372,17 @@ class HTMLParser(_markupbase.ParserBase):
                     c = int(s)
                 return chr(c)
             else:
-                # Cannot use name2codepoint directly, because HTMLParser supports apos,
-                # which is not part of HTML 4
-                import htmlentitydefs
+                # Cannot use name2codepoint directly, because HTMLParser
+                # supports apos, which is not part of HTML 4
+                import html.entities
                 if HTMLParser.entitydefs is None:
                     entitydefs = HTMLParser.entitydefs = {'apos':"'"}
-                    for k, v in htmlentitydefs.name2codepoint.items():
-                        entitydefs[k] = chr(v)
+                    for k, v in html.entities.name2codepoint.items():
+                        entitydefs[k] = unichr(v)
                 try:
                     return self.entitydefs[s]
                 except KeyError:
                     return '&'+s+';'
 
-        return re.sub(r"&(#?[xX]?(?:[0-9a-fA-F]+|\w{1,8}));", replaceEntities, s)
+        return re.sub(r"&(#?[xX]?(?:[0-9a-fA-F]+|\w{1,8}));",
+                      replaceEntities, s)
index 88e1df5741c06c44bb0917bc7c4085a2ceb50f3d..a5800068283f18c2426636c5b81af5d2bba4f538 100644 (file)
@@ -24,7 +24,7 @@ class HTMLParser(sgmllib.SGMLParser):
 
     """
 
-    from htmlentitydefs import entitydefs
+    from html.entities import entitydefs
 
     def __init__(self, formatter, verbose=0):
         """Creates an instance of the HTMLParser class.
index 12eb068c2aa05810ff85eb2efebf9334ee75664a..64d1645dbb2dffdc13012fe3405dcd7aa19fee18 100644 (file)
@@ -1,5 +1,5 @@
 import test.test_support, unittest
-import sys, codecs, htmlentitydefs, unicodedata
+import sys, codecs, html.entities, unicodedata
 
 class PosReturn:
     # this can be used for configurable callbacks
@@ -86,7 +86,7 @@ class CodecCallbackTest(unittest.TestCase):
             l = []
             for c in exc.object[exc.start:exc.end]:
                 try:
-                    l.append("&%s;" % htmlentitydefs.codepoint2name[ord(c)])
+                    l.append("&%s;" % html.entities.codepoint2name[ord(c)])
                 except KeyError:
                     l.append("&#%d;" % ord(c))
             return ("".join(l), exc.end)
index 48e90899ddaf1adb7e7761883d9bbfb2d511c582..5508c9d09c201aed1f77ec757e5aa6ad0f494151 100644 (file)
@@ -74,7 +74,7 @@ class TestBase:
         if self.has_iso10646:
             return
 
-        from htmlentitydefs import codepoint2name
+        from html.entities import codepoint2name
 
         def xmlcharnamereplace(exc):
             if not isinstance(exc, UnicodeEncodeError):
index dd81e5b27e3f41e99cfd1ca8fd0792fe2a2285b5..1b6069dde08e86c70a118e330f29a5cfd4edc0cd 100644 (file)
@@ -48,7 +48,7 @@ class TestUntestedModules(unittest.TestCase):
             import encodings
             import formatter
             import getpass
-            import htmlentitydefs
+            import html.entities
             import imghdr
             import keyword
             import linecache