Example #1
0
    def __init__(self, bucket=None, **kwargs):
        self._log = logging.getLogger("MultiPartUpload")
        self._bucket = bucket
        self._conjoined_identifier = kwargs["conjoined_identifier"]
        self.key_name = kwargs["key"]
        self.create_timestamp = \
            parse_http_timestamp(kwargs["create_timestamp"])
        if "abort_timestamp" in kwargs and \
           kwargs["abort_timestamp"] is not None and \
           len(kwargs["abort_timestamp"]) > 0:
            self.abort_timestamp = \
                parse_http_timestamp(kwargs["abort_timestamp"])
        else:
            self.abort_timestamp = None

        if "complete_timestamp" in kwargs and \
           kwargs["complete_timestamp"] is not None and \
           len(kwargs["complete_timestamp"]) > 0:
            self.complete_timestamp = \
                parse_http_timestamp(kwargs["complete_timestamp"])
        else:
            self.complete_timestamp = None

        if "delete_timestamp" in kwargs and \
           kwargs["delete_timestamp"] is not None and \
           len(kwargs["delete_timestamp"]) > 0:
            self.delete_timestamp = \
                parse_http_timestamp(kwargs["delete_timestamp"])
        else:
            self.delete_timestamp = None
Example #2
0
    def get_all_keys(
        self, max_keys=1000, prefix="", marker="", delimiter=""
    ):
        """
        max_keys
            The maximum number of keys to retrieve

        prefix
            The prfix of the keys you want to retrieve

        marker 
            where you are in the result set

        delimiter
        
            Keys that contain the same string between the prefix and the 
            first occurrence of the delimiter will be rolled up into a single 
            result element. 

            These rolled-up keys are not returned elsewhere in the response.

        return 
            TruncatableList : a list of Keys() with an additional attribute
            `truncated`. If truncated is True, ithere are more keys avaialoble 
            to list. To get them, call get_all_keys again with 'marker' set 
            to the name of the last key in the list
        """
        method = "GET"

        http_connection = self.create_http_connection()

        kwargs = {
            "max_keys" : max_keys,
        }
        if prefix != "" and prefix is not None: 
            kwargs["prefix"] = prefix
        if marker != "" and marker is not None: 
            kwargs["marker"] = marker
        if delimiter != "" and delimiter is not None: 
            kwargs["delimiter"] = delimiter

        uri = compute_uri("data/", **kwargs)

        response = http_connection.request(method, uri)
        
        data = response.read()
        http_connection.close()
        data_dict = json.loads(data.decode("utf-8"))

        if "key_data" in data_dict:
            result_list = TruncatableList()
            for key_entry in data_dict["key_data"]:
                key = Key(
                    bucket=self, 
                    name=key_entry["key"], 
                    version_id=key_entry["version_identifier"],
                    last_modified=parse_http_timestamp(key_entry["timestamp"])
                )
                result_list.append(key)
        elif "prefixes" in data_dict:
            result_list = TruncatableList(
                [Prefix(bucket=self, name=p) for p in data_dict["prefixes"]]
            )
        else:
            raise ValueError("Unexpected return value {0}".format(data_dict))

        result_list.truncated = data_dict["truncated"]
        return result_list