Browse code

* S3/Utils.py: Fix crash in stripNameSpace() when the XML has no NS.

git-svn-id: https://s3tools.svn.sourceforge.net/svnroot/s3tools/s3cmd/trunk@329 830e0280-6d2a-0410-9c65-932aecc39d9d

Michal Ludvig authored on 2009/01/06 22:13:03
Showing 2 changed files
... ...
@@ -1,6 +1,7 @@
1 1
 2009-01-07  Michal Ludvig  <michal@logix.cz>
2 2
 
3 3
 	* S3/ACL.py: Keep ACL internally as a list of of 'Grantee' objects.
4
+	* S3/Utils.py: Fix crash in stripNameSpace() when the XML has no NS.
4 5
 
5 6
 2009-01-07  Michal Ludvig  <michal@logix.cz>
6 7
 
... ...
@@ -39,24 +39,23 @@ def parseNodes(nodes):
39 39
 		retval.append(retval_item)
40 40
 	return retval
41 41
 
42
-def getNameSpace(element):
43
-	if not element.tag.startswith("{"):
44
-		return ""
45
-	return re.compile("^(\{[^}]+\})").match(element.tag).groups()[0]
46
-
47 42
 def stripNameSpace(xml):
48 43
 	"""
49 44
 	removeNameSpace(xml) -- remove top-level AWS namespace
50 45
 	"""
51 46
 	r = re.compile('^(<?[^>]+?>\s?)(<\w+) xmlns=[\'"](http://[^\'"]+)[\'"](.*)', re.MULTILINE)
52
-	xmlns = r.match(xml).groups()[2]
53
-	xml = r.sub("\\1\\2\\4", xml)
47
+	if r.match(xml):
48
+		xmlns = r.match(xml).groups()[2]
49
+		xml = r.sub("\\1\\2\\4", xml)
50
+	else:
51
+		xmlns = None
54 52
 	return xml, xmlns
55 53
 
56 54
 def getTreeFromXml(xml):
57 55
 	xml, xmlns = stripNameSpace(xml)
58 56
 	tree = ET.fromstring(xml)
59
-	tree.attrib['xmlns'] = xmlns
57
+	if xmlns:
58
+		tree.attrib['xmlns'] = xmlns
60 59
 	return tree
61 60
 	
62 61
 def getListFromXml(xml, node):