5
# A simple XML tree builder, based on the sgmlop library.
7
# Note that this version does not support namespaces. This may be
8
# changed in future versions.
11
# 2004-03-28 fl created
13
# Copyright (c) 1999-2004 by Fredrik Lundh. All rights reserved.
15
# fredrik@pythonware.com
16
# http://www.pythonware.com
18
# --------------------------------------------------------------------
19
# The ElementTree toolkit is
21
# Copyright (c) 1999-2004 by Fredrik Lundh
23
# By obtaining, using, and/or copying this software and/or its
24
# associated documentation, you agree that you have read, understood,
25
# and will comply with the following terms and conditions:
27
# Permission to use, copy, modify, and distribute this software and
28
# its associated documentation for any purpose and without fee is
29
# hereby granted, provided that the above copyright notice appears in
30
# all copies, and that both that copyright notice and this permission
31
# notice appear in supporting documentation, and that the name of
32
# Secret Labs AB or the author not be used in advertising or publicity
33
# pertaining to distribution of the software without specific, written
36
# SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
37
# TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT-
38
# ABILITY AND FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR
39
# BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
40
# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
42
# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
44
# --------------------------------------------------------------------
47
# Tools to build element trees from XML, based on the SGMLOP parser.
49
# The current version does not support XML namespaces.
51
# This tree builder requires the <b>sgmlop</b> extension module
53
# <a href='http://effbot.org/downloads'>http://effbot.org/downloads</a>).
59
# ElementTree builder for XML source data, based on the SGMLOP parser.
61
# @see elementtree.ElementTree
65
def __init__(self, html=0):
69
raise RuntimeError("sgmlop parser not available")
70
self.__builder = ElementTree.TreeBuilder()
73
self.entitydefs.update(htmlentitydefs.entitydefs)
74
self.__parser = sgmlop.XMLParser()
75
self.__parser.register(self)
78
# Feeds data to the parser.
80
# @param data Encoded data.
83
self.__parser.feed(data)
86
# Finishes feeding data to the parser.
88
# @return An element structure.
94
return self.__builder.close()
96
def finish_starttag(self, tag, attrib):
97
self.__builder.start(tag, attrib)
99
def finish_endtag(self, tag):
100
self.__builder.end(tag)
102
def handle_data(self, data):
103
self.__builder.data(data)