18 |
# |
# |
19 |
# Copyright 2000-2002 Free Software Foundation |
# Copyright 2000-2002 Free Software Foundation |
20 |
# |
# |
|
# |
|
21 |
# FILE: |
# FILE: |
22 |
# GObjects.py |
# GObjects.py |
23 |
# |
# |
28 |
# |
# |
29 |
import sys |
import sys |
30 |
|
|
31 |
try: |
from xml.sax import saxutils |
|
from xml.sax import saxutils |
|
|
except ImportError: |
|
|
print """ |
|
|
This GNUe tool requires PyXML to be installed. |
|
|
Please download and install PyXML from: |
|
|
|
|
|
http://pyxml.sourceforge.net/ |
|
|
|
|
|
""" |
|
|
sys.exit() |
|
|
|
|
32 |
import GDebug |
import GDebug |
33 |
import string |
import string |
34 |
import types |
import types |
60 |
self.__dict__.update(params) |
self.__dict__.update(params) |
61 |
return self._buildObject() |
return self._buildObject() |
62 |
|
|
63 |
|
|
64 |
# This is a convenience function for applications |
# This is a convenience function for applications |
65 |
# NOT using GParser to load an object tree. |
# NOT using GParser to load an object tree. |
66 |
def buildAndInitObject(self, **params): |
def buildAndInitObject(self, **params): |
67 |
self.phaseInit(self.buildObject(**params)) |
self.phaseInit(self.buildObject(**params)) |
68 |
|
|
69 |
|
|
70 |
|
def getParent(self): |
71 |
|
return self._parent |
72 |
|
|
73 |
# |
# |
74 |
# phaseInit |
# phaseInit |
78 |
self._phaseInit(phase) |
self._phaseInit(phase) |
79 |
|
|
80 |
def _phaseInit(self,phase): |
def _phaseInit(self,phase): |
81 |
|
|
82 |
|
## TODO: Below is a call-less recursive version of |
83 |
|
## TODO: phaseInit. Needs to be profiled both ways. |
84 |
|
## object = self |
85 |
|
## stack = [self] |
86 |
|
## while stack: |
87 |
|
## object = stack.pop() |
88 |
|
## for child in object._children: |
89 |
|
## stack.insert(0,child) |
90 |
|
## try: |
91 |
|
## init = object._inits[phase] |
92 |
|
## except IndexError: |
93 |
|
## init = None |
94 |
|
## if init: |
95 |
|
## init() |
96 |
|
|
97 |
if (len(self._inits) > phase) and self._inits[phase]: |
if (len(self._inits) > phase) and self._inits[phase]: |
98 |
GDebug.printMesg(6,"%s: Init Phase %s" % (self._type, phase+1)) |
GDebug.printMesg(6,"%s: Init Phase %s" % (self._type, phase+1)) |
99 |
self._inits[phase]() |
self._inits[phase]() |
214 |
typecast = lookupDict[xmlEntity]['Attributes'][attribute]['Typecast'] |
typecast = lookupDict[xmlEntity]['Attributes'][attribute]['Typecast'] |
215 |
except: |
except: |
216 |
typecast = GTypecast.text |
typecast = GTypecast.text |
217 |
if typecast == GTypecast.boolean \ |
if typecast == GTypecast.boolean: |
218 |
and val == 1: |
if val: |
219 |
addl = ' %s=""' % (attribute) |
addl = ' %s="Y"' % (attribute) |
220 |
|
else: |
221 |
|
addl = ' %s="N"' % (attribute) |
222 |
elif typecast == GTypecast.names: |
elif typecast == GTypecast.names: |
223 |
addl = ' %s="%s"' % \ |
addl = ' %s="%s"' % \ |
224 |
(attribute, string.join(val,',')) |
(attribute, string.join(val,',')) |
272 |
parentObject = self |
parentObject = self |
273 |
else: |
else: |
274 |
parentObject = self._parent |
parentObject = self._parent |
|
# |
|
|
# Replacing this code with code below decreased startup |
|
|
# function call time by approx 33% |
|
|
# |
|
|
# if parentObject is None: |
|
|
# return None |
|
|
# |
|
|
# while (parentObject._parent != None and parentObject._type != type): |
|
|
# parentObject = parentObject._parent |
|
|
# |
|
|
# if parentObject._type == type: |
|
|
# return parentObject |
|
|
# else: |
|
|
# return None |
|
275 |
|
|
276 |
while 1: |
while 1: |
277 |
if parentObject == None: |
if parentObject == None: |
279 |
elif parentObject._type == type: |
elif parentObject._type == type: |
280 |
return parentObject |
return parentObject |
281 |
|
|
282 |
|
# If passed a type of NONE it finds the top object in the tree |
283 |
|
if not type and not parentObject._parent: |
284 |
|
return parentObject |
285 |
|
|
286 |
parentObject = parentObject._parent |
parentObject = parentObject._parent |
287 |
|
|
288 |
|
# |
289 |
|
# findChildOfType |
290 |
|
# |
291 |
|
# Moves upward though the parents of an object till |
292 |
|
# it finds the parent of the specified type |
293 |
|
# |
294 |
|
def findChildOfType(self, type, includeSelf=1, allowAllChildren=1): |
295 |
|
|
296 |
|
if includeSelf and self._type == type: |
297 |
|
return self |
298 |
|
|
299 |
|
for child in self._children: |
300 |
|
if child._type == type: |
301 |
|
return child |
302 |
|
|
303 |
|
if allowAllChildren: |
304 |
|
for child in self._children: |
305 |
|
o = child.findChildOfType(type,0, 1) |
306 |
|
if o: |
307 |
|
return o |
308 |
|
|
309 |
|
return None |
310 |
|
|
311 |
|
|
312 |
# |
# |