Skip to content

Commit

Permalink
Fixes #929 - strip namespace well even without xml declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
fviard committed Nov 5, 2017
1 parent 3eb5a52 commit 6d8e621
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 3 additions & 1 deletion S3/S3.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,9 @@ def object_move(self, src_uri, dst_uri, extra_headers = None):
debug("Object %s copied to %s" % (src_uri, dst_uri))
if not response_copy["data"] or getRootTagName(response_copy["data"]) == "CopyObjectResult":
self.object_delete(src_uri)
debug("Object %s deleted" % src_uri)
debug("Object '%s' deleted", src_uri)
else:
debug("Object '%s' NOT deleted because of an unexepected response data content.", src_uri)
return response_copy

def object_info(self, uri):
Expand Down
13 changes: 8 additions & 5 deletions S3/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,17 @@ def getPrettyFromXml(xmlstr):

__all__.append("getPrettyFromXml")

RE_XML_NAMESPACE = re.compile(b'^(<?[^>]+?>\s*|\s*)(<\w+) xmlns=[\'"](http://[^\'"]+)[\'"]', re.MULTILINE)

def stripNameSpace(xml):
"""
removeNameSpace(xml) -- remove top-level AWS namespace
Operate on raw byte(utf-8) xml string. (Not unicode)
"""
r = re.compile(b'^(<?[^>]+?>\s*)(<\w+) xmlns=[\'"](http://[^\'"]+)[\'"](.*)', re.MULTILINE)
if r.match(xml):
xmlns = r.match(xml).groups()[2]
xml = r.sub("\\1\\2\\4", xml)
xmlns_match = RE_XML_NAMESPACE.match(xml)
if xmlns_match:
xmlns = xmlns_match.group(3)
xml = RE_XML_NAMESPACE.sub("\\1\\2", xml, 1)
else:
xmlns = None
return xml, xmlns
Expand Down Expand Up @@ -169,9 +170,11 @@ def appendXmlTextNode(tag_name, text, parent):
return el
__all__.append("appendXmlTextNode")

RE_S3_DATESTRING = re.compile('\.[0-9]*(?:[Z\\-\\+]*?)')

def dateS3toPython(date):
# Reset milliseconds to 000
date = re.compile('\.[0-9]*(?:[Z\\-\\+]*?)').sub(".000", date)
date = RE_S3_DATESTRING.sub(".000", date)
return dateutil.parser.parse(date, fuzzy=True)
__all__.append("dateS3toPython")

Expand Down

0 comments on commit 6d8e621

Please sign in to comment.