Issue #424: https://github.com/s3tools/s3cmd/issues/424
Florent Viard authored on 2014/12/19 23:27:25... | ... |
@@ -11,8 +11,15 @@ import ExitCodes |
11 | 11 |
try: |
12 | 12 |
import xml.etree.ElementTree as ET |
13 | 13 |
except ImportError: |
14 |
+ # xml.etree.ElementTree was only added in python 2.5 |
|
14 | 15 |
import elementtree.ElementTree as ET |
15 | 16 |
|
17 |
+try: |
|
18 |
+ from xml.etree.ElementTree import ParseError as XmlParseError |
|
19 |
+except ImportError: |
|
20 |
+ # ParseError was only added in python2.7, before ET was raising ExpatError |
|
21 |
+ from xml.parsers.expat import ExpatError as XmlParseError |
|
22 |
+ |
|
16 | 23 |
class S3Exception(Exception): |
17 | 24 |
def __init__(self, message = ""): |
18 | 25 |
self.message = unicodise(message) |
... | ... |
@@ -49,7 +56,7 @@ class S3Error (S3Exception): |
49 | 49 |
if response.has_key("data") and response["data"]: |
50 | 50 |
try: |
51 | 51 |
tree = getTreeFromXml(response["data"]) |
52 |
- except ET.ParseError: |
|
52 |
+ except XmlParseError: |
|
53 | 53 |
debug("Not an XML response") |
54 | 54 |
else: |
55 | 55 |
self.info.update(self.parse_error_xml(tree)) |
... | ... |
@@ -47,8 +47,8 @@ else: |
47 | 47 |
try: |
48 | 48 |
import xml.etree.ElementTree as ET |
49 | 49 |
except ImportError: |
50 |
+ # xml.etree.ElementTree was only added in python 2.5 |
|
50 | 51 |
import elementtree.ElementTree as ET |
51 |
-from xml.parsers.expat import ExpatError |
|
52 | 52 |
|
53 | 53 |
__all__ = [] |
54 | 54 |
def parseNodes(nodes): |
... | ... |
@@ -88,11 +88,8 @@ def getTreeFromXml(xml): |
88 | 88 |
if xmlns: |
89 | 89 |
tree.attrib['xmlns'] = xmlns |
90 | 90 |
return tree |
91 |
- except ExpatError, e: |
|
92 |
- error(e) |
|
93 |
- raise Exceptions.ParameterError("Bucket contains invalid filenames. Please run: s3cmd fixbucket s3://your-bucket/") |
|
94 | 91 |
except Exception, e: |
95 |
- error(e) |
|
92 |
+ error("Error parsing xml: %s", e) |
|
96 | 93 |
error(xml) |
97 | 94 |
raise |
98 | 95 |
|