[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/common/src GObjects.py GParserHelpers.py
From: |
Jason Cater |
Subject: |
gnue/common/src GObjects.py GParserHelpers.py |
Date: |
Thu, 09 Jan 2003 20:30:52 -0500 |
CVSROOT: /cvsroot/gnue
Module name: gnue
Changes by: Jason Cater <address@hidden> 03/01/09 20:30:52
Modified files:
common/src : GObjects.py GParserHelpers.py
Log message:
* Cleaned up some init routines
* Added a multiplexing GObj
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/GObjects.py.diff?tr1=1.51&tr2=1.52&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/GParserHelpers.py.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
Patches:
Index: gnue/common/src/GObjects.py
diff -c gnue/common/src/GObjects.py:1.51 gnue/common/src/GObjects.py:1.52
*** gnue/common/src/GObjects.py:1.51 Wed Jan 1 19:45:41 2003
--- gnue/common/src/GObjects.py Thu Jan 9 20:30:52 2003
***************
*** 32,60 ****
import GDebug
import string
import types
! from GParserHelpers import GContent
import GTypecast
from GTriggerCore import GTriggerCore
#
# Class GObj
#
! # Base class for GNUe objects which can be represented as XML
#
! class GObj(GTriggerCore):
! def __init__(self, parent=None, type='GObj'):
GTriggerCore.__init__(self)
! self._type = type
! self._parent = parent # The object that contains this object
! self._children = [] # The objects contained by this object
! self._attributes = {}
! self._inits = [] # functions called during phaseInit stage
! self._xmlnamespace = None # If the object is namespace-qualified, the
namespace
! self._xmlnamespaces = {} # If attributes are namespace-qualified, a map
! if parent :
! parent.addChild(self)
!
# This is a convenience function for applications
# NOT using GParser to load an object tree.
def buildObject(self, **params):
--- 32,53 ----
import GDebug
import string
import types
! from GParserHelpers import GContent, ParserObj
import GTypecast
from GTriggerCore import GTriggerCore
#
# Class GObj
#
! # Base class for GNUe objects which
! # can be represented by XML tags
#
! class GObj(GTriggerCore, ParserObj):
! def __init__(self, *args, **parms):
GTriggerCore.__init__(self)
! ParserObj.__init__(self, *args, **parms)
+
# This is a convenience function for applications
# NOT using GParser to load an object tree.
def buildObject(self, **params):
***************
*** 84,90 ****
## TODO: Below is a call-less recursive version of
## TODO: phaseInit. Needs to be profiled both ways.
- ## object = self
## stack = [self]
## while stack:
## object = stack.pop()
--- 77,82 ----
***************
*** 93,110 ****
## try:
## init = object._inits[phase]
## except IndexError:
! ## init = None
! ## if init:
! ## init()
! if (len(self._inits) > phase) and self._inits[phase]:
GDebug.printMesg(6,"%s: Init Phase %s" % (self._type, phase+1))
! self._inits[phase]()
for child in self._children:
! if isinstance(child, GObj):
! child._phaseInit(phase)
# This function is called after the parsers have completely
# constructed. All children should be in place and
# attributes and content should be set at this point.
--- 85,106 ----
## try:
## init = object._inits[phase]
## except IndexError:
! ## continue
! ## init()
! inits = self._inits
! if (len(inits) > phase) and inits[phase]:
GDebug.printMesg(6,"%s: Init Phase %s" % (self._type, phase+1))
! inits[phase]()
for child in self._children:
! try:
! initter = child._phaseInit
! except AttributeError:
! continue
! initter(phase)
+
# This function is called after the parsers have completely
# constructed. All children should be in place and
# attributes and content should be set at this point.
***************
*** 384,386 ****
--- 380,423 ----
def _setItemHook(self, key, value):
self.__dict__[key] = value
+
+ #
+ # ParserMultiplexor
+ #
+ # When a GParser's BaseClass needs to be dependent upon
+ # an attribute, the tool can use a customized ParserMultiplexor,
+ # overwriting the getClass method.
+ #
+ # e.g., assume we have an xml tag 'goblin', that
+ # corresponds to a GObj-based class Goblin. However,
+ # if <goblin style="boo"> we really need a BooGoblin
+ # object or if <goblin style="foo"> then we need a
+ # FooBoblin object, then the a GoblinPlexor would
+ # define getClass as:
+ #
+ # def getClass(self):
+ # if self.style == 'boo':
+ # return BooGoblin
+ # elif self.style == 'foo':
+ # return FooGoblin
+ # else:
+ # return Goblin
+ #
+ class ParserMultiplexor(ParserObj):
+
+ def _buildObject(self):
+ newObj = self.getClass()(None)
+ for attr, value in self.__dict__.items():
+ if attr not in ('_buildObject','getClass') and attr[:2] != '__':
+ newObj.__dict__[attr] = value
+
+ if self._parent:
+ self._parent._children[self._parent._children.find(self)] = newObj
+ return newObj._buildObject(self)
+
+
+ # This should return a GObj-based class
+ def getClass(self):
+ raise "Virtual method not implemented"
+
+
\ No newline at end of file
Index: gnue/common/src/GParserHelpers.py
diff -c gnue/common/src/GParserHelpers.py:1.6
gnue/common/src/GParserHelpers.py:1.7
*** gnue/common/src/GParserHelpers.py:1.6 Wed Jan 1 19:45:41 2003
--- gnue/common/src/GParserHelpers.py Thu Jan 9 20:30:52 2003
***************
*** 32,57 ****
from xml.sax import saxutils
#
# Class GContent
#
# Base class for xml content
#
! class GContent:
def __init__(self, parent, content):
self._content = content
- self._type = "_content_"
- if parent :
- parent.addChild(self)
def getEscapedContent(self):
return saxutils.escape(self._content)
def getContent(self):
return self._content
-
- def toXML(self):
- return saxutils.escape(self._content)
def dumpXML(self, lookupDict, treeDump=None, gap=None,
escape=1, xmlnamespaces={}):
--- 32,70 ----
from xml.sax import saxutils
#
+ # Class ParserObj
+ #
+ # Common initialization for GParser objects
+ #
+ class ParserObj:
+ def __init__(self, parent=None, type='_NotSet_'):
+ self._type = type
+ self._parent = parent # The object that contains this object
+ self._children = [] # The objects contained by this object
+ self._attributes = {}
+ self._inits = [] # functions called during phaseInit stage
+ self._xmlnamespace = None # If the object is namespace-qualified, the
namespace
+ self._xmlnamespaces = {} # If attributes are namespace-qualified, a map
+ if parent :
+ parent.addChild(self)
+
+
+ #
# Class GContent
#
# Base class for xml content
#
! class GContent(ParserObj):
def __init__(self, parent, content):
+ ParserObj.__init__(self, parent, '_content_')
self._content = content
def getEscapedContent(self):
return saxutils.escape(self._content)
def getContent(self):
return self._content
def dumpXML(self, lookupDict, treeDump=None, gap=None,
escape=1, xmlnamespaces={}):
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gnue/common/src GObjects.py GParserHelpers.py,
Jason Cater <=