1 from s3.connection import S3Connection
2 from s3.objects import S3Bucket
3 from s3.parsers import parseListBuckets, parseGetBucket, parseGetBucketNames
4
6 """
7 S3 Service class.
8
9 Behaves like a dictionary of buckets, with some additional functions.
10 """
11
14
15 - def get(self, name, default=None):
16 """
17 Get bucket with the exact name.
18
19 @param name: The name of the bucket
20 @type name: string
21 @return: Bucket if exists, else None
22 @rtype: S3Bucket or None
23 """
24 response = self._s3_conn.clone().get()
25 return parseGetBucket(name, response.read(), self._s3_conn, default)
26
28 """
29 List all buckets.
30
31 @return: List of buckets associated with the authenticated user
32 @rtype: list
33 """
34 response = self._s3_conn.clone().get()
35 return parseListBuckets(response.read(), self._s3_conn)
36
38 """
39 Create a bucket.
40
41 @param name: Name for the new bucket
42 @type name: string
43 @return: Returns the newly created bucket
44 @rtype: S3Bucket
45 """
46 self._s3_conn.clone().put(name)
47 return S3Bucket(name, self._s3_conn)
48
49
51 """
52 Deletes a bucket.
53
54 @param name: Name of the queue that should be deleted
55 @type name: string
56 """
57 self._s3_conn.clone().delete(name)
58
59
61 """
62 Returns a flat list of bucket names.
63
64 @return: List of bucket names
65 @rtype: list
66 """
67 response = self._s3_conn.clone().get()
68 return parseGetBucketNames(response.read())
69
70 values = list
71
73 """
74 Returns (key, value) pairs, where, keys are bucket names, and values are S3Buckets.
75
76 @return: List of (bucket name, bucket) pairs
77 @rtype: list
78 """
79 return zip(self.keys(), self.list())
80
81
83 """
84 Does bucket exist.
85 """
86 return key in self.keys()
87
88
90 """
91 Get a bucket instance.
92 """
93 return self.get(key)
94
95
97 """
98 Deletes a bucket
99 """
100 self.delete(key)
101