Nektar++
Public Member Functions | Public Attributes | List of all members
CellMLToNektar.pycml.element_base Class Reference
Inheritance diagram for CellMLToNektar.pycml.element_base:
[legend]

Public Member Functions

def __init__ (self)
 
def __delattr__ (self, key)
 
def __setattr__ (self, key, value)
 
def rootNode (self)
 
def cmeta_id (self)
 
def xml_remove_child_at (self, index=-1)
 
def xml_doc (self)
 
def xml_properties (self)
 

Public Attributes

 xml_attributes
 

Detailed Description

Base element class to allow me to set certain attributes on my instances
that are Python objects rather than unicode strings.

Definition at line 207 of file pycml.py.

Constructor & Destructor Documentation

◆ __init__()

def CellMLToNektar.pycml.element_base.__init__ (   self)

Member Function Documentation

◆ __delattr__()

def CellMLToNektar.pycml.element_base.__delattr__ (   self,
  key 
)
Bypass Amara's __delattr__ for attribute names that start with _cml_

Definition at line 216 of file pycml.py.

216 def __delattr__(self, key):
217 """
218 Bypass Amara's __delattr__ for attribute names that start with _cml_
219 """
220 if key.startswith('_cml_'):
221 del self.__dict__[key]
222 else:
223 amara.bindery.element_base.__delattr__(self, key)
224

◆ __setattr__()

def CellMLToNektar.pycml.element_base.__setattr__ (   self,
  key,
  value 
)
Bypass Amara's __setattr__ for attribute names that start with _cml_

Definition at line 225 of file pycml.py.

225 def __setattr__(self, key, value):
226 """
227 Bypass Amara's __setattr__ for attribute names that start with _cml_
228 """
229 if key.startswith('_cml_'):
230 self.__dict__[key] = value
231 else:
232 amara.bindery.element_base.__setattr__(self, key, value)
233

◆ cmeta_id()

def CellMLToNektar.pycml.element_base.cmeta_id (   self)
Get the value of the cmeta:id attribute, or the empty string if not set.

Definition at line 244 of file pycml.py.

244 def cmeta_id(self):
245 """Get the value of the cmeta:id attribute, or the empty string if not set."""
246 return self.getAttributeNS(NSS['cmeta'], u'id')
247

Referenced by CellMLToNektar.pycml.cellml_variable.add_rdf_annotation(), CellMLToNektar.pycml.cellml_variable.get_rdf_annotation(), CellMLToNektar.pycml.cellml_variable.get_rdf_annotations(), CellMLToNektar.pycml.cellml_model.is_self_excitatory(), and CellMLToNektar.pycml.cellml_variable.remove_rdf_annotations().

◆ rootNode()

def CellMLToNektar.pycml.element_base.rootNode (   self)

Definition at line 235 of file pycml.py.

235 def rootNode(self):
236 p = self.parentNode
237 if p:
238 return p.rootNode
239 elif isinstance(self, mathml):
240 raise ValueError('MathML element with no parent!')
241 return self
242

Referenced by CellMLToNektar.pycml.mathml_ci._reduce(), CellMLToNektar.pycml.mathml_constructor._tree_complexity(), CellMLToNektar.pycml.mathml.model(), CellMLToNektar.pycml.mathml_piecewise.tree_complexity(), and CellMLToNektar.pycml.cellml_model.validate().

◆ xml_doc()

def CellMLToNektar.pycml.element_base.xml_doc (   self)

Definition at line 275 of file pycml.py.

275 def xml_doc(self):
276 msg = []
277 xml_attrs = []
278 if hasattr(self, 'xml_attributes'):
279 msg.append('Object references based on XML attributes:')
280 for apyname in self.xml_attributes:
281 local, ns = self.xml_attributes[apyname]
282 if ns:
283 source_phrase = " based on '{%s}%s' in XML"%(ns, local)
284 else:
285 source_phrase = " based on '%s' in XML"%(local)
286 msg.append(apyname+source_phrase)
287 xml_attrs.append(apyname)
288 msg.append('Object references based on XML child elements:')
289 for attr, val in self.__dict__.items():
290 if not (attr.startswith('xml') or
291 attr.startswith('_cml_') or
292 attr in self.xml_ignore_members):
293 if attr not in xml_attrs:
294 count = len(list(getattr(self, attr)))
295 if count == 1:
296 count_phrase = " (%s element)"%count
297 else:
298 count_phrase = " (%s elements)"%count
299 local, ns = val.localName, val.namespaceURI
300 if ns:
301 source_phrase = " based on '{%s}%s' in XML"%(ns, local)
302 else:
303 source_phrase = " based on '%s' in XML"%(local)
304 msg.append(attr+count_phrase+source_phrase)
305 return u'\n'.join(msg)
306

References CellMLToNektar.pycml.element_base.xml_attributes.

◆ xml_properties()

def CellMLToNektar.pycml.element_base.xml_properties (   self)
Return a dictionary whose keys are Python properties on this
object that represent XML attributes and elements, and whose vaues
are the corresponding objects (a subset of __dict__)

Definition at line 308 of file pycml.py.

308 def xml_properties(self):
309 """
310 Return a dictionary whose keys are Python properties on this
311 object that represent XML attributes and elements, and whose vaues
312 are the corresponding objects (a subset of __dict__)
313 """
314 properties = {}
315 for attr in self.__dict__:
316 if (not (attr.startswith('xml')
317 or attr.startswith('_cml_')
318 or attr in self.xml_ignore_members)):
319 properties[attr] = self.__dict__[attr]
320 return properties
321
322# Add some improved/new methods to all bindings

◆ xml_remove_child_at()

def CellMLToNektar.pycml.element_base.xml_remove_child_at (   self,
  index = -1 
)
Remove child object at a given index
index - optional, 0-based index of child to remove (defaults to the last child)

Definition at line 248 of file pycml.py.

248 def xml_remove_child_at(self, index=-1):
249 """
250 Remove child object at a given index
251 index - optional, 0-based index of child to remove (defaults to the last child)
252 """
253 obj = self.xml_children[index]
254 if isinstance(obj, unicode):
255 del self.xml_children[index]
256 else:
257 # Remove references to the object
258 # Probably a slow way to go about this
259 for attr, val in self.__dict__.items():
260 if not (attr.startswith('xml') or
261 attr.startswith('_cml_') or
262 attr in self.xml_ignore_members):
263 next = getattr(val, 'next_elem', None)
264 if val == obj:
265 del self.__dict__[attr]
266 if next: self.__dict__[attr] = next
267 while next:
268 prev, val = val, next
269 next = getattr(val, 'next_elem', None)
270 if val == obj:
271 prev.next_elem = next
272 break
273 del self.xml_children[index]
274

Member Data Documentation

◆ xml_attributes

CellMLToNektar.pycml.element_base.xml_attributes