"""
system types
"""

from xnb_parse.file_formats.xml_utils import E


class XNAList(list):
    def xml(self, xml_tag='List', xml_entry='Entry'):
        root = E(xml_tag)
        for cur_value in self:
            if hasattr(cur_value, 'xml'):
                root.append(cur_value.xml())
            else:
                root.append(E(xml_entry, unicode(cur_value)))
        return root

    def export(self, _):
        return self.xml()


class XNADict(dict):
    def xml(self, xml_tag='Dict', xml_entry='Entry'):
        root = E(xml_tag)
        for cur_key, cur_value in self.items():
            if hasattr(cur_value, 'xml'):
                root.append(E(xml_entry, cur_value.xml(), key=unicode(cur_key)))
            else:
                root.append(E(xml_entry, unicode(cur_value), key=unicode(cur_key)))
        return root

    def export(self, _):
        return self.xml()

@@ -128,32 +128,45 @@
 ml_entry='Entry'
+, attrib=None
 ):%0A        root 
@@ -267,28 +267,26 @@
         
-root.append(
+cur_tag = 
 cur_valu
@@ -292,17 +292,16 @@
 ue.xml()
-)
 %0A       
@@ -311,72 +311,222 @@
   el
-se:%0A                root.append(E(xml_entry, unicode(cur_value))
+if attrib:%0A                cur_tag = E(xml_entry)%0A                cur_tag.set(attrib, unicode(cur_value))%0A            else:%0A                cur_tag = E(xml_entry, unicode(cur_value))%0A            root.append(cur_tag
 )%0A  
@@ -669,16 +669,29 @@
 ='Entry'
+, attrib=None
 ):%0A     
@@ -759,16 +759,51 @@
 tems():%0A
+            cur_tag = E(xml_entry)%0A
         
@@ -813,37 +813,35 @@
  if hasattr(cur_
-value
+key
 , 'xml'):%0A      
@@ -855,53 +855,99 @@
    r
-oot.append(E(xml_entry, cur_value.xml(), key=
+aise ValueError(%22XNADict key is xml%22)%0A            else:%0A                cur_tag.set('key', 
 unic
@@ -951,33 +951,32 @@
 nicode(cur_key))
-)
 %0A            els
@@ -964,36 +964,60 @@
 y))%0A            
-else
+if hasattr(cur_value, 'xml')
 :%0A              
@@ -1018,28 +1018,31 @@
         
-root
+cur_tag
 .append(
 E(xml_en
@@ -1037,62 +1037,205 @@
 end(
-E(xml_entry, unicode(cur_value), key=unicode(cur_key))
+cur_value.xml())%0A            elif attrib:%0A                cur_tag.set(attrib, unicode(cur_value))%0A            else:%0A                cur_tag.text = unicode(cur_value)%0A            root.append(cur_tag
 )%0A  

allow using attribute instead of text for entry in XNAList and XNADict xml output