Skip to content

Commit 3c50ea4

Browse files
committed
rename HTMLParser to html.parser and htmlentitydefs to html.entities;
includes merge of trunk revision 63432
1 parent 9b020c7 commit 3c50ea4

9 files changed

Lines changed: 25 additions & 23 deletions

File tree

Doc/library/htmllib.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ The module defines a parser class and an exception:
7575
Interface definition for transforming an abstract flow of formatting events into
7676
specific output events on writer objects.
7777

78-
Module :mod:`HTMLParser`
78+
Module :mod:`html.parser`
7979
Alternate HTML parser that offers a slightly lower-level view of the input, but
8080
is designed to work with XHTML, and does not implement some of the SGML syntax
8181
not used in "HTML as deployed" and which isn't legal for XHTML.
8282

83-
Module :mod:`htmlentitydefs`
83+
Module :mod:`html.entities`
8484
Definition of replacement text for XHTML 1.0 entities.
8585

8686
Module :mod:`sgmllib`
@@ -147,10 +147,10 @@ additional methods and instance variables for use within tag methods.
147147
:meth:`save_bgn` will raise a :exc:`TypeError` exception.
148148

149149

150-
:mod:`htmlentitydefs` --- Definitions of HTML general entities
151-
==============================================================
150+
:mod:`html.entities` --- Definitions of HTML general entities
151+
=============================================================
152152

153-
.. module:: htmlentitydefs
153+
.. module:: html.entities
154154
:synopsis: Definitions of HTML general entities.
155155
.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
156156

Doc/library/htmlparser.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

2-
:mod:`HTMLParser` --- Simple HTML and XHTML parser
3-
==================================================
2+
:mod:`html.parser` --- Simple HTML and XHTML parser
3+
===================================================
44

5-
.. module:: HTMLParser
5+
.. module:: html.parser
66
:synopsis: A simple parser that can handle HTML and XHTML.
77

88

@@ -18,7 +18,7 @@ in :mod:`sgmllib`.
1818

1919
The :class:`HTMLParser` class is instantiated without arguments.
2020

21-
An HTMLParser instance is fed HTML data and calls handler functions when tags
21+
An :class:`HTMLParser` instance is fed HTML data and calls handler functions when tags
2222
begin and end. The :class:`HTMLParser` class is meant to be overridden by the
2323
user to provide a desired behavior.
2424

@@ -87,8 +87,8 @@ An exception is defined as well:
8787
HREF="http://www.cwi.nl/">``, this method would be called as
8888
``handle_starttag('a', [('href', 'http://www.cwi.nl/')])``.
8989

90-
All entity references from htmlentitydefs are replaced in the attribute
91-
values.
90+
All entity references from :mod:`html.entities` are replaced in the
91+
attribute values.
9292

9393

9494
.. method:: HTMLParser.handle_startendtag(tag, attrs)
@@ -166,7 +166,7 @@ Example HTML Parser Application
166166
As a basic example, below is a very basic HTML parser that uses the
167167
:class:`HTMLParser` class to print out tags as they are encountered::
168168

169-
from HTMLParser import HTMLParser
169+
from html.parser import HTMLParser
170170

171171
class MyHTMLParser(HTMLParser):
172172

Lib/html/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This directory is a Python package.
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,16 +372,17 @@ def replaceEntities(s):
372372
c = int(s)
373373
return chr(c)
374374
else:
375-
# Cannot use name2codepoint directly, because HTMLParser supports apos,
376-
# which is not part of HTML 4
377-
import htmlentitydefs
375+
# Cannot use name2codepoint directly, because HTMLParser
376+
# supports apos, which is not part of HTML 4
377+
import html.entities
378378
if HTMLParser.entitydefs is None:
379379
entitydefs = HTMLParser.entitydefs = {'apos':"'"}
380-
for k, v in htmlentitydefs.name2codepoint.items():
381-
entitydefs[k] = chr(v)
380+
for k, v in html.entities.name2codepoint.items():
381+
entitydefs[k] = unichr(v)
382382
try:
383383
return self.entitydefs[s]
384384
except KeyError:
385385
return '&'+s+';'
386386

387-
return re.sub(r"&(#?[xX]?(?:[0-9a-fA-F]+|\w{1,8}));", replaceEntities, s)
387+
return re.sub(r"&(#?[xX]?(?:[0-9a-fA-F]+|\w{1,8}));",
388+
replaceEntities, s)

Lib/htmllib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class HTMLParser(sgmllib.SGMLParser):
2424
2525
"""
2626

27-
from htmlentitydefs import entitydefs
27+
from html.entities import entitydefs
2828

2929
def __init__(self, formatter, verbose=0):
3030
"""Creates an instance of the HTMLParser class.

Lib/test/test_codeccallbacks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import test.test_support, unittest
2-
import sys, codecs, htmlentitydefs, unicodedata
2+
import sys, codecs, html.entities, unicodedata
33

44
class PosReturn:
55
# this can be used for configurable callbacks
@@ -86,7 +86,7 @@ def xmlcharnamereplace(exc):
8686
l = []
8787
for c in exc.object[exc.start:exc.end]:
8888
try:
89-
l.append("&%s;" % htmlentitydefs.codepoint2name[ord(c)])
89+
l.append("&%s;" % html.entities.codepoint2name[ord(c)])
9090
except KeyError:
9191
l.append("&#%d;" % ord(c))
9292
return ("".join(l), exc.end)

Lib/test/test_multibytecodec_support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_customreplace_encode(self):
7474
if self.has_iso10646:
7575
return
7676

77-
from htmlentitydefs import codepoint2name
77+
from html.entities import codepoint2name
7878

7979
def xmlcharnamereplace(exc):
8080
if not isinstance(exc, UnicodeEncodeError):

Lib/test/test_sundry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_at_least_import_untested_modules(self):
4848
import encodings
4949
import formatter
5050
import getpass
51-
import htmlentitydefs
51+
import html.entities
5252
import imghdr
5353
import keyword
5454
import linecache

0 commit comments

Comments
 (0)