Author: tomaz
Date: Thu Apr 7 11:32:33 2011
New Revision: 1089830
URL: http://svn.apache.org/viewvc?rev=1089830&view=rev
Log:
Move xml utility functions into libcloud.utils
Modified:
incubator/libcloud/trunk/libcloud/utils.py
Modified: incubator/libcloud/trunk/libcloud/utils.py
URL:
http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/utils.py?rev=1089830&r1=1089829&r2=1089830&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/utils.py (original)
+++ incubator/libcloud/trunk/libcloud/utils.py Thu Apr 7 11:32:33 2011
@@ -162,6 +162,20 @@ def dict2str(data):
result += '%s\n' % str(k)
return result
+
+def fixxpath(xpath, namespace):
+ # ElementTree wants namespaces in its xpaths, so here we add them.
+ return '/'.join(['{%s}%s' % (namespace, e) for e in xpath.split('/')])
+
+def findtext(element, xpath, namespace):
+ return element.findtext(fixxpath(xpath=xpath, namespace=namespace))
+
+def findattr(self, element, xpath, namespace):
+ return element.findtext(fixxpath(xpath=xpath, namespace=namespace))
+
+def findall(self, element, xpath, namespace):
+ return element.findall(fixxpath(xpath=xpath, namespace=namespace))
+
def get_driver(drivers, provider):
"""
Get a driver.