trimmed useless imports, unstarred all imports
[sfa.git] / sfa / util / xml.py
index 91a1d95..a1a6fa3 100755 (executable)
@@ -1,10 +1,8 @@
 #!/usr/bin/python 
 from lxml import etree
 from StringIO import StringIO
-from datetime import datetime, timedelta
-from sfa.util.xrn import *
-from sfa.util.plxrn import hostname_to_urn
-from sfa.util.faults import SfaNotImplemented, InvalidXML
+
+from sfa.util.faults import InvalidXML
 
 class XpathFilter:
     @staticmethod
@@ -56,6 +54,8 @@ class XML:
         self.root = tree.getroot()
         # set namespaces map
         self.namespaces = dict(self.root.nsmap)
+        if 'default' not in self.namespaces and None in self.namespaces: 
+            self.namespaces['default'] = self.namespaces[None]
         # If the 'None' exist, then it's pointing to the default namespace. This makes 
         # it hard for us to write xpath queries for the default naemspace because lxml 
         # wont understand a None prefix. We will just associate the default namespeace 
@@ -200,7 +200,7 @@ class XML:
         return self.toxml()
 
     def toxml(self):
-        return etree.tostring(self.root, pretty_print=True)  
+        return etree.tostring(self.root, encoding='UTF-8', pretty_print=True)  
     
     def todict(self, elem=None):
         if elem is None:
@@ -218,8 +218,9 @@ class XML:
         f = open(filename, 'w')
         f.write(self.toxml())
         f.close()
-if __name__ == '__main__':
-    rspec = RSpec('/tmp/resources.rspec')
-    print rspec
+
+# no RSpec in scope 
+#if __name__ == '__main__':
+#    rspec = RSpec('/tmp/resources.rspec')
+#    print rspec