forked from minio/minio-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deleteobjects.py
167 lines (134 loc) · 4.73 KB
/
deleteobjects.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# -*- coding: utf-8 -*-
# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C)
# 2020 MinIO, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Request/response of DeleteObjects API."""
from __future__ import absolute_import
from .xml import Element, SubElement, findall, findtext
class DeleteObject:
"""Delete object request information."""
def __init__(self, name, version_id=None):
self._name = name
self._version_id = version_id
def toxml(self, element):
"""Convert to XML."""
element = SubElement(element, "Object")
SubElement(element, "Key", self._name)
if self._version_id is not None:
SubElement(element, "VersionId", self._version_id)
return element
class DeleteRequest:
"""Delete object request."""
def __init__(self, object_list, quiet=False):
self._object_list = object_list
self._quiet = quiet
def toxml(self, element):
"""Convert to XML."""
element = Element("Delete")
if self._quiet:
SubElement(element, "Quiet", str(self._quiet))
for obj in self._object_list:
obj.toxml(element)
return element
class DeletedObject:
"""Deleted object information."""
def __init__(self, name, version_id, delete_marker,
delete_marker_version_id):
self._name = name
self._version_id = version_id
self._delete_marker = delete_marker
self._delete_marker_version_id = delete_marker_version_id
@property
def name(self):
"""Get name."""
return self._name
@property
def version_id(self):
"""Get version ID."""
return self._version_id
@property
def delete_marker(self):
"""Get delete marker."""
return self._delete_marker
@property
def delete_marker_version_id(self):
"""Get delete marker version ID."""
return self._delete_marker_version_id
@classmethod
def fromxml(cls, element):
"""Create new object with values from XML element."""
name = findtext(element, "Key", True)
version_id = findtext(element, "VersionId")
delete_marker = findtext(element, "DeleteMarker")
delete_marker = (
delete_marker is not None and delete_marker.title() == "True"
)
delete_marker_version_id = findtext(element, "DeleteMarkerVersionId")
return cls(name, version_id, delete_marker, delete_marker_version_id)
class DeleteError:
"""Delete error information."""
def __init__(self, code, message, name, version_id):
self._code = code
self._message = message
self._name = name
self._version_id = version_id
@property
def code(self):
"""Get error code."""
return self._code
@property
def message(self):
"""Get error message."""
return self._message
@property
def name(self):
"""Get name."""
return self._name
@property
def version_id(self):
"""Get version ID."""
return self._version_id
@classmethod
def fromxml(cls, element):
"""Create new object with values from XML element."""
code = findtext(element, "Code", True)
message = findtext(element, "Message")
name = findtext(element, "Key")
version_id = findtext(element, "VersionId")
return cls(code, message, name, version_id)
class DeleteResult:
"""Delete object result."""
def __init__(self, object_list, error_list):
self._object_list = object_list
self._error_list = error_list
@property
def object_list(self):
"""Get object list."""
return self._object_list
@property
def error_list(self):
"""Get error list."""
return self._error_list
@classmethod
def fromxml(cls, element):
"""Create new object with values from XML element."""
elements = findall(element, "Deleted")
object_list = []
for tag in elements:
object_list.append(DeletedObject.fromxml(tag))
elements = findall(element, "Error")
error_list = []
for tag in elements:
error_list.append(DeleteError.fromxml(tag))
return cls(object_list, error_list)