1
# Copyright (C) 2009 Canonical Ltd
2
# Copyright (C) 2009 Duncan McGreggor <oubiwann@adytum.us>
3
# Copyright (C) 2011 Drew Smathers <drew.smathers@gmail.com>
4
# Copyright (C) 2012 New Dream Network (DreamHost)
5
# Licenced under the txaws licence available at /LICENSE in the txaws source.
6
from txaws.util import XML
11
An Amazon S3 storage bucket.
13
def __init__(self, name, creation_date):
15
self.creation_date = creation_date
18
class ItemOwner(object):
20
The owner of a content item.
22
def __init__(self, id, display_name):
24
self.display_name = display_name
27
class BucketItem(object):
29
The contents of an Amazon S3 bucket.
31
def __init__(self, key, modification_date, etag, size, storage_class,
34
self.modification_date = modification_date
37
self.storage_class = storage_class
41
class BucketListing(object):
43
A mapping for the data in a bucket listing.
45
def __init__(self, name, prefix, marker, max_keys, is_truncated,
46
contents=None, common_prefixes=None):
50
self.max_keys = max_keys
51
self.is_truncated = is_truncated
52
self.contents = contents
53
self.common_prefixes = common_prefixes
56
class LifecycleConfiguration(object):
58
Returns the lifecycle configuration information set on the bucket.
60
def __init__(self, rules):
64
class LifecycleConfigurationRule(object):
66
Container for elements that describe a lifecycle rule.
68
def __init__(self, id, prefix, status, expiration):
72
self.expiration = expiration
75
class WebsiteConfiguration(object):
77
A mapping for the data in a bucket website configuration.
79
def __init__(self, index_suffix, error_key=None):
80
self.index_suffix = index_suffix
81
self.error_key = error_key
84
class NotificationConfiguration(object):
86
A mapping for the data in a bucket notification configuration.
88
def __init__(self, topic=None, event=None):
93
class VersioningConfiguration(object):
95
Container for the bucket versioning configuration.
99
C{MfaDelete}: This element is only returned if the bucket has been
100
configured with C{MfaDelete}. If the bucket has never been so configured,
101
this element is not returned. The possible values are None, "Disabled" or
104
C{Status}: If the bucket has never been so configured, this element is not
105
returned. The possible values are None, "Suspended" or "Enabled".
107
def __init__(self, mfa_delete=None, status=None):
108
self.mfa_delete = mfa_delete
112
class FileChunk(object):
114
An Amazon S3 file chunk.
116
S3 returns file chunks, 10 MB at a time, until the entire file is returned.
117
These chunks need to be assembled once they are all returned.
121
class RequestPayment(object):
125
@param payer: One of 'Requester' or 'BucketOwner'.
128
payer_choices = ("Requester", "BucketOwner")
130
def __init__(self, payer):
131
if payer not in self.payer_choices:
132
raise ValueError("Invalid value for payer: `%s`. Must be one of "
133
"%s." % (payer, ",".join(self.payer_choices)))
138
Convert this request into a C{RequestPaymentConfiguration} XML
141
return ("<RequestPaymentConfiguration "
142
'xmlns="http://s3.amazonaws.com/doc/2006-03-01/">\n'
143
" <Payer>%s</Payer>\n"
144
"</RequestPaymentConfiguration>" % self.payer)
147
def from_xml(cls, xml_bytes):
149
Create an instance from a C{RequestPaymentConfiguration} XML document.
151
root = XML(xml_bytes)
152
return cls(root.findtext("Payer"))
155
class MultipartInitiationResponse(object):
157
A response to Initiate Multipart Upload
160
def __init__(self, bucket, object_name, upload_id):
162
@param bucket: The bucket name
163
@param object_name: The object name
164
@param upload_id: The upload id
167
self.object_name = object_name
168
self.upload_id = upload_id
171
def from_xml(cls, xml_bytes):
173
Create an instance of this from XML bytes.
175
@param xml_bytes: C{str} bytes of XML to parse
176
@return: an instance of L{MultipartInitiationResponse}
178
root = XML(xml_bytes)
179
return cls(root.findtext('Bucket'),
180
root.findtext('Key'),
181
root.findtext('UploadId'))
184
class MultipartCompletionResponse(object):
186
Represents a response to Complete Multipart Upload
189
def __init__(self, location, bucket, object_name, etag):
191
@param location: The URI identifying newly created object
192
@param bucket: The bucket name
193
@param object_name: The object name / key
194
@param etag: The entity tag
196
self.location = location
198
self.object_name = object_name
202
def from_xml(cls, xml_bytes):
204
Create an instance of this class from XML bytes.
206
@param xml_bytes: C{str} bytes of XML to parse
207
@return: an instance of L{MultipartCompletionResponse}
209
root = XML(xml_bytes)
210
return cls(root.findtext('Location'),
211
root.findtext('Bucket'),
212
root.findtext('Key'),
213
root.findtext('ETag'))