split api and driver
[sfa.git] / sfa / rspecs / elements / element.py
index 495ff3e..401ca31 100644 (file)
@@ -10,7 +10,7 @@ class Element:
 
     def add_element(self, name, attrs={}, parent=None, text=""):
         """
-        Generic wrapper around etree.SubElement(). Adds an element to
+        Wrapper around etree.SubElement(). Adds an element to
         specified parent node. Adds element to root node is parent is
         not specified.
         """
@@ -59,15 +59,18 @@ class Element:
                     if opt.text == value:
                         elem.remove(opt)
 
-    def get_attributes(self, elem=None, recursive=False):
+    def get_attributes(self, elem=None, depth=None):
         if elem == None:
             elem = self.root_node
         attrs = dict(elem.attrib)
         attrs['text'] = str(elem.text).strip()
-        if recursive:
+        if depth is None or isinstance(depth, int) and depth > 0: 
             for child_elem in list(elem):
-                attrs[str(child_elem.tag)] = self.get_attributes(child_elem, recursive)
-             
+                key = str(child_elem.tag)
+                if key not in attrs:
+                    attrs[key] = [self.get_attributes(child_elem, recursive)]
+                else:
+                    attrs[key].append(self.get_attributes(child_elem, recursive))
         return attrs
     
     def attributes_list(self, elem):