~fluidity-core/fluidity/exorcised

« back to all changes in this revision

Viewing changes to multiphase/tools/elementtree/SgmlopXMLTreeBuilder.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$
4
 
#
5
 
# A simple XML tree builder, based on the sgmlop library.
6
 
#
7
 
# Note that this version does not support namespaces.  This may be
8
 
# changed in future versions.
9
 
#
10
 
# history:
11
 
# 2004-03-28 fl   created
12
 
#
13
 
# Copyright (c) 1999-2004 by Fredrik Lundh.  All rights reserved.
14
 
#
15
 
# fredrik@pythonware.com
16
 
# http://www.pythonware.com
17
 
#
18
 
# --------------------------------------------------------------------
19
 
# The ElementTree toolkit is
20
 
#
21
 
# Copyright (c) 1999-2004 by Fredrik Lundh
22
 
#
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:
26
 
#
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
34
 
# prior permission.
35
 
#
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
43
 
# OF THIS SOFTWARE.
44
 
# --------------------------------------------------------------------
45
 
 
46
 
##
47
 
# Tools to build element trees from XML, based on the SGMLOP parser.
48
 
# <p>
49
 
# The current version does not support XML namespaces.
50
 
# <p>
51
 
# This tree builder requires the <b>sgmlop</b> extension module
52
 
# (available from
53
 
# <a href='http://effbot.org/downloads'>http://effbot.org/downloads</a>).
54
 
##
55
 
 
56
 
import ElementTree
57
 
 
58
 
##
59
 
# ElementTree builder for XML source data, based on the SGMLOP parser.
60
 
#
61
 
# @see elementtree.ElementTree
62
 
 
63
 
class TreeBuilder:
64
 
 
65
 
    def __init__(self, html=0):
66
 
        try:
67
 
            import sgmlop
68
 
        except ImportError:
69
 
            raise RuntimeError("sgmlop parser not available")
70
 
        self.__builder = ElementTree.TreeBuilder()
71
 
        if html:
72
 
            import htmlentitydefs
73
 
            self.entitydefs.update(htmlentitydefs.entitydefs)
74
 
        self.__parser = sgmlop.XMLParser()
75
 
        self.__parser.register(self)
76
 
 
77
 
    ##
78
 
    # Feeds data to the parser.
79
 
    #
80
 
    # @param data Encoded data.
81
 
 
82
 
    def feed(self, data):
83
 
        self.__parser.feed(data)
84
 
 
85
 
    ##
86
 
    # Finishes feeding data to the parser.
87
 
    #
88
 
    # @return An element structure.
89
 
    # @defreturn Element
90
 
 
91
 
    def close(self):
92
 
        self.__parser.close()
93
 
        self.__parser = None
94
 
        return self.__builder.close()
95
 
 
96
 
    def finish_starttag(self, tag, attrib):
97
 
        self.__builder.start(tag, attrib)
98
 
 
99
 
    def finish_endtag(self, tag):
100
 
        self.__builder.end(tag)
101
 
 
102
 
    def handle_data(self, data):
103
 
        self.__builder.data(data)