当前位置: 首页>>代码示例>>Python>>正文


Python exceptions.NotFound方法代码示例

本文整理汇总了Python中google.cloud.exceptions.NotFound方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.NotFound方法的具体用法?Python exceptions.NotFound怎么用?Python exceptions.NotFound使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在google.cloud.exceptions的用法示例。


在下文中一共展示了exceptions.NotFound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_bucket

# 需要导入模块: from google.cloud import exceptions [as 别名]
# 或者: from google.cloud.exceptions import NotFound [as 别名]
def get_bucket(self, bucket_name=None):
    """Retrieves a Google Cloud Storage Bucket object.

    Args:
      bucket_name: str, the name of the Google Cloud Storage Bucket to retrieve.

    Returns:
      A dictionary object representing a Google Cloud Storage Bucket.
          type: google.cloud.storage.bucket.Bucket

    Raises:
      NotFoundError: when a resource is not found.
    """
    bucket_name = bucket_name or self._config.bucket
    try:
      return self._client.get_bucket(bucket_name)
    except exceptions.NotFound as err:
      logging.error(_GET_BUCKET_ERROR_MSG, bucket_name, err)
      raise NotFoundError(_GET_BUCKET_ERROR_MSG % (bucket_name, err)) 
开发者ID:google,项目名称:loaner,代码行数:21,代码来源:storage.py

示例2: list_checkpoints

# 需要导入模块: from google.cloud import exceptions [as 别名]
# 或者: from google.cloud.exceptions import NotFound [as 别名]
def list_checkpoints(self, path):
        """Return a list of checkpoints for a given file"""
        cp = self._get_checkpoint_path(None, path)
        bucket_name, bucket_path = self.parent._parse_path(cp)
        try:
            bucket = self.parent._get_bucket(bucket_name)
            it = bucket.list_blobs(prefix=bucket_path, delimiter="/",
                                   max_results=self.parent.max_list_size)
            checkpoints = [{
                "id": os.path.splitext(file.path)[0][-36:],
                "last_modified": file.updated,
            } for file in islice(it, self.parent.max_list_size)]
        except NotFound:
            return []
        checkpoints.sort(key=lambda c: c["last_modified"], reverse=True)
        self.log.debug("list_checkpoints: %s: %s", path, checkpoints)
        return checkpoints 
开发者ID:src-d,项目名称:jgscm,代码行数:19,代码来源:__init__.py

示例3: table_exists

# 需要导入模块: from google.cloud import exceptions [as 别名]
# 或者: from google.cloud.exceptions import NotFound [as 别名]
def table_exists(self, dataset_id: str, table_id: str, project_id: str) -> bool:
        """
        Checks for the existence of a table in Google BigQuery.

        :param project_id: The Google cloud project in which to look for the
            table. The connection supplied to the hook must provide access to
            the specified project.
        :type project_id: str
        :param dataset_id: The name of the dataset in which to look for the
            table.
        :type dataset_id: str
        :param table_id: The name of the table to check the existence of.
        :type table_id: str
        """
        table_reference = TableReference(DatasetReference(project_id, dataset_id), table_id)
        try:
            self.get_client().get_table(table_reference)
            return True
        except NotFound:
            return False 
开发者ID:apache,项目名称:airflow,代码行数:22,代码来源:bigquery.py

示例4: download_cache

# 需要导入模块: from google.cloud import exceptions [as 别名]
# 或者: from google.cloud.exceptions import NotFound [as 别名]
def download_cache(self, path):
        """Retrieve and return the cached file"""
        bucket = self.get_bucket()
        blob = bucket.get_blob(path)

        if not blob:
            raise NotFound(path)

        media_file = io.BytesIO()
        self._do_download(blob, media_file)
        media_file.seek(0, 0)
        log.debug('Retrieved file from GCS bucket %s: %s' % (self.bucket_name, path))

        resource = FileResource(media_file)
        resource.content_type = blob.content_type
        resource.file_size = blob.size
        return resource 
开发者ID:openstate,项目名称:open-raadsinformatie,代码行数:19,代码来源:http.py

示例5: send

# 需要导入模块: from google.cloud import exceptions [as 别名]
# 或者: from google.cloud.exceptions import NotFound [as 别名]
def send(attachment):
    """Send to download URI."""
    try:
        client = storage.Client()
        bucket = client.bucket(get_bucket())
        buf = BytesIO()
        blob = bucket.get_blob(attachment.aid)
        if not blob:
            return flask.abort(404)
        blob.download_to_file(buf)
        buf.seek(0)
        return flask.send_file(
            buf,
            mimetype=attachment.content_type,
            attachment_filename=attachment.filename,
            add_etags=False, as_attachment=True)
    except exceptions.NotFound:
        return flask.abort(404) 
开发者ID:google,项目名称:ctfscoreboard,代码行数:20,代码来源:gcs.py

示例6: glossary

# 需要导入模块: from google.cloud import exceptions [as 别名]
# 或者: from google.cloud.exceptions import NotFound [as 别名]
def glossary():
    """Get the ID of a glossary available to session (do not mutate/delete)."""
    glossary_id = "test-{}".format(uuid.uuid4())
    translate_v3_create_glossary.create_glossary(
        PROJECT_ID, GLOSSARY_INPUT_URI, glossary_id
    )

    yield glossary_id

    # cleanup
    @backoff.on_exception(
        backoff.expo, (DeadlineExceeded, GoogleAPICallError), max_time=60
    )
    def delete_glossary():
        try:
            translate_v3_delete_glossary.delete_glossary(
                PROJECT_ID, glossary_id)
        except NotFound as e:
            # Ignoring this case.
            print("Got NotFound, detail: {}".format(str(e)))
    delete_glossary() 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:23,代码来源:translate_v3_batch_translate_text_with_glossary_test.py

示例7: glossary

# 需要导入模块: from google.cloud import exceptions [as 别名]
# 或者: from google.cloud.exceptions import NotFound [as 别名]
def glossary():
    """Get the ID of a glossary available to session (do not mutate/delete)."""
    glossary_id = "must-start-with-letters-" + str(uuid.uuid1())
    translate_v3_create_glossary.create_glossary(
        PROJECT_ID, GLOSSARY_INPUT_URI, glossary_id
    )

    yield glossary_id

    # clean up
    @backoff.on_exception(
        backoff.expo, (DeadlineExceeded, GoogleAPICallError), max_time=60
    )
    def delete_glossary():
        try:
            translate_v3_delete_glossary.delete_glossary(
                PROJECT_ID, glossary_id)
        except NotFound as e:
            # Ignoring this case.
            print("Got NotFound, detail: {}".format(str(e)))
    delete_glossary() 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:23,代码来源:translate_v3_list_glossary_test.py

示例8: glossary

# 需要导入模块: from google.cloud import exceptions [as 别名]
# 或者: from google.cloud.exceptions import NotFound [as 别名]
def glossary():
    """Get the ID of a glossary available to session (do not mutate/delete)."""
    glossary_id = "must-start-with-letters-" + str(uuid.uuid1())
    translate_v3_create_glossary.create_glossary(
        PROJECT_ID, GLOSSARY_INPUT_URI, glossary_id
    )

    yield glossary_id

    # cleanup
    @backoff.on_exception(
        backoff.expo, (DeadlineExceeded, GoogleAPICallError), max_time=60
    )
    def delete_glossary():
        try:
            translate_v3_delete_glossary.delete_glossary(
                PROJECT_ID, glossary_id)
        except NotFound as e:
            # Ignoring this case.
            print("Got NotFound, detail: {}".format(str(e)))
    delete_glossary() 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:23,代码来源:translate_v3_get_glossary_test.py

示例9: test_create_glossary

# 需要导入模块: from google.cloud import exceptions [as 别名]
# 或者: from google.cloud.exceptions import NotFound [as 别名]
def test_create_glossary(capsys):
    try:
        glossary_id = "test-{}".format(uuid.uuid4())
        translate_v3_create_glossary.create_glossary(
            PROJECT_ID, GLOSSARY_INPUT_URI, glossary_id
        )
        out, _ = capsys.readouterr()
        # assert
        assert "Created:" in out
        assert "gs://cloud-samples-data/translation/glossary_ja.csv" in out
    finally:
        # cleanup
        @backoff.on_exception(
            backoff.expo, (DeadlineExceeded, GoogleAPICallError), max_time=60
        )
        def delete_glossary():
            try:
                translate_v3_delete_glossary.delete_glossary(
                    PROJECT_ID, glossary_id)
            except NotFound as e:
                # Ignoring this case.
                print("Got NotFound, detail: {}".format(str(e)))
        delete_glossary() 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:25,代码来源:translate_v3_create_glossary_test.py

示例10: delete_blob

# 需要导入模块: from google.cloud import exceptions [as 别名]
# 或者: from google.cloud.exceptions import NotFound [as 别名]
def delete_blob(to_delete):
    # [START delete_blob]
    from google.cloud.exceptions import NotFound

    client = storage.Client()
    bucket = client.get_bucket("my-bucket")
    blobs = list(bucket.list_blobs())
    assert len(blobs) > 0
    # [<Blob: my-bucket, my-file.txt>]
    bucket.delete_blob("my-file.txt")
    try:
        bucket.delete_blob("doesnt-exist")
    except NotFound:
        pass
    # [END delete_blob]

    blob = None
    # [START delete_blobs]
    bucket.delete_blobs([blob], on_error=lambda blob: None)
    # [END delete_blobs]

    to_delete.append(bucket) 
开发者ID:googleapis,项目名称:python-storage,代码行数:24,代码来源:snippets.py

示例11: test_exists_miss_no_project_set

# 需要导入模块: from google.cloud import exceptions [as 别名]
# 或者: from google.cloud.exceptions import NotFound [as 别名]
def test_exists_miss_no_project_set(self):
        from google.cloud.exceptions import NotFound

        access_id = "ACCESS-ID"
        connection = mock.Mock(spec=["api_request"])
        connection.api_request.side_effect = NotFound("testing")
        client = _Client(connection)
        metadata = self._make_one(client)
        metadata._properties["accessId"] = access_id

        self.assertFalse(metadata.exists(timeout=42))

        expected_path = "/projects/{}/hmacKeys/{}".format(
            client.DEFAULT_PROJECT, access_id
        )
        expected_kwargs = {
            "method": "GET",
            "path": expected_path,
            "query_params": {},
            "timeout": 42,
        }
        connection.api_request.assert_called_once_with(**expected_kwargs) 
开发者ID:googleapis,项目名称:python-storage,代码行数:24,代码来源:test_hmac_key.py

示例12: test_reload_miss_no_project_set

# 需要导入模块: from google.cloud import exceptions [as 别名]
# 或者: from google.cloud.exceptions import NotFound [as 别名]
def test_reload_miss_no_project_set(self):
        from google.cloud.exceptions import NotFound

        access_id = "ACCESS-ID"
        connection = mock.Mock(spec=["api_request"])
        connection.api_request.side_effect = NotFound("testing")
        client = _Client(connection)
        metadata = self._make_one(client)
        metadata._properties["accessId"] = access_id

        with self.assertRaises(NotFound):
            metadata.reload(timeout=42)

        expected_path = "/projects/{}/hmacKeys/{}".format(
            client.DEFAULT_PROJECT, access_id
        )
        expected_kwargs = {
            "method": "GET",
            "path": expected_path,
            "query_params": {},
            "timeout": 42,
        }
        connection.api_request.assert_called_once_with(**expected_kwargs) 
开发者ID:googleapis,项目名称:python-storage,代码行数:25,代码来源:test_hmac_key.py

示例13: test_update_miss_no_project_set

# 需要导入模块: from google.cloud import exceptions [as 别名]
# 或者: from google.cloud.exceptions import NotFound [as 别名]
def test_update_miss_no_project_set(self):
        from google.cloud.exceptions import NotFound

        access_id = "ACCESS-ID"
        connection = mock.Mock(spec=["api_request"])
        connection.api_request.side_effect = NotFound("testing")
        client = _Client(connection)
        metadata = self._make_one(client)
        metadata._properties["accessId"] = access_id
        metadata.state = "INACTIVE"

        with self.assertRaises(NotFound):
            metadata.update(timeout=42)

        expected_path = "/projects/{}/hmacKeys/{}".format(
            client.DEFAULT_PROJECT, access_id
        )
        expected_kwargs = {
            "method": "PUT",
            "path": expected_path,
            "data": {"state": "INACTIVE"},
            "query_params": {},
            "timeout": 42,
        }
        connection.api_request.assert_called_once_with(**expected_kwargs) 
开发者ID:googleapis,项目名称:python-storage,代码行数:27,代码来源:test_hmac_key.py

示例14: test_exists_miss

# 需要导入模块: from google.cloud import exceptions [as 别名]
# 或者: from google.cloud.exceptions import NotFound [as 别名]
def test_exists_miss(self):
        from google.cloud.exceptions import NotFound

        class _FakeConnection(object):

            _called_with = []

            @classmethod
            def api_request(cls, *args, **kwargs):
                cls._called_with.append((args, kwargs))
                raise NotFound(args)

        BUCKET_NAME = "bucket-name"
        bucket = self._make_one(name=BUCKET_NAME)
        client = _Client(_FakeConnection)
        self.assertFalse(bucket.exists(client=client, timeout=42))
        expected_called_kwargs = {
            "method": "GET",
            "path": bucket.path,
            "query_params": {"fields": "name"},
            "_target_object": None,
            "timeout": 42,
        }
        expected_cw = [((), expected_called_kwargs)]
        self.assertEqual(_FakeConnection._called_with, expected_cw) 
开发者ID:googleapis,项目名称:python-storage,代码行数:27,代码来源:test_bucket.py

示例15: test_delete_miss

# 需要导入模块: from google.cloud import exceptions [as 别名]
# 或者: from google.cloud.exceptions import NotFound [as 别名]
def test_delete_miss(self):
        from google.cloud.exceptions import NotFound

        NAME = "name"
        connection = _Connection()
        client = _Client(connection)
        bucket = self._make_one(client=client, name=NAME)
        self.assertRaises(NotFound, bucket.delete)
        expected_cw = [
            {
                "method": "DELETE",
                "path": bucket.path,
                "query_params": {},
                "_target_object": None,
                "timeout": self._get_default_timeout(),
            }
        ]
        self.assertEqual(connection._deleted_buckets, expected_cw) 
开发者ID:googleapis,项目名称:python-storage,代码行数:20,代码来源:test_bucket.py


注:本文中的google.cloud.exceptions.NotFound方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。