Beispiel #1
0
class Bucket(boto.s3.bucket.Bucket):
    __metaclass__ = monkeypatch_class

    _bucket = mock_dict.MockDict()
    _bucket.add_dict_methods()

    @property
    def _bucket_dict(self):
        if self.name in Bucket._bucket:
            return Bucket._bucket[self.name]._mock_dict

    def __init__(self, *args, **kwargs):
        Bucket__init__(self, *args, **kwargs)
        Bucket._bucket[self.name] = mock_dict.MockDict()
        Bucket._bucket[self.name].add_dict_methods()

    def delete(self):
        if self.name in Bucket._bucket:
            Bucket._bucket[self.name] = mock_dict.MockDict()
            Bucket._bucket[self.name].add_dict_methods()

    def list(self, **kwargs):
        return ([self.lookup(k) for k in self._bucket_dict.keys()]
                if self._bucket_dict else [])

    def lookup(self, key_name, **kwargs):
        if self._bucket_dict and key_name in self._bucket_dict:
            value = Bucket._bucket[self.name][key_name]
            k = Key(self)
            k.name = key_name
            k.size = len(value)
            return k

    def initiate_multipart_upload(self, key_name, **kwargs):
        # Pass key_name to MultiPartUpload
        mp = MultiPartUpload(self)
        mp._tmp_key = key_name
        return mp
Beispiel #2
0
 def delete(self):
     if self.name in Bucket._bucket:
         Bucket._bucket[self.name] = mock_dict.MockDict()
         Bucket._bucket[self.name].add_dict_methods()
Beispiel #3
0
 def __init__(self, *args, **kwargs):
     Bucket__init__(self, *args, **kwargs)
     Bucket._bucket[self.name] = mock_dict.MockDict()
     Bucket._bucket[self.name].add_dict_methods()