[Tutor] Re: Tutor Digest, Vol 5, Issue 39
Luiz Siqueira Neto
cybersamurai at terra.com.br
Fri Dec 12 06:49:19 EST 2003
I send to you my unfinished code, here you can see the idea more clear.
If you pay attention you see the dictionary implicit inside of module,
I use this to make a reference to the correct function declared on end of
the code.
The general idea of this algorithim is simulate a biological tree
growing, with this I can
map easyli some data in layout mode (like bits in memory) on a XML model
data.
-------------- next part --------------
################################################################################
# Internode and seed
################################################################################
# a set of functions to make a tree grow
################################################################################
"""
Author Luiz Siqueira Neto
"""
from xml.dom.ext.reader.Sax2 import FromXmlFile
from xml import xpath
import sys
self_module = sys.modules[__name__]
def seed(XMLmodel, fontFile):
"""
seed(XMLmodel_file_name, Font_file_name) -> XML DOM tree
a seed to start the new tree
"""
XMLmodel = FromXmlFile(XMLmodel)
self_module.tecniquie = xpath.Evaluate('/layout/tecniquie',
XMLmodel)[0].childNodes[0].nodeValue
internode( XMLmodel.documentElement, open(fontFile).read() )
return XMLmodel
class internode:
def __init__(self, node, data):
"""
x.__init__(XML_node, font_string_data)
start the growth of the current node if needed.
"""
for child in node.childNodes:
self.data_list = getattr(self_module,
'load_' + node.nodeName)(child, data)
for data_part in self.data_list:
i = 1 + node.childNodes.index(child)
node.childNodes.insert( i, child.cloneNode(True) )
if child.nodeName == u'celula':
if not child.getAttribute('key'):
child.childNodes[0]._set_nodeValue(data_part)
else internode(node.childNodes[i], data_part)
def load_layout(node, data):
"""
load and separe all groups in a list
"""
groups = None
if self_module.tecniquie == u'layout':
startFlag = node.getAttribute('startFlag')
groups = map( lambda x: startFlag + x, data.split('\x00\n' + startFlag) )
return groups
def load_group(node, data):
"""
load and separe all dataSets in a list
"""
def load_dataSet(node, data):
"""
load and separe all celulas in a list
"""
More information about the Tutor
mailing list