webfaction and repo.or.cz deployment done
[worddb.git] / libs / elementtree / XMLTreeBuilder.py
blob405a7f285236c9e9b2212f9c5a268acf80ef81b8
2 # ElementTree
3 # $Id: XMLTreeBuilder.py 2305 2005-03-01 17:43:09Z fredrik $
5 # an XML tree builder
7 # history:
8 # 2001-10-20 fl created
9 # 2002-05-01 fl added namespace support for xmllib
10 # 2002-07-27 fl require expat (1.5.2 code can use SimpleXMLTreeBuilder)
11 # 2002-08-17 fl use tag/attribute name memo cache
12 # 2002-12-04 fl moved XMLTreeBuilder to the ElementTree module
14 # Copyright (c) 1999-2004 by Fredrik Lundh. All rights reserved.
16 # fredrik@pythonware.com
17 # http://www.pythonware.com
19 # --------------------------------------------------------------------
20 # The ElementTree toolkit is
22 # Copyright (c) 1999-2004 by Fredrik Lundh
24 # By obtaining, using, and/or copying this software and/or its
25 # associated documentation, you agree that you have read, understood,
26 # and will comply with the following terms and conditions:
28 # Permission to use, copy, modify, and distribute this software and
29 # its associated documentation for any purpose and without fee is
30 # hereby granted, provided that the above copyright notice appears in
31 # all copies, and that both that copyright notice and this permission
32 # notice appear in supporting documentation, and that the name of
33 # Secret Labs AB or the author not be used in advertising or publicity
34 # pertaining to distribution of the software without specific, written
35 # prior permission.
37 # SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
38 # TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT-
39 # ABILITY AND FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR
40 # BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
41 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
43 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
44 # OF THIS SOFTWARE.
45 # --------------------------------------------------------------------
48 # Tools to build element trees from XML files.
51 import ElementTree
54 # (obsolete) ElementTree builder for XML source data, based on the
55 # <b>expat</b> parser.
56 # <p>
57 # This class is an alias for ElementTree.XMLTreeBuilder. New code
58 # should use that version instead.
60 # @see elementtree.ElementTree
62 class TreeBuilder(ElementTree.XMLTreeBuilder):
63 pass
66 # (experimental) An alternate builder that supports manipulation of
67 # new elements.
69 class FancyTreeBuilder(TreeBuilder):
71 def __init__(self, html=0):
72 TreeBuilder.__init__(self, html)
73 self._parser.StartNamespaceDeclHandler = self._start_ns
74 self._parser.EndNamespaceDeclHandler = self._end_ns
75 self.namespaces = []
77 def _start(self, tag, attrib_in):
78 elem = TreeBuilder._start(self, tag, attrib_in)
79 self.start(elem)
81 def _start_list(self, tag, attrib_in):
82 elem = TreeBuilder._start_list(self, tag, attrib_in)
83 self.start(elem)
85 def _end(self, tag):
86 elem = TreeBuilder._end(self, tag)
87 self.end(elem)
89 def _start_ns(self, prefix, value):
90 self.namespaces.insert(0, (prefix, value))
92 def _end_ns(self, prefix):
93 assert self.namespaces.pop(0)[0] == prefix, "implementation confused"
96 # Hook method that's called when a new element has been opened.
97 # May access the <b>namespaces</b> attribute.
99 # @param element The new element. The tag name and attributes are,
100 # set, but it has no children, and the text and tail attributes
101 # are still empty.
103 def start(self, element):
104 pass
107 # Hook method that's called when a new element has been closed.
108 # May access the <b>namespaces</b> attribute.
110 # @param element The new element.
112 def end(self, element):
113 pass