[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue common/src/GParser.py forms/src/GFParser.py
From: |
James Thompson |
Subject: |
gnue common/src/GParser.py forms/src/GFParser.py |
Date: |
Wed, 06 Nov 2002 22:20:33 -0500 |
CVSROOT: /cvsroot/gnue
Module name: gnue
Changes by: James Thompson <address@hidden> 02/11/06 22:20:33
Modified files:
common/src : GParser.py
forms/src : GFParser.py
Log message:
GParser now honors the Required and SingleInstance attributes on tag
definitions.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/GParser.py.diff?tr1=1.46&tr2=1.47&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/forms/src/GFParser.py.diff?tr1=1.77&tr2=1.78&r1=text&r2=text
Patches:
Index: gnue/common/src/GParser.py
diff -c gnue/common/src/GParser.py:1.46 gnue/common/src/GParser.py:1.47
*** gnue/common/src/GParser.py:1.46 Mon Nov 4 15:14:54 2002
--- gnue/common/src/GParser.py Wed Nov 6 22:20:33 2002
***************
*** 83,88 ****
--- 83,90 ----
def loadXMLObject(stream, handler, rootType, xmlFileType,
initialize=1, attributes={}, initParameters={}):
+
+
# Create a parser
parser = xml.sax.make_parser()
***************
*** 98,103 ****
--- 100,106 ----
# Create the handler
dh = handler()
+ dh.initValidation()
# Tell the parser to use our handler
parser.setContentHandler(dh)
***************
*** 111,123 ****
--- 114,131 ----
raise MarkupError, _("Error loading %s: not a valid %s definition
(expected: %s, got: %s)") % (xmlFileType,
xmlFileType, rootType, object._type)
+ dh.finalValidation()
+
# Set the object's attributes
object.__dict__.update(attributes)
+
if initialize:
GDebug.printMesg(10,"Initializing the object tree starting at %s"
%(object))
object.phaseInit(dh._phaseInitCount)
+
+
return object
***************
*** 159,165 ****
--- 167,178 ----
self.uniqueIDs = {}
self.root = None
self._phaseInitCount = 0
+
+ self._requiredTags = []
+ self._singleInstanceTags = []
+ self._tagCounts = {}
+
#
# Called by client code to get the "root" node
#
***************
*** 167,172 ****
--- 180,217 ----
return self.root
#
+ # Builds structures need to verify requirements in the file
+ #
+ def initValidation(self):
+ #
+ # Build list of tags along with a list of
+ # require tags
+ #
+ for element in self.xmlElements.keys():
+ self._tagCounts[element] = 0
+ try:
+ if self.xmlElements[element]['Required'] == 1:
+ self._requiredTags.append(element)
+ except KeyError:
+ pass
+
+ try:
+ if self.xmlElements[element]['SingleInstance'] == 1:
+ self._singleInstanceTags.append(element)
+ except KeyError:
+ pass
+
+ def finalValidation(self):
+ for element in self._singleInstanceTags:
+ if self._tagCounts[element] > 1:
+ raise MarkupError, _("File has multiple instances of <%s> when only
one allowed") % (element)
+
+ for element in self._requiredTags:
+ if self._tagCounts[element] < 1:
+ raise MarkupError, _("File is missing required tag <%s>") % (element)
+
+
+ #
# Called by the internal SAX parser whenever
# a starting XML element/tag is encountered.
#
***************
*** 175,180 ****
--- 220,226 ----
attrs = {}
loadedxmlattrs = {}
+ self._tagCounts[name] += 1
if not ns:
#
# No namespace qualifier
***************
*** 182,188 ****
GDebug.printMesg(50, "<%s>" % name)
try:
! baseAttrs = self.xmlElements[name].get('Attributes',{}) #
default(self.xmlElements[name],'Attributes',{})
except KeyError:
raise MarkupError, _('Error processing <%s> tag [I do not know what a
<%s> tag does]') % (name, name)
--- 228,234 ----
GDebug.printMesg(50, "<%s>" % name)
try:
! baseAttrs = self.xmlElements[name].get('Attributes',{})
except KeyError:
raise MarkupError, _('Error processing <%s> tag [I do not know what a
<%s> tag does]') % (name, name)
Index: gnue/forms/src/GFParser.py
diff -c gnue/forms/src/GFParser.py:1.77 gnue/forms/src/GFParser.py:1.78
*** gnue/forms/src/GFParser.py:1.77 Mon Nov 4 15:14:55 2002
--- gnue/forms/src/GFParser.py Wed Nov 6 22:20:33 2002
***************
*** 138,143 ****
--- 138,144 ----
'block': {
'BaseClass': GFObjects.GFBlock,
+ 'Required': 1,
'Importable':1,
'Attributes': {
'name': {
***************
*** 387,393 ****
'options': {
'BaseClass': GFObjects.GFOptions,
- 'SingleInstance': 1,
'UsableBySiblings': 1,
'ParentTags': ('form',) },
--- 388,393 ----
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gnue common/src/GParser.py forms/src/GFParser.py,
James Thompson <=