return xpath
@staticmethod
- def xpath(filter={}):
+ def xpath(filter=None):
+ if filter is None: filter={}
xpath = ""
if filter:
filter_list = []
def getparent(self):
return XmlElement(self.element.getparent(), self.namespaces)
- def get_instance(self, instance_class=None, fields=[]):
+ def get_instance(self, instance_class=None, fields=None):
"""
Returns an instance (dict) of this xml element. The instance
holds a reference to this xml element.
"""
+ if fields is None: fields=[]
if not instance_class:
instance_class = Element
if not fields and hasattr(instance_class, 'fields'):
instance[field] = self.attrib[field]
return instance
- def add_instance(self, name, instance, fields=[]):
+ def add_instance(self, name, instance, fields=None):
"""
Adds the specifed instance(s) as a child element of this xml
element.
"""
+ if fields is None: fields=[]
if not fields and hasattr(instance, 'keys'):
fields = instance.keys()
elem = self.add_element(name)
# are redirected on self.element
def __getattr__ (self, name):
if not hasattr(self.element, name):
- raise AttributeError, name
+ raise AttributeError(name)
return getattr(self.element, name)
class XML:
# 'rspec' file doesnt exist. 'rspec' is proably an xml string
try:
tree = etree.parse(StringIO(xml), parser)
- except Exception, e:
+ except Exception as e:
raise InvalidXML(str(e))
root = tree.getroot()
self.namespaces = dict(root.nsmap)