Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor XML handling of _complete_multipart_upload() API #994

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions minio/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@
from .sse import SseCustomerKey
from .thread_pool import ThreadPool
from .versioningconfig import VersioningConfig
from .xml import Element, SubElement, findtext, marshal, unmarshal
from .xml import Element, SubElement, findtext, getbytes, marshal, unmarshal
from .xml_marshal import (marshal_bucket_notifications,
marshal_complete_multipart,
xml_marshal_bucket_encryption,
xml_marshal_delete_objects, xml_to_dict)

Expand Down Expand Up @@ -1164,7 +1163,12 @@ def _complete_multipart_upload(
self, bucket_name, object_name, upload_id, parts,
):
"""Execute CompleteMultipartUpload S3 API."""
body = marshal_complete_multipart(parts)
element = Element("CompleteMultipartUpload")
for part in parts:
tag = SubElement(element, "Part")
SubElement(tag, "PartNumber", str(part.part_number))
SubElement(tag, "ETag", '"' + part.etag + '"')
body = getbytes(element)
response = self._execute(
"POST",
bucket_name,
Expand Down
11 changes: 8 additions & 3 deletions minio/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,15 @@ def unmarshal(cls, xmlstring):
return cls.fromxml(ET.fromstring(xmlstring))


def marshal(obj):
"""Get XML data as bytes of ElementTree.Element."""
def getbytes(element):
"""Convert ElementTree.Element to bytes."""
data = io.BytesIO()
ET.ElementTree(obj.toxml(None)).write(
ET.ElementTree(element).write(
data, encoding=None, xml_declaration=False,
)
return data.getvalue()


def marshal(obj):
"""Get XML data as bytes of ElementTree.Element."""
return getbytes(obj.toxml(None))
16 changes: 0 additions & 16 deletions minio/xml_marshal.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,6 @@ def xml_marshal_bucket_encryption(rules):
return _get_xml_data(root)


def marshal_complete_multipart(uploaded_parts):
"""
Marshal's complete multipart upload request based on *uploaded_parts*.

:param uploaded_parts: List of all uploaded parts, ordered by part number.
:return: Marshalled XML data.
"""
root = Element('CompleteMultipartUpload', with_namespace=True)
for uploaded_part in uploaded_parts:
part = SubElement(root, 'Part')
SubElement(part, 'PartNumber', str(uploaded_part.part_number))
SubElement(part, 'ETag', '"' + uploaded_part.etag + '"')

return _get_xml_data(root)


def marshal_bucket_notifications(notifications):
"""
Marshals the notifications structure for sending to S3 compatible storage
Expand Down
46 changes: 0 additions & 46 deletions tests/unit/generate_xml_test.py

This file was deleted.