~fluidity-core/fluidity/exorcised

« back to all changes in this revision

Viewing changes to legacy_reservoir_prototype/tools/elementtree/XMLTreeBuilder.py

  • Committer: saunde01
  • Date: 2011-03-23 13:15:31 UTC
  • Revision ID: svn-v4:5bf5533e-7014-46e3-b1bb-cce4b9d03719:trunk:3310
As discussed in the Dev meeting and in emails, this commit renames the multiphase directory to legacy_reservoir_prototype, and adds an obvious warning to the top of the README file to warn unsuspecting users of the experimental nature of the code. Iterations on the exact wording very welcome

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# ElementTree
 
3
# $Id: XMLTreeBuilder.py 2305 2005-03-01 17:43:09Z fredrik $
 
4
#
 
5
# an XML tree builder
 
6
#
 
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
 
13
#
 
14
# Copyright (c) 1999-2004 by Fredrik Lundh.  All rights reserved.
 
15
#
 
16
# fredrik@pythonware.com
 
17
# http://www.pythonware.com
 
18
#
 
19
# --------------------------------------------------------------------
 
20
# The ElementTree toolkit is
 
21
#
 
22
# Copyright (c) 1999-2004 by Fredrik Lundh
 
23
#
 
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:
 
27
#
 
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.
 
36
#
 
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
# --------------------------------------------------------------------
 
46
 
 
47
##
 
48
# Tools to build element trees from XML files.
 
49
##
 
50
 
 
51
import ElementTree
 
52
 
 
53
##
 
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.
 
59
#
 
60
# @see elementtree.ElementTree
 
61
 
 
62
class TreeBuilder(ElementTree.XMLTreeBuilder):
 
63
    pass
 
64
 
 
65
##
 
66
# (experimental) An alternate builder that supports manipulation of
 
67
# new elements.
 
68
 
 
69
class FancyTreeBuilder(TreeBuilder):
 
70
 
 
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 = []
 
76
 
 
77
    def _start(self, tag, attrib_in):
 
78
        elem = TreeBuilder._start(self, tag, attrib_in)
 
79
        self.start(elem)
 
80
 
 
81
    def _start_list(self, tag, attrib_in):
 
82
        elem = TreeBuilder._start_list(self, tag, attrib_in)
 
83
        self.start(elem)
 
84
 
 
85
    def _end(self, tag):
 
86
        elem = TreeBuilder._end(self, tag)
 
87
        self.end(elem)
 
88
 
 
89
    def _start_ns(self, prefix, value):
 
90
        self.namespaces.insert(0, (prefix, value))
 
91
 
 
92
    def _end_ns(self, prefix):
 
93
        assert self.namespaces.pop(0)[0] == prefix, "implementation confused"
 
94
 
 
95
    ##
 
96
    # Hook method that's called when a new element has been opened.
 
97
    # May access the <b>namespaces</b> attribute.
 
98
    #
 
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.
 
102
 
 
103
    def start(self, element):
 
104
        pass
 
105
 
 
106
    ##
 
107
    # Hook method that's called when a new element has been closed.
 
108
    # May access the <b>namespaces</b> attribute.
 
109
    #
 
110
    # @param element The new element.
 
111
 
 
112
    def end(self, element):
 
113
        pass