當前位置: 首頁>>代碼示例>>Python>>正文


Python exceptions.Conflict方法代碼示例

本文整理匯總了Python中google.cloud.exceptions.Conflict方法的典型用法代碼示例。如果您正苦於以下問題:Python exceptions.Conflict方法的具體用法?Python exceptions.Conflict怎麽用?Python exceptions.Conflict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在google.cloud.exceptions的用法示例。


在下文中一共展示了exceptions.Conflict方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: insert_bucket

# 需要導入模塊: from google.cloud import exceptions [as 別名]
# 或者: from google.cloud.exceptions import Conflict [as 別名]
def insert_bucket(self, bucket_name=None):
    """Inserts a Google Cloud Storage Bucket object.

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

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

    Raises:
      AlreadyExistsError: when trying to insert a bucket that already exists.
    """
    bucket_name = bucket_name or self._config.bucket
    try:
      new_bucket = self._client.create_bucket(bucket_name)
    except exceptions.Conflict as err:
      raise AlreadyExistsError(
          'the Google Cloud Storage Bucket with name {!r} already exists: '
          '{}'.format(bucket_name, err))

    logging.debug(
        'The Googld Cloud Storage Bucket %r has been created for project '
        '%r.', bucket_name, self._config.project)
    return new_bucket 
開發者ID:google,項目名稱:loaner,代碼行數:27,代碼來源:storage.py

示例2: setup_subscriber

# 需要導入模塊: from google.cloud import exceptions [as 別名]
# 或者: from google.cloud.exceptions import Conflict [as 別名]
def setup_subscriber(self):
    """Set up the pubsub subscriber."""
    config.LoadConfig()
    self.subscriber = pubsub.SubscriberClient()
    subscription_path = self.subscriber.subscription_path(
        config.TURBINIA_PROJECT, self.topic_name)
    if not self.topic_path:
      self.topic_path = self.subscriber.topic_path(
          config.TURBINIA_PROJECT, self.topic_name)
    try:
      log.debug(
          'Trying to create subscription {0:s} on topic {1:s}'.format(
              subscription_path, self.topic_path))
      self.subscriber.create_subscription(subscription_path, self.topic_path)
    except exceptions.Conflict:
      log.debug('Subscription {0:s} already exists.'.format(subscription_path))

    log.debug('Setup PubSub Subscription {0:s}'.format(subscription_path))
    self.subscription = self.subscriber.subscribe(
        subscription_path, self._callback) 
開發者ID:google,項目名稱:turbinia,代碼行數:22,代碼來源:pubsub.py

示例3: test_upload_from_file_failure

# 需要導入模塊: from google.cloud import exceptions [as 別名]
# 或者: from google.cloud.exceptions import Conflict [as 別名]
def test_upload_from_file_failure(self):
        import requests

        from google.resumable_media import InvalidResponse
        from google.cloud import exceptions

        message = "Someone is already in this spot."
        response = requests.Response()
        response.status_code = http_client.CONFLICT
        response.request = requests.Request("POST", "http://example.com").prepare()
        side_effect = InvalidResponse(response, message)

        with self.assertRaises(exceptions.Conflict) as exc_info:
            self._upload_from_file_helper(side_effect=side_effect)

        self.assertIn(message, exc_info.exception.message)
        self.assertEqual(exc_info.exception.errors, []) 
開發者ID:googleapis,項目名稱:python-storage,代碼行數:19,代碼來源:test_blob.py

示例4: destroy

# 需要導入模塊: from google.cloud import exceptions [as 別名]
# 或者: from google.cloud.exceptions import Conflict [as 別名]
def destroy(self):
        try:
            self.bucket = self.storageClient.get_bucket(self.bucketName)

        except exceptions.NotFound:
            # just return if not connect to physical storage. Needed for idempotency
            return
        try:
            self.bucket.delete(force=True)
            # throws ValueError if bucket has more than 256 objects. Then we must delete manually
        except ValueError:
            self.bucket.delete_blobs(self.bucket.list_blobs())
            self.bucket.delete()
            # if ^ throws a google.cloud.exceptions.Conflict, then we should have a deletion retry mechanism.

        # google freaks out if we call delete multiple times on the bucket obj, so after success
        # just set to None.
        self.bucket = None 
開發者ID:DataBiosphere,項目名稱:toil,代碼行數:20,代碼來源:googleJobStore.py

示例5: testMissingDataset_Conflict

# 需要導入模塊: from google.cloud import exceptions [as 別名]
# 或者: from google.cloud.exceptions import Conflict [as 別名]
def testMissingDataset_Conflict(self):

    mock_client = mock.Mock(spec=tables.bigquery.Client)
    mock_client.insert_rows.side_effect = [exceptions.NotFound('OMG'), []]
    mock_client.get_dataset.side_effect = exceptions.NotFound('OMG')
    mock_client.create_dataset.side_effect = exceptions.Conflict('WTF')
    mock_client.get_table.side_effect = exceptions.NotFound('OMG')
    self.Patch(tables.bigquery, 'Client', return_value=mock_client)

    tables._SendToBigQuery(TEST_TABLE, self.row_dict)

    insert_rows_call = mock.call(
        mock.ANY, [self.row_dict], selected_fields=TEST_TABLE.schema,
        row_ids=[self.row_id])

    mock_client.insert_rows.assert_has_calls([insert_rows_call] * 2)
    mock_client.get_dataset.assert_called_once()
    mock_client.create_dataset.assert_called_once()
    mock_client.get_table.assert_called_once()
    mock_client.create_table.assert_called_once() 
開發者ID:google,項目名稱:upvote,代碼行數:22,代碼來源:tables_test.py

示例6: testMissingTable_Conflict

# 需要導入模塊: from google.cloud import exceptions [as 別名]
# 或者: from google.cloud.exceptions import Conflict [as 別名]
def testMissingTable_Conflict(self):

    mock_client = mock.Mock(spec=tables.bigquery.Client)
    mock_client.insert_rows.side_effect = [exceptions.NotFound('OMG'), []]
    mock_client.get_table.side_effect = exceptions.NotFound('OMG')
    mock_client.create_table.side_effect = exceptions.Conflict('WTF')
    self.Patch(tables.bigquery, 'Client', return_value=mock_client)

    tables._SendToBigQuery(TEST_TABLE, self.row_dict)

    insert_rows_call = mock.call(
        mock.ANY, [self.row_dict], selected_fields=TEST_TABLE.schema,
        row_ids=[self.row_id])

    mock_client.insert_rows.assert_has_calls([insert_rows_call] * 2)
    mock_client.get_dataset.assert_called_once()
    mock_client.create_dataset.assert_not_called()
    mock_client.get_table.assert_called_once()
    mock_client.create_table.assert_called_once() 
開發者ID:google,項目名稱:upvote,代碼行數:21,代碼來源:tables_test.py

示例7: create_container

# 需要導入模塊: from google.cloud import exceptions [as 別名]
# 或者: from google.cloud.exceptions import Conflict [as 別名]
def create_container(
        self, container_name: str, acl: str = None, meta_data: MetaData = None
    ) -> Container:
        if meta_data:
            logger.warning(messages.OPTION_NOT_SUPPORTED, "meta_data")

        try:
            bucket = self.client.create_bucket(container_name)
        except Conflict:
            logger.debug(messages.CONTAINER_EXISTS, container_name)
            bucket = self._get_bucket(container_name)
        except ValueError as err:
            raise CloudStorageError(str(err))

        if acl:
            bucket.acl.save_predefined(acl)

        return self._make_container(bucket) 
開發者ID:scottwernervt,項目名稱:cloudstorage,代碼行數:20,代碼來源:google.py

示例8: set_up_bq

# 需要導入模塊: from google.cloud import exceptions [as 別名]
# 或者: from google.cloud.exceptions import Conflict [as 別名]
def set_up_bq():
    """Set up BQ datasets and tables."""

    try:
        Client("measures").create_dataset()
    except Conflict:
        pass

    client = Client("hscic")
    client.get_or_create_table("ccgs", schemas.CCG_SCHEMA)
    client.get_or_create_table("practices", schemas.PRACTICE_SCHEMA)
    client.get_or_create_table("normalised_prescribing", schemas.PRESCRIBING_SCHEMA)
    client.get_or_create_table(
        "practice_statistics", schemas.PRACTICE_STATISTICS_SCHEMA
    )
    client.get_or_create_table("presentation", schemas.PRESENTATION_SCHEMA) 
開發者ID:ebmdatalab,項目名稱:openprescribing,代碼行數:18,代碼來源:test_import_measures.py

示例9: test_cloud_storage_api_insert_bucket__already_exists_error

# 需要導入模塊: from google.cloud import exceptions [as 別名]
# 或者: from google.cloud.exceptions import Conflict [as 別名]
def test_cloud_storage_api_insert_bucket__already_exists_error(self):
    """Test the Cloud Storage Bucket creation for an existing bucket."""
    test_cloud_storage_api = storage.CloudStorageAPI(self.config, mock.Mock())
    test_cloud_storage_api._client.create_bucket.side_effect = (
        exceptions.Conflict('This bucket already exists.'))
    with self.assertRaises(storage.AlreadyExistsError):
      test_cloud_storage_api.insert_bucket() 
開發者ID:google,項目名稱:loaner,代碼行數:9,代碼來源:storage_test.py

示例10: get_bucket

# 需要導入模塊: from google.cloud import exceptions [as 別名]
# 或者: from google.cloud.exceptions import Conflict [as 別名]
def get_bucket(self):
        """Get the bucket defined by 'bucket_name' from the storage_client.
        Throws a ValueError when bucket_name is not set. If the bucket does not
        exist in GCS, a new bucket will be created.
        """
        if self._bucket:
            return self._bucket

        if not self.bucket_name:
            raise ValueError("The 'bucket_name' needs to be set.")

        try:
            self._bucket = self.storage_client.get_bucket(self.bucket_name)
        except (exceptions.NotFound, exceptions.Forbidden):
            bucket = storage.Bucket(self.storage_client, name=self.bucket_name)
            bucket.versioning_enabled = True
            bucket.lifecycle_rules = [{
                'action': {'type': 'SetStorageClass', 'storageClass': 'NEARLINE'},
                'condition': {
                    'numNewerVersions': 1,
                    'matchesStorageClass': ['REGIONAL', 'STANDARD'],
                    'age': 30
                }
            }]
            try:
                bucket.create(location='europe-west4')
            except exceptions.Conflict:
                raise
            self._bucket = self.storage_client.get_bucket(self.bucket_name)

        return self._bucket 
開發者ID:openstate,項目名稱:open-raadsinformatie,代碼行數:33,代碼來源:http.py

示例11: _ensure_bucket_exists

# 需要導入模塊: from google.cloud import exceptions [as 別名]
# 或者: from google.cloud.exceptions import Conflict [as 別名]
def _ensure_bucket_exists(self, bucket_name: Text) -> None:
        from google.cloud import exceptions

        try:
            self.storage_client.create_bucket(bucket_name)
        except exceptions.Conflict:
            # bucket exists
            pass 
開發者ID:weizhenzhao,項目名稱:rasa_nlu,代碼行數:10,代碼來源:persistor.py

示例12: setup_publisher

# 需要導入模塊: from google.cloud import exceptions [as 別名]
# 或者: from google.cloud.exceptions import Conflict [as 別名]
def setup_publisher(self):
    """Set up the pubsub publisher."""
    config.LoadConfig()
    self.publisher = pubsub.PublisherClient()
    self.topic_path = self.publisher.topic_path(
        config.TURBINIA_PROJECT, self.topic_name)
    try:
      log.debug('Trying to create pubsub topic {0:s}'.format(self.topic_path))
      self.publisher.create_topic(self.topic_path)
    except exceptions.Conflict:
      log.debug('PubSub topic {0:s} already exists.'.format(self.topic_path))
    log.debug('Setup PubSub publisher at {0:s}'.format(self.topic_path)) 
開發者ID:google,項目名稱:turbinia,代碼行數:14,代碼來源:pubsub.py

示例13: test_create_bucket_w_conflict

# 需要導入模塊: from google.cloud import exceptions [as 別名]
# 或者: from google.cloud.exceptions import Conflict [as 別名]
def test_create_bucket_w_conflict(self):
        from google.cloud.exceptions import Conflict

        project = "PROJECT"
        user_project = "USER_PROJECT"
        other_project = "OTHER_PROJECT"
        credentials = _make_credentials()
        client = self._make_one(project=project, credentials=credentials)
        connection = _make_connection()
        client._base_connection = connection
        connection.api_request.side_effect = Conflict("testing")

        bucket_name = "bucket-name"
        data = {"name": bucket_name}

        with self.assertRaises(Conflict):
            client.create_bucket(
                bucket_name, project=other_project, user_project=user_project
            )

        connection.api_request.assert_called_once_with(
            method="POST",
            path="/b",
            query_params={"project": other_project, "userProject": user_project},
            data=data,
            _target_object=mock.ANY,
            timeout=self._get_default_timeout(),
        ) 
開發者ID:googleapis,項目名稱:python-storage,代碼行數:30,代碼來源:test_client.py

示例14: tearDownModule

# 需要導入模塊: from google.cloud import exceptions [as 別名]
# 或者: from google.cloud.exceptions import Conflict [as 別名]
def tearDownModule():
    errors = (exceptions.Conflict, exceptions.TooManyRequests)
    retry = RetryErrors(errors, max_tries=15)
    retry(_empty_bucket)(Config.TEST_BUCKET)
    retry(Config.TEST_BUCKET.delete)(force=True) 
開發者ID:googleapis,項目名稱:python-storage,代碼行數:7,代碼來源:test_system.py

示例15: tearDownClass

# 需要導入模塊: from google.cloud import exceptions [as 別名]
# 或者: from google.cloud.exceptions import Conflict [as 別名]
def tearDownClass(cls):
        _empty_bucket(cls.bucket)
        errors = (exceptions.Conflict, exceptions.TooManyRequests)
        retry = RetryErrors(errors, max_tries=6)
        retry(cls.bucket.delete)(force=True) 
開發者ID:googleapis,項目名稱:python-storage,代碼行數:7,代碼來源:test_system.py


注:本文中的google.cloud.exceptions.Conflict方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。