当前位置: 首页>>代码示例>>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;未经允许,请勿转载。