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


Python datastore_errors.Error方法代碼示例

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


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

示例1: _MakeSyncCall

# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import Error [as 別名]
def _MakeSyncCall(service, call, request, response, config=None):
  """The APIProxy entry point for a synchronous API call.

  Args:
    service: For backwards compatibility, must be 'datastore_v3'.
    call: String representing which function to call.
    request: Protocol buffer for the request.
    response: Protocol buffer for the response.
    config: Optional Configuration to use for this request.

  Returns:
    Response protocol buffer. Caller should always use returned value
    which may or may not be same as passed in 'response'.

  Raises:
    apiproxy_errors.Error or a subclass.
  """
  conn = _GetConnection()
  if isinstance(request, datastore_pb.Query):
    conn._set_request_read_policy(request, config)
    conn._set_request_transaction(request)
  rpc = conn._make_rpc_call(config, call, request, response)
  conn.check_rpc_success(rpc)
  return response 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:26,代碼來源:datastore.py

示例2: Get

# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import Error [as 別名]
def Get(keys, **kwargs):
  """Retrieves one or more entities from the datastore.

  Retrieves the entity or entities with the given key(s) from the datastore
  and returns them as fully populated Entity objects, as defined below. If
  there is an error, raises a subclass of datastore_errors.Error.

  If keys is a single key or string, an Entity will be returned, or
  EntityNotFoundError will be raised if no existing entity matches the key.

  However, if keys is a list or tuple, a list of entities will be returned
  that corresponds to the sequence of keys. It will include entities for keys
  that were found and None placeholders for keys that were not found.

  Args:
    keys: Key or string or list of Keys or strings
    config: Optional Configuration to use for this request, must be specified
      as a keyword argument.

  Returns:
    Entity or list of Entity objects
  """
  return GetAsync(keys, **kwargs).get_result() 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:25,代碼來源:datastore.py

示例3: Delete

# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import Error [as 別名]
def Delete(keys, **kwargs):
  """Deletes one or more entities from the datastore. Use with care!

  Deletes the given entity(ies) from the datastore. You can only delete
  entities from your app. If there is an error, raises a subclass of
  datastore_errors.Error.

  Args:
    # the primary key(s) of the entity(ies) to delete
    keys: Key or string or list of Keys or strings
    config: Optional Configuration to use for this request, must be specified
      as a keyword argument.

  Raises:
    TransactionFailedError, if the Delete could not be committed.
  """
  return DeleteAsync(keys, **kwargs).get_result() 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:19,代碼來源:datastore.py

示例4: _DatastoreExceptionFromErrorCodeAndDetail

# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import Error [as 別名]
def _DatastoreExceptionFromErrorCodeAndDetail(error, detail):
  """Converts a datastore_pb.Error into a datastore_errors.Error.

  Args:
    error: A member of the datastore_pb.Error enumeration.
    detail: A string providing extra details about the error.

  Returns:
    An instance of a subclass of datastore_errors.Error.
  """
  exception_class = _DATASTORE_EXCEPTION_CLASSES.get(error,
                                                     datastore_errors.Error)

  if detail is None:
    return exception_class()
  else:
    return exception_class(detail) 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:19,代碼來源:datastore_rpc.py

示例5: _DatastoreExceptionFromCanonicalErrorCodeAndDetail

# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import Error [as 別名]
def _DatastoreExceptionFromCanonicalErrorCodeAndDetail(error, detail):
  """Converts a canonical error code into a datastore_errors.Error.

  Args:
    error: A canonical error code from google.rpc.code.
    detail: A string providing extra details about the error.

  Returns:
    An instance of a subclass of datastore_errors.Error.
  """
  exception_class = _CLOUD_DATASTORE_EXCEPTION_CLASSES.get(
      error, datastore_errors.InternalError)

  if detail is None:
    return exception_class()
  else:
    return exception_class(detail) 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:19,代碼來源:datastore_rpc.py

示例6: _AcquireAsync

# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import Error [as 別名]
def _AcquireAsync(self, timeout):
    """Acquires the lock via datastore or returns False."""

    @ndb.transactional_tasklet(retries=0)
    def _TransactionalAcquireAsync():
      lock_entity = yield _DatastoreLockEntity.get_or_insert_async(self._id)
      if lock_entity.lock_held:
        raise ndb.Return(False)

      lock_entity.lock_id = self._lock_id
      lock_entity.acquired = True
      lock_entity.timeout = timeout
      yield lock_entity.put_async()
      raise ndb.Return(True)

    try:
      raise ndb.Return((yield _TransactionalAcquireAsync()))
    except datastore_errors.Error:
      raise ndb.Return(False) 
開發者ID:google,項目名稱:upvote,代碼行數:21,代碼來源:datastore_locks.py

示例7: execute_jobs

# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import Error [as 別名]
def execute_jobs(jobs, txn_sleep_time):
  """Executes all jobs one by one, sleeping between them.

  This gives the datastore some time to "land" transactions. It's not a
  guarantee, but just a best effort attempt to avoid contention. If it
  happens, refetch_config() will resume unfinished work on the next iteration.

  There should be no casual dependencies between jobs. Even through they will
  be executed sequentially, some may fail, and this does NOT stop processing
  of subsequent jobs.

  Args:
    txn_sleep_time: how long to sleep between jobs.

  Returns:
    True if all jobs succeeded, False if at least one failed.
  """
  success = True
  for idx, job in enumerate(jobs):
    if idx:
      time.sleep(txn_sleep_time)
    try:
      job()
    except (
          apiproxy_errors.Error,
          datastore_errors.Error,
          replication.ReplicationTriggerError) as exc:
      logging.error(
          'Failed, will try again later: %s - %s',
          exc.__class__.__name__, exc)
      success = False
  return success 
開發者ID:luci,項目名稱:luci-py,代碼行數:34,代碼來源:config.py

示例8: AllocateIds

# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import Error [as 別名]
def AllocateIds(model_key, size=None, **kwargs):
  """Allocates a range of IDs of size or with max for the given key.

  Allocates a range of IDs in the datastore such that those IDs will not
  be automatically assigned to new entities. You can only allocate IDs
  for model keys from your app. If there is an error, raises a subclass of
  datastore_errors.Error.

  Either size or max must be provided but not both. If size is provided then a
  range of the given size is returned. If max is provided then the largest
  range of ids that are safe to use with an upper bound of max is returned (can
  be an empty range).

  Max should only be provided if you have an existing numeric id range that you
  want to reserve, e.g. bulk loading entities that already have IDs. If you
  don't care about which IDs you receive, use size instead.

  Args:
    model_key: Key or string to serve as a model specifying the ID sequence
               in which to allocate IDs
    size: integer, number of IDs to allocate.
    max: integer, upper bound of the range of IDs to allocate.
    config: Optional Configuration to use for this request.

  Returns:
    (start, end) of the allocated range, inclusive.
  """
  return AllocateIdsAsync(model_key, size, **kwargs).get_result() 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:30,代碼來源:datastore.py

示例9: _OpenBlob

# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import Error [as 別名]
def _OpenBlob(self, blob_key):
    """Create an Image from the blob data read from blob_key."""

    try:
      _ = datastore.Get(
          blobstore_stub.BlobstoreServiceStub.ToDatastoreBlobKey(blob_key))
    except datastore_errors.Error:


      logging.exception('Blob with key %r does not exist', blob_key)
      raise apiproxy_errors.ApplicationError(
          images_service_pb.ImagesServiceError.UNSPECIFIED_ERROR)

    blobstore_storage = apiproxy_stub_map.apiproxy.GetStub('blobstore')


    try:
      blob_file = blobstore_storage.storage.OpenBlob(blob_key)
    except IOError:
      logging.exception('Could not get file for blob_key %r', blob_key)

      raise apiproxy_errors.ApplicationError(
          images_service_pb.ImagesServiceError.BAD_IMAGE_DATA)

    try:
      return Image.open(blob_file)
    except IOError:
      logging.exception('Could not open image %r for blob_key %r',
                        blob_file, blob_key)

      raise apiproxy_errors.ApplicationError(
          images_service_pb.ImagesServiceError.BAD_IMAGE_DATA) 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:34,代碼來源:images_stub.py

示例10: __commit_hook

# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import Error [as 別名]
def __commit_hook(self, rpc):
    """Internal method used as get_result_hook for Commit."""
    try:
      rpc.check_success()
      self._state = TransactionalConnection.CLOSED
      self.__transaction = None
    except apiproxy_errors.ApplicationError, err:
      self._state = TransactionalConnection.FAILED
      if err.application_error == datastore_pb.Error.CONCURRENT_TRANSACTION:
        return False
      else:
        raise _ToDatastoreError(err) 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:14,代碼來源:datastore_rpc.py

示例11: _ToDatastoreError

# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import Error [as 別名]
def _ToDatastoreError(err):
  """Converts an apiproxy.ApplicationError to an error in datastore_errors.

  Args:
    err: An apiproxy.ApplicationError object.

  Returns:
    An instance of a subclass of datastore_errors.Error.
  """
  return _DatastoreExceptionFromErrorCodeAndDetail(err.application_error,
                                                   err.error_detail) 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:13,代碼來源:datastore_rpc.py

示例12: ListActions

# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import Error [as 別名]
def ListActions(self, error=None):
    """Handler for get requests to datastore_admin/confirm_delete."""
    use_stats_kinds = False
    kinds = []
    more_kinds = False
    try:
      kinds, more_kinds = utils.GetKinds()
      if not kinds:
        use_stats_kinds = True
        logging.warning('Found no kinds. Using datastore stats instead.')
    except datastore_errors.Error, e:
      logging.exception(e)
      use_stats_kinds = True 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:15,代碼來源:main.py

示例13: process_next_chunk

# 需要導入模塊: from google.appengine.api import datastore_errors [as 別名]
# 或者: from google.appengine.api.datastore_errors import Error [as 別名]
def process_next_chunk(self, up_to):
    """Processes as much minutes starting at a specific time.

    This class should be called from a non-synchronized cron job, so it will
    rarely have more than one instance running at a time. Every entity is self
    contained so it explicitly handles datastore inconsistency.

    Arguments:
    - up_to: number of minutes to buffer between 'now' and the last minute to
             process. Will usually be in the range of 1 to 10.

    Returns:
      Number of self.stats_minute_cls generated, e.g. the number of minutes
      processed successfully by self_generate_snapshot. Returns None in case of
      failure.
    """
    count = 0
    original_minute = None
    try:
      now = utils.utcnow()
      original_minute = self._get_next_minute_to_process(now)
      next_minute = original_minute
      while now - next_minute >= datetime.timedelta(minutes=up_to):
        self._process_one_minute(next_minute)
        count += 1
        self._set_last_processed_time(next_minute)
        if self._max_minutes_per_process == count:
          break
        next_minute = next_minute + datetime.timedelta(minutes=1)
        now = utils.utcnow()
      return count
    except (
        datastore_errors.Error,
        logservice.Error,
        DeadlineExceededError) as e:
      msg = (
          'Got an error while processing stats.\n'
          'Processing started at %s; tried to get up to %smins from now; '
          'Processed %dmins\n%s') % (
          original_minute, up_to, count, e)
      if not count:
        logging.error(msg)
        # This is bad, it means that for the lifespan of the cron handler
        # (currently 10 minutes), it was unable to even process a single minute
        # worth of statistics.
        return None
      logging.warning(msg)
      # At least something was processed, so it's fine.
      return count 
開發者ID:luci,項目名稱:luci-py,代碼行數:51,代碼來源:__init__.py


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