Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Public Member Functions | Public Attributes | List of all members
CellMLToNektar.pycml.element_base Class Reference
Inheritance diagram for CellMLToNektar.pycml.element_base:
Inheritance graph
[legend]
Collaboration diagram for CellMLToNektar.pycml.element_base:
Collaboration graph
[legend]

Public Member Functions

def __init__
 
def __delattr__
 
def __setattr__
 
def rootNode
 
def cmeta_id
 
def xml_remove_child_at
 
def xml_doc
 
def xml_properties
 

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

def CellMLToNektar.pycml.element_base.__init__ (   self)

Definition at line 212 of file pycml.py.

213  def __init__(self):
214  self.xml_attributes = {} # Amara should really do this!
215  super(element_base, self).__init__()

Member Function Documentation

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.

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

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

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().

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

Definition at line 235 of file pycml.py.

Referenced by CellMLToNektar.pycml.mathml_constructor._tree_complexity(), and CellMLToNektar.pycml.mathml_piecewise.tree_complexity().

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

Definition at line 275 of file pycml.py.

References CellMLToNektar.pycml.element_base.xml_attributes.

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

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

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

Member Data Documentation

CellMLToNektar.pycml.element_base.xml_attributes

Definition at line 213 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_model.xml(), and CellMLToNektar.pycml.element_base.xml_doc().