예제 #1
0
    def _list_objects(self, client_kwargs, path, max_results, first_level):
        """
        Lists objects.

        args:
            client_kwargs (dict): Client arguments.
            path (str): Path to list.
            max_results (int): The maximum results that should return the method.
                None if no limit.
            first_level (bool): It True, may only first level objects.

        Yields:
            tuple: object path str, object header dict, has content bool
        """
        # Implementation note:
        #
        # Should return a tuple of the following values
        # - The object path (relative to the "path" argument)
        # - The object headers
        # - The "had content" bool that must be True if the object has sub-content that
        #   should be listed recursively by the function. For instance, it should be
        #   False for files, True for directories that are list without there content
        #   and False for directories that are list with their content.
        #
        # Returning only first level entries with "first_level" or only the maximum
        # entries with "max_results" are optional, these parameters are mainly
        # intended to help to reduce result size from requests against the storage and
        # improve the performance.
        raise ObjectUnsupportedOperation("listdir")
예제 #2
0
    def _remove(self, client_kwargs):
        """
        Remove an object.

        args:
            client_kwargs (dict): Client arguments.
        """
        raise ObjectUnsupportedOperation("remove")
예제 #3
0
    def _make_dir(self, client_kwargs):
        """
        Make a directory.

        args:
            client_kwargs (dict): Client arguments.
        """
        raise ObjectUnsupportedOperation("mkdir")
예제 #4
0
    def symlink(self, target, path=None, client_kwargs=None):
        """
        Creates a symbolic link to target.

        Args:
            target (str): Target path or URL.
            path (str): File path or URL.
            client_kwargs (dict): Client arguments.
        """
        raise ObjectUnsupportedOperation("symlink")
예제 #5
0
    def _list_locators(self, max_results):
        """
        Lists locators.

        args:
            max_results (int): The maximum results that should return the method.

        Yields:
            tuple: locator name str, locator header dict, has content bool
        """
        # Implementation note: See "_list_objects" method.
        raise ObjectUnsupportedOperation("listdir")
예제 #6
0
    def read_link(self, path=None, client_kwargs=None, header=None):
        """
        Return the path linked by the symbolic link.

        Args:
            path (str): File path or URL.
            client_kwargs (dict): Client arguments.
            header (dict): Object header.

        Returns:
            str: Path.
        """
        raise ObjectUnsupportedOperation("symlink")
예제 #7
0
    def _getsize_from_header(self, header):
        """
        Return the size from header

        Args:
            header (dict): Object header.

        Returns:
            int: Size in bytes.
        """
        for key in self._SIZE_KEYS:
            try:
                return int(header[key])
            except KeyError:
                continue
        else:
            raise ObjectUnsupportedOperation("getsize")
예제 #8
0
def shareable_url(path, expires_in=3600):
    """
    Get a shareable public URL for the specified path of an existing object.

    Only available for some storage and not for local paths.

    .. versionadded:: 1.5.0

    Args:
        path (str): Path or URL.
        expires_in (int): Expiration in seconds. Default to 1 hour.
    """
    with handle_os_exceptions():
        path_str = fsdecode(path).replace("\\", "/")

        if not is_storage(path_str):
            raise ObjectUnsupportedOperation("shareable_url")

        return get_instance(path).shareable_url(path_str, expires_in)
예제 #9
0
    def _get_time(header, keys, name):
        """
        Get time from header

        Args:
            header (dict): Object header.
            keys (tuple of str): Header keys.
            name (str): Method name.

        Returns:
            float: The number of seconds since the epoch
        """
        for key in keys:
            try:
                date_value = header[key]
            except KeyError:
                continue
            try:
                return parse(date_value).timestamp()
            except TypeError:
                return float(date_value)
        raise ObjectUnsupportedOperation(name)