コード例 #1
0
ファイル: bucket.py プロジェクト: rakyll/gcloud-python
    def get_key(self, key):
        """Get a key object by name.

    This will return None if the key doesn't exist::

      >>> from gcloud import storage
      >>> connection = storage.get_connection(project, email, key_path)
      >>> bucket = connection.get_bucket('my-bucket')
      >>> print bucket.get_key('/path/to/key.txt')
      <Key: my-bucket, /path/to/key.txt>
      >>> print bucket.get_key('/does-not-exist.txt')
      None

    :type key: string or :class:`gcloud.storage.key.Key`
    :param key: The name of the key to retrieve.

    :rtype: :class:`gcloud.storage.key.Key` or None
    :returns: The key object if it exists, otherwise None.
    """

        # Coerce this to a key object (either from a Key or a string).
        key = self.new_key(key)

        try:
            response = self.connection.api_request(method='GET', path=key.path)
            return Key.from_dict(response, bucket=self)
        except exceptions.NotFoundError:
            return None
コード例 #2
0
ファイル: bucket.py プロジェクト: pohsiang/gcloud-python
    def get_key(self, key):
        """Get a key object by name.

        This will return None if the key doesn't exist::

          >>> from gcloud import storage
          >>> connection = storage.get_connection(project, email, key_path)
          >>> bucket = connection.get_bucket('my-bucket')
          >>> print bucket.get_key('/path/to/key.txt')
          <Key: my-bucket, /path/to/key.txt>
          >>> print bucket.get_key('/does-not-exist.txt')
          None

        :type key: string or :class:`gcloud.storage.key.Key`
        :param key: The name of the key to retrieve.

        :rtype: :class:`gcloud.storage.key.Key` or None
        :returns: The key object if it exists, otherwise None.
        """
        # Coerce this to a key object (either from a Key or a string).
        key = self.new_key(key)

        try:
            response = self.connection.api_request(method='GET', path=key.path)
            return Key.from_dict(response, bucket=self)
        except exceptions.NotFound:
            return None
コード例 #3
0
ファイル: bucket.py プロジェクト: pohsiang/gcloud-python
    def get_items_from_response(self, response):
        """Yield :class:`.storage.key.Key` items from response.

        :type response: dict
        :param response: The JSON API response for a page of keys.
        """
        self.prefixes = tuple(response.get('prefixes', ()))
        for item in response.get('items', []):
            yield Key.from_dict(item, bucket=self.bucket)
コード例 #4
0
ファイル: bucket.py プロジェクト: adieu/gcloud-python
    def get_items_from_response(self, response):
        """Yield :class:`.storage.key.Key` items from response.

        :type response: dict
        :param response: The JSON API response for a page of keys.
        """
        self.prefixes = tuple(response.get('prefixes', ()))
        for item in response.get('items', []):
            yield Key.from_dict(item, bucket=self.bucket)
コード例 #5
0
ファイル: iterator.py プロジェクト: x1ddos/gcloud-python
    def get_items_from_response(self, response):
        """Factory method which yields :class:`gcloud.storage.key.Key` items from a response.

    :type response: dict
    :param response: The JSON API response for a page of keys.
    """

        from gcloud.storage.key import Key
        for item in response.get('items', []):
            yield Key.from_dict(item, bucket=self.bucket)
コード例 #6
0
ファイル: iterator.py プロジェクト: feczo/gcloud-python
    def get_items_from_response(self, response):
        """Factory method, yields :class:`.storage.key.Key` items from response.

        :type response: dict
        :param response: The JSON API response for a page of keys.
        """

        from gcloud.storage.key import Key
        for item in response.get('items', []):
            yield Key.from_dict(item, bucket=self.bucket)