MCPcopy Create free account
hub / github.com/s3tools/s3cmd / object_batch_delete_uri_strs

Method object_batch_delete_uri_strs

S3/S3.py:860–889  ·  view source on GitHub ↗

Batch delete given a list of object uris

(self, uris)

Source from the content-addressed store, hash-verified

858 return self.object_batch_delete_uri_strs(uris)
859
860 def object_batch_delete_uri_strs(self, uris):
861 """ Batch delete given a list of object uris """
862 def compose_batch_del_xml(bucket, key_list):
863 body = u"<?xml version=\"1.0\" encoding=\"UTF-8\"?><Delete>"
864 for key in key_list:
865 uri = S3Uri(key)
866 if uri.type != "s3":
867 raise ValueError("Expected URI type 's3', got '%s'" % uri.type)
868 if not uri.has_object():
869 raise ValueError("URI '%s' has no object" % key)
870 if uri.bucket() != bucket:
871 raise ValueError("The batch should contain keys from the same bucket")
872 object = saxutils.escape(uri.object())
873 body += u"<Object><Key>%s</Key></Object>" % object
874 body += u"</Delete>"
875 body = encode_to_s3(body)
876 return body
877
878 batch = uris
879 if len(batch) == 0:
880 raise ValueError("Key list is empty")
881 bucket = S3Uri(batch[0]).bucket()
882 request_body = compose_batch_del_xml(bucket, batch)
883 headers = SortedDict({'content-md5': generate_content_md5(request_body),
884 'content-type': 'application/xml'}, ignore_case=True)
885 request = self.create_request("BATCH_DELETE", bucket = bucket,
886 headers = headers, body = request_body,
887 uri_params = {'delete': None})
888 response = self.send_request(request)
889 return response
890
891 def object_delete(self, uri):
892 if uri.type != "s3":

Callers 1

object_batch_deleteMethod · 0.95

Calls 6

create_requestMethod · 0.95
send_requestMethod · 0.95
S3UriClass · 0.90
SortedDictClass · 0.90
generate_content_md5Function · 0.85
bucketMethod · 0.80

Tested by

no test coverage detected