commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/common/src GObjects.py GParser.py


From: Jason Cater
Subject: gnue/common/src GObjects.py GParser.py
Date: Mon, 25 Mar 2002 23:19:47 -0500

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    02/03/25 23:19:47

Modified files:
        common/src     : GObjects.py GParser.py 

Log message:
        performance enhancements

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/common/src/GObjects.py.diff?cvsroot=OldCVS&tr1=1.27&tr2=1.28&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/common/src/GParser.py.diff?cvsroot=OldCVS&tr1=1.30&tr2=1.31&r1=text&r2=text

Patches:
Index: gnue/common/src/GObjects.py
diff -c gnue/common/src/GObjects.py:1.27 gnue/common/src/GObjects.py:1.28
*** gnue/common/src/GObjects.py:1.27    Wed Jan 30 19:28:49 2002
--- gnue/common/src/GObjects.py Mon Mar 25 23:19:46 2002
***************
*** 61,66 ****
--- 61,67 ----
      self._children = []
      self._attributes = {}
      self._inits = []
+     self._xmlnamespace = None
      if parent :
        parent.addChild(self)
  
***************
*** 73,79 ****
  
    def _phaseInit(self,phase):
      if (len(self._inits) > phase) and (self._inits[phase] != None):
!       GDebug.printMesg(6,"%s: Init Phase %s" % (self.getObjectType(), 
phase+1))
        self._inits[phase]()
  
      if self._children:
--- 74,80 ----
  
    def _phaseInit(self,phase):
      if (len(self._inits) > phase) and (self._inits[phase] != None):
!       GDebug.printMesg(6,"%s: Init Phase %s" % (self._type, phase+1))
        self._inits[phase]()
  
      if self._children:
***************
*** 215,224 ****
    #
    def findParentOfType(self,type):
      parentObject = self
!     while (parentObject._parent != None and parentObject.getObjectType() != 
type):
        parentObject = parentObject._parent
  
!     if parentObject.getObjectType() == type:
        return parentObject
      else:
        return None
--- 216,225 ----
    #
    def findParentOfType(self,type):
      parentObject = self
!     while (parentObject._parent != None and parentObject._type != type):
        parentObject = parentObject._parent
  
!     if parentObject._type == type:
        return parentObject
      else:
        return None
Index: gnue/common/src/GParser.py
diff -c gnue/common/src/GParser.py:1.30 gnue/common/src/GParser.py:1.31
*** gnue/common/src/GParser.py:1.30     Fri Mar 22 03:08:06 2002
--- gnue/common/src/GParser.py  Mon Mar 25 23:19:46 2002
***************
*** 175,180 ****
--- 175,181 ----
    def __init__(self):
  
      self.xmlElements = {}
+     self.xmlMasqueradeNamespaceElements = None
  
      self.xmlStack = []
      self.nameStack = []
***************
*** 195,251 ****
    #
    def startElementNS(self, qtag, qname, saxattrs):
      ns, name = qtag
- 
-     GDebug.printMesg(50, "<%s>" % name)
- 
-     # Make sure the tag we are looking at is a valid tag
-     if not self.xmlElements.has_key (name):
-       raise MarkupError, 'Error processing <%s> tag [I do not know what a 
<%s> tag does]' % (name, name)
- 
-     baseAttrs = default(self.xmlElements[name],'Attributes',{})
      attrs = {}
      loadedxmlattrs = {}
  
!     for qattr in saxattrs.keys():
!       attrns, attr = qattr
  
-       # Make sure the attribute we are looking at is a valid attribute
-       if not baseAttrs.has_key(attr):
-         raise MarkupError, 'Error processing <%s> tag [I do not recognize the 
"%s" attribute' % (name, attr)
- 
-       # Typecasting, anyone?  If attribute should be int, make it an int
        try:
!         attrs[attr] = 
default(baseAttrs[attr],'Typecast',char)(saxattrs[qattr])
!         loadedxmlattrs[attr] = attrs[attr]
!       except:
!         raise MarkupError, 'Error processing <%s> tag [invalid type for "%s" 
attribute; value is "%s"]' % (name, attr, saxattrs[qattr])
! 
!       # If this attribute must be unique, check for duplicates
!       if default (baseAttrs[attr],'Unique',0):
!         if self.uniqueIDs.has_key('%s' % (saxattrs[qattr])):
!           raise MarkupError, 'Error processing <%s> tag ["%s" attribute 
should be unique; duplicate value is "%s"]' % (name, attr, saxattrs[qattr])
! 
!     for attr in baseAttrs.keys():
!       if not attrs.has_key(attr):
! 
!         # Pull default values for missing attributes
!         if baseAttrs[attr].has_key ('Default'):
!           attrs[attr] = default(baseAttrs[attr],'Typecast', char) 
(baseAttrs[attr]['Default'])
! 
!         # Check for missing required attributes
!         elif default(baseAttrs[attr], 'Required', 0):
!           raise MarkupError, 'Error processing <%s> tag [required attribute 
"%s" not present]' % (name, attr)
! 
! 
!     if self.bootstrapflag:
!       if self.xmlStack[0] != None:
!         object = self.xmlElements[name]['BaseClass'](self.xmlStack[0])
      else:
!       object = self.xmlElements[name]['BaseClass']()
!       self.root = object
!       self.bootstrapflag = 1
  
-     object._xmltag = name
  
      # Save the attributes loaded from XML file
      # (i.e., attributes that were not defaulted)
--- 196,278 ----
    #
    def startElementNS(self, qtag, qname, saxattrs):
      ns, name = qtag
      attrs = {}
      loadedxmlattrs = {}
  
!     if not ns:
!       #
!       # No namespace qualifier
!       #
!       GDebug.printMesg(50, "<%s>" % name)
  
        try:
!         baseAttrs = default(self.xmlElements[name],'Attributes',{})
!       except KeyError:
!         raise MarkupError, 'Error processing <%s> tag [I do not know what a 
<%s> tag does]' % (name, name)
! 
! 
!       for qattr in saxattrs.keys():
!         attrns, attr = qattr
! 
! 
!         # Typecasting, anyone?  If attribute should be int, make it an int
!         try:
!           attrs[attr] = 
default(baseAttrs[attr],'Typecast',char)(saxattrs[qattr])
!           loadedxmlattrs[attr] = attrs[attr]
!         except KeyError:
!           raise MarkupError, 'Error processing <%s> tag [I do not recognize 
the "%s" attribute' % (name, attr)
!         except:
!           raise MarkupError, 'Error processing <%s> tag [invalid type for 
"%s" attribute; value is "%s"]' % (name, attr, saxattrs[qattr])
! 
!         # If this attribute must be unique, check for duplicates
!         if default (baseAttrs[attr],'Unique',0):
!           if self.uniqueIDs.has_key('%s' % (saxattrs[qattr])):
!             raise MarkupError, 'Error processing <%s> tag ["%s" attribute 
should be unique; duplicate value is "%s"]' % (name, attr, saxattrs[qattr])
! 
!       for attr in baseAttrs.keys():
!         if not attrs.has_key(attr):
! 
!           # Pull default values for missing attributes
!           if baseAttrs[attr].has_key ('Default'):
!             attrs[attr] = default(baseAttrs[attr],'Typecast', char) 
(baseAttrs[attr]['Default'])
! 
!           # Check for missing required attributes
!           elif default(baseAttrs[attr], 'Required', 0):
!             raise MarkupError, 'Error processing <%s> tag [required attribute 
"%s" not present]' % (name, attr)
! 
! 
!       if self.bootstrapflag:
!         if self.xmlStack[0] != None:
!           object = self.xmlElements[name]['BaseClass'](self.xmlStack[0])
!       else:
!         object = self.xmlElements[name]['BaseClass']()
!         self.root = object
!         self.bootstrapflag = 1
! 
!       object._xmltag = name
! 
!     elif self.xmlMasqueradeNamespaceElements:
!       #
!       # namespace qualifier and we are masquerading
!       #
!       for qattr in saxattrs.keys():
!         attrns, attr = qattr
! 
!         attrs[attr] = saxattrs[qattr]
!         loadedxmlattrs[attr] = saxattrs[qattr]
! 
!       object = self.xmlMasqueradeNamespaceElements(self.xmlStack[0])
!       object._xmltag = name
!       object._xmlnamespace = ns
!       object._listedAttributes = loadedxmlattrs.keys()
! 
      else:
!       #
!       # namespace qualifier and we are not masquerading
!       #
!       print "WARNING: Markup includes namespaces, but the current tool does 
not include namespace support!"
!       sys.exit()
  
  
      # Save the attributes loaded from XML file
      # (i.e., attributes that were not defaulted)
***************
*** 266,273 ****
  
      if self.xmlStack[0] != None:
  
        # Should we keep the text?
!       if default(self.xmlElements[self.nameStack[0]],'MixedContent',0):
  
          if default(self.xmlElements[self.nameStack[0]],'KeepWhitespace',0):
            GContent(self.xmlStack[0], text)
--- 293,304 ----
  
      if self.xmlStack[0] != None:
  
+       # Masqueraging namespace elements, then keep content
+       if isinstance(self.xmlStack[0],self.xmlMasqueradeNamespaceElements):
+         GContent(self.xmlStack[0], text)
+ 
        # Should we keep the text?
!       elif default(self.xmlElements[self.nameStack[0]],'MixedContent',0):
  
          if default(self.xmlElements[self.nameStack[0]],'KeepWhitespace',0):
            GContent(self.xmlStack[0], text)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]