Commit 877b10ad authored by Georg Brandl's avatar Georg Brandl

Remove the htmllib and sgmllib modules as per PEP 3108.

parent 6b38daa8
:mod:`formatter` --- Generic output formatting :mod:`formatter` --- Generic output formatting
============================================== ==============================================
...@@ -6,12 +5,9 @@ ...@@ -6,12 +5,9 @@
:synopsis: Generic output formatter and device interface. :synopsis: Generic output formatter and device interface.
.. index:: single: HTMLParser (class in htmllib)
This module supports two interface definitions, each with multiple This module supports two interface definitions, each with multiple
implementations. The *formatter* interface is used by the :class:`HTMLParser` implementations: The *formatter* interface, and the *writer* interface which is
class of the :mod:`htmllib` module, and the *writer* interface is required by required by the formatter interface.
the formatter interface.
Formatter objects transform an abstract flow of formatting events into specific Formatter objects transform an abstract flow of formatting events into specific
output events on writer objects. Formatters manage several stack structures to output events on writer objects. Formatters manage several stack structures to
......
...@@ -7,11 +7,10 @@ ...@@ -7,11 +7,10 @@
This module defines three dictionaries, ``name2codepoint``, ``codepoint2name``, This module defines three dictionaries, ``name2codepoint``, ``codepoint2name``,
and ``entitydefs``. ``entitydefs`` is used by the :mod:`htmllib` module to and ``entitydefs``. ``entitydefs`` is used to provide the :attr:`entitydefs`
provide the :attr:`entitydefs` member of the :class:`html.parser.HTMLParser` member of the :class:`html.parser.HTMLParser` class. The definition provided
class. The definition provided here contains all the entities defined by XHTML here contains all the entities defined by XHTML 1.0 that can be handled using
1.0 that can be handled using simple textual substitution in the Latin-1 simple textual substitution in the Latin-1 character set (ISO-8859-1).
character set (ISO-8859-1).
.. data:: entitydefs .. data:: entitydefs
......
...@@ -11,9 +11,6 @@ ...@@ -11,9 +11,6 @@
This module defines a class :class:`HTMLParser` which serves as the basis for This module defines a class :class:`HTMLParser` which serves as the basis for
parsing text files formatted in HTML (HyperText Mark-up Language) and XHTML. parsing text files formatted in HTML (HyperText Mark-up Language) and XHTML.
Unlike the parser in :mod:`htmllib`, this parser is not based on the SGML parser
in :mod:`sgmllib`.
.. class:: HTMLParser() .. class:: HTMLParser()
...@@ -23,9 +20,8 @@ in :mod:`sgmllib`. ...@@ -23,9 +20,8 @@ in :mod:`sgmllib`.
begin and end. The :class:`HTMLParser` class is meant to be overridden by the begin and end. The :class:`HTMLParser` class is meant to be overridden by the
user to provide a desired behavior. user to provide a desired behavior.
Unlike the parser in :mod:`htmllib`, this parser does not check that end tags This parser does not check that end tags match start tags or call the end-tag
match start tags or call the end-tag handler for elements which are closed handler for elements which are closed implicitly by closing an outer element.
implicitly by closing an outer element.
An exception is defined as well: An exception is defined as well:
......
:mod:`htmllib` --- A parser for HTML documents
==============================================
.. module:: htmllib
:synopsis: A parser for HTML documents.
.. index::
single: HTML
single: hypertext
.. index::
module: sgmllib
module: formatter
single: SGMLParser (in module sgmllib)
This module defines a class which can serve as a base for parsing text files
formatted in the HyperText Mark-up Language (HTML). The class is not directly
concerned with I/O --- it must be provided with input in string form via a
method, and makes calls to methods of a "formatter" object in order to produce
output. The :class:`HTMLParser` class is designed to be used as a base class
for other classes in order to add functionality, and allows most of its methods
to be extended or overridden. In turn, this class is derived from and extends
the :class:`SGMLParser` class defined in module :mod:`sgmllib`. The
:class:`HTMLParser` implementation supports the HTML 2.0 language as described
in :rfc:`1866`. Two implementations of formatter objects are provided in the
:mod:`formatter` module; refer to the documentation for that module for
information on the formatter interface.
The following is a summary of the interface defined by
:class:`sgmllib.SGMLParser`:
* The interface to feed data to an instance is through the :meth:`feed` method,
which takes a string argument. This can be called with as little or as much
text at a time as desired; ``p.feed(a); p.feed(b)`` has the same effect as
``p.feed(a+b)``. When the data contains complete HTML markup constructs, these
are processed immediately; incomplete constructs are saved in a buffer. To
force processing of all unprocessed data, call the :meth:`close` method.
For example, to parse the entire contents of a file, use::
parser.feed(open('myfile.html').read())
parser.close()
* The interface to define semantics for HTML tags is very simple: derive a class
and define methods called :meth:`start_tag`, :meth:`end_tag`, or :meth:`do_tag`.
The parser will call these at appropriate moments: :meth:`start_tag` or
:meth:`do_tag` is called when an opening tag of the form ``<tag ...>`` is
encountered; :meth:`end_tag` is called when a closing tag of the form ``<tag>``
is encountered. If an opening tag requires a corresponding closing tag, like
``<H1>`` ... ``</H1>``, the class should define the :meth:`start_tag` method; if
a tag requires no closing tag, like ``<P>``, the class should define the
:meth:`do_tag` method.
The module defines a parser class and an exception:
.. class:: HTMLParser(formatter)
This is the basic HTML parser class. It supports all entity names required by
the XHTML 1.0 Recommendation (http://www.w3.org/TR/xhtml1). It also defines
handlers for all HTML 2.0 and many HTML 3.0 and 3.2 elements.
.. exception:: HTMLParseError
Exception raised by the :class:`HTMLParser` class when it encounters an error
while parsing.
.. seealso::
Module :mod:`formatter`
Interface definition for transforming an abstract flow of formatting events into
specific output events on writer objects.
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:`html.entities`
Definition of replacement text for XHTML 1.0 entities.
Module :mod:`sgmllib`
Base class for :class:`HTMLParser`.
.. _html-parser-objects:
HTMLParser Objects
------------------
In addition to tag methods, the :class:`HTMLParser` class provides some
additional methods and instance variables for use within tag methods.
.. attribute:: HTMLParser.formatter
This is the formatter instance associated with the parser.
.. attribute:: HTMLParser.nofill
Boolean flag which should be true when whitespace should not be collapsed, or
false when it should be. In general, this should only be true when character
data is to be treated as "preformatted" text, as within a ``<PRE>`` element.
The default value is false. This affects the operation of :meth:`handle_data`
and :meth:`save_end`.
.. method:: HTMLParser.anchor_bgn(href, name, type)
This method is called at the start of an anchor region. The arguments
correspond to the attributes of the ``<A>`` tag with the same names. The
default implementation maintains a list of hyperlinks (defined by the ``HREF``
attribute for ``<A>`` tags) within the document. The list of hyperlinks is
available as the data attribute :attr:`anchorlist`.
.. method:: HTMLParser.anchor_end()
This method is called at the end of an anchor region. The default
implementation adds a textual footnote marker using an index into the list of
hyperlinks created by :meth:`anchor_bgn`.
.. method:: HTMLParser.handle_image(source, alt[, ismap[, align[, width[, height]]]])
This method is called to handle images. The default implementation simply
passes the *alt* value to the :meth:`handle_data` method.
.. method:: HTMLParser.save_bgn()
Begins saving character data in a buffer instead of sending it to the formatter
object. Retrieve the stored data via :meth:`save_end`. Use of the
:meth:`save_bgn` / :meth:`save_end` pair may not be nested.
.. method:: HTMLParser.save_end()
Ends buffering character data and returns all data saved since the preceding
call to :meth:`save_bgn`. If the :attr:`nofill` flag is false, whitespace is
collapsed to single spaces. A call to this method without a preceding call to
:meth:`save_bgn` will raise a :exc:`TypeError` exception.
...@@ -23,8 +23,6 @@ definition of the Python bindings for the DOM and SAX interfaces. ...@@ -23,8 +23,6 @@ definition of the Python bindings for the DOM and SAX interfaces.
html.parser.rst html.parser.rst
html.entities.rst html.entities.rst
sgmllib.rst
htmllib.rst
pyexpat.rst pyexpat.rst
xml.dom.rst xml.dom.rst
xml.dom.minidom.rst xml.dom.minidom.rst
......
This diff is collapsed.
...@@ -389,14 +389,13 @@ URL Opener objects ...@@ -389,14 +389,13 @@ URL Opener objects
.. index:: .. index::
single: HTML single: HTML
pair: HTTP; protocol pair: HTTP; protocol
module: htmllib
* The data returned by :func:`urlopen` or :func:`urlretrieve` is the raw data * The data returned by :func:`urlopen` or :func:`urlretrieve` is the raw data
returned by the server. This may be binary data (such as an image), plain text returned by the server. This may be binary data (such as an image), plain text
or (for example) HTML. The HTTP protocol provides type information in the reply or (for example) HTML. The HTTP protocol provides type information in the reply
header, which can be inspected by looking at the :mailheader:`Content-Type` header, which can be inspected by looking at the :mailheader:`Content-Type`
header. If the returned data is HTML, you can use the module :mod:`htmllib` to header. If the returned data is HTML, you can use the module
parse it. :mod:`html.parser` to parse it.
.. index:: single: FTP .. index:: single: FTP
......
"""Shared support for scanning document type declarations in HTML and XHTML. """Shared support for scanning document type declarations in HTML and XHTML.
This module is used as a foundation for the HTMLParser and sgmllib This module is used as a foundation for the html.parser module. It has no
modules (indirectly, for htmllib as well). It has no documented documented public API and should not be used directly.
public API and should not be used directly.
""" """
......
This diff is collapsed.
This diff is collapsed.
...@@ -73,7 +73,6 @@ class AllTest(unittest.TestCase): ...@@ -73,7 +73,6 @@ class AllTest(unittest.TestCase):
self.check_all("glob") self.check_all("glob")
self.check_all("gzip") self.check_all("gzip")
self.check_all("heapq") self.check_all("heapq")
self.check_all("htmllib")
self.check_all("http.client") self.check_all("http.client")
self.check_all("ihooks") self.check_all("ihooks")
self.check_all("imaplib") self.check_all("imaplib")
...@@ -116,7 +115,6 @@ class AllTest(unittest.TestCase): ...@@ -116,7 +115,6 @@ class AllTest(unittest.TestCase):
self.check_all("rlcompleter") self.check_all("rlcompleter")
self.check_all("robotparser") self.check_all("robotparser")
self.check_all("sched") self.check_all("sched")
self.check_all("sgmllib")
self.check_all("shelve") self.check_all("shelve")
self.check_all("shlex") self.check_all("shlex")
self.check_all("shutil") self.check_all("shutil")
......
import formatter
import htmllib
import unittest
from test import support
class AnchorCollector(htmllib.HTMLParser):
def __init__(self, *args, **kw):
self.__anchors = []
htmllib.HTMLParser.__init__(self, *args, **kw)
def get_anchor_info(self):
return self.__anchors
def anchor_bgn(self, *args):
self.__anchors.append(args)
class DeclCollector(htmllib.HTMLParser):
def __init__(self, *args, **kw):
self.__decls = []
htmllib.HTMLParser.__init__(self, *args, **kw)
def get_decl_info(self):
return self.__decls
def unknown_decl(self, data):
self.__decls.append(data)
class HTMLParserTestCase(unittest.TestCase):
def test_anchor_collection(self):
# See SF bug #467059.
parser = AnchorCollector(formatter.NullFormatter(), verbose=1)
parser.feed(
"""<a href='http://foo.org/' name='splat'> </a>
<a href='http://www.python.org/'> </a>
<a name='frob'> </a>
""")
parser.close()
self.assertEquals(parser.get_anchor_info(),
[('http://foo.org/', 'splat', ''),
('http://www.python.org/', '', ''),
('', 'frob', ''),
])
def test_decl_collection(self):
# See SF patch #545300
parser = DeclCollector(formatter.NullFormatter(), verbose=1)
parser.feed(
"""<html>
<body>
hallo
<![if !supportEmptyParas]>&nbsp;<![endif]>
</body>
</html>
""")
parser.close()
self.assertEquals(parser.get_decl_info(),
["if !supportEmptyParas",
"endif"
])
def test_main():
support.run_unittest(HTMLParserTestCase)
if __name__ == "__main__":
test_main()
This diff is collapsed.
...@@ -60,6 +60,8 @@ Extension Modules ...@@ -60,6 +60,8 @@ Extension Modules
Library Library
------- -------
- Removed the ``htmllib`` and ``sgmllib`` modules.
- The deprecated ``SmartCookie`` and ``SimpleCookie`` classes have - The deprecated ``SmartCookie`` and ``SimpleCookie`` classes have
been removed from ``http.cookies``. been removed from ``http.cookies``.
......
...@@ -1895,7 +1895,6 @@ reprlib Redo repr() but with limits on most sizes. ...@@ -1895,7 +1895,6 @@ reprlib Redo repr() but with limits on most sizes.
rlcompleter Word completion for GNU readline 2.0. rlcompleter Word completion for GNU readline 2.0.
robotparser Parse robots.txt files, useful for web spiders. robotparser Parse robots.txt files, useful for web spiders.
sched A generally useful event scheduler class. sched A generally useful event scheduler class.
sgmllib A parser for SGML.
shelve Manage shelves of pickled objects. shelve Manage shelves of pickled objects.
shlex Lexical analyzer class for simple shell-like syntaxes. shlex Lexical analyzer class for simple shell-like syntaxes.
shutil Utility functions usable in a shell-like program. shutil Utility functions usable in a shell-like program.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment