Esempio n. 1
0
 def _fromXMLElement(cls, xmlElement):
     network = cls()
     
     network.setBulkLoading(True)
     
     # Load the classes in such an order that any referenced objects are guaranteed to have already been created.
     for moduleName, className in [('region', 'Region'), ('pathway', 'Pathway'), ('neuron', 'Neuron'), ('muscle', 'Muscle'), ('arborization', 'Arborization'), ('innervation', 'Innervation'), ('gap_junction', 'GapJunction'), ('synapse', 'Synapse'), ('stimulus', 'Stimulus')]:
         elementModule = getattr(sys.modules['network'], moduleName)
         elementClass = getattr(elementModule, className)
         for element in xmlElement.findall(className):
             networkObject = elementClass._fromXMLElement(network, element)
             if networkObject is not None:
                 network.addObject(networkObject)
     
     weightingFunctionElement = xmlElement.find('WeightingFunction')
     if weightingFunctionElement is not None:
         funcType = weightingFunctionElement.get('type')
         funcName = weightingFunctionElement.get('name')
         if funcType == 'source':
             exec(weightingFunctionElement.text)
             network._weightingFunction = eval(funcName)
         elif funcType == 'marshal':
             code = marshal.loads(eval(weightingFunctionElement.text))
             network._weightingFunction = types.FunctionType(code, globals(), funcName or 'weightingFunction')
         else:
             raise ValueError, gettext('Unknown weighting function type: %s') % (funcType)
     
     for element in xmlElement.findall('Attribute'):
         attribute = Attribute._fromXMLElement(network, element)
         if attribute is not None:
             network._attributes.append(attribute)
     
     network.setBulkLoading(False)
     
     return network
Esempio n. 2
0
 def _fromXMLElement(cls, network, xmlElement):
     networkObject = super(Object, cls).__new__(cls)
     networkObject.network = network
     networkObject.networkId = int(xmlElement.get('id'))
     
     networkObject.name = xmlElement.findtext('Name')
     if networkObject.name is None:
         networkObject.name = xmlElement.findtext('name')
     networkObject.abbreviation = xmlElement.findtext('Abbreviation')
     if networkObject.abbreviation is None:
         networkObject.abbreviation = xmlElement.findtext('abbreviation')
     networkObject.description = xmlElement.findtext('Description')
     if networkObject.description is None:
         networkObject.description = xmlElement.findtext('description')
     
     networkObject._attributes = []
     for element in xmlElement.findall('Attribute'):
         attribute = Attribute._fromXMLElement(networkObject, element)
         if attribute is not None:
             networkObject._attributes.append(attribute)
     
     # TODO: handle links
     # TODO: handle notes
     return networkObject