Exemple #1
0
    def test_list_with_url_encoding(self):
        expected = [u"α", u"β", u"γ"]
        for key_name in expected:
            key = self.bucket.new_key(key_name)
            key.set_contents_from_string(key_name)

        # ensure bucket.list() still works by just
        # popping elements off the front of expected.
        orig_getall = self.bucket._get_all
        getall = lambda *a, **k: orig_getall(*a, max_keys=2, **k)
        with patch.object(self.bucket, '_get_all', getall):
            rs = self.bucket.list(encoding_type="url")
            for element in rs:
                name = unquote_str(element.name)
                self.assertEqual(name, expected.pop(0))
            self.assertEqual(expected, [])
def bucket_lister(bucket, prefix='', delimiter='', marker='', headers=None,
                  encoding_type=None):
    """
    A generator function for listing keys in a bucket.
    """
    more_results = True
    k = None
    while more_results:
        rs = bucket.get_all_keys(prefix=prefix, marker=marker,
                                 delimiter=delimiter, headers=headers,
                                 encoding_type=encoding_type)
        for k in rs:
            yield k
        if k:
            marker = rs.next_marker or k.name
        if marker and encoding_type == "url":
            marker = unquote_str(marker)
        more_results= rs.is_truncated
Exemple #3
0
def versioned_bucket_lister(bucket, prefix='', delimiter='',
                            key_marker='', version_id_marker='', headers=None,
                            encoding_type=None):
    """
    A generator function for listing versions in a bucket.
    """
    more_results = True
    k = None
    while more_results:
        rs = bucket.get_all_versions(prefix=prefix, key_marker=key_marker,
                                     version_id_marker=version_id_marker,
                                     delimiter=delimiter, headers=headers,
                                     max_keys=999, encoding_type=encoding_type)
        for k in rs:
            yield k
        key_marker = rs.next_key_marker
        if key_marker and encoding_type == "url":
            key_marker = unquote_str(key_marker)
        version_id_marker = rs.next_version_id_marker
        more_results= rs.is_truncated
Exemple #4
0
def multipart_upload_lister(bucket, key_marker='',
                            upload_id_marker='',
                            headers=None, encoding_type=None):
    """
    A generator function for listing multipart uploads in a bucket.
    """
    more_results = True
    k = None
    while more_results:
        rs = bucket.get_all_multipart_uploads(key_marker=key_marker,
                                              upload_id_marker=upload_id_marker,
                                              headers=headers,
                                              encoding_type=encoding_type)
        for k in rs:
            yield k
        key_marker = rs.next_key_marker
        if key_marker and encoding_type == "url":
            key_marker = unquote_str(key_marker)
        upload_id_marker = rs.next_upload_id_marker
        more_results= rs.is_truncated