當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。