Python google.appengine.runtime.apiproxy_errors.Error() Examples

The following are 11 code examples for showing how to use google.appengine.runtime.apiproxy_errors.Error(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module google.appengine.runtime.apiproxy_errors , or try the search function .

Example 1
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: apiproxy_stub_map.py    License: Apache License 2.0 6 votes vote down vote up
def MakeSyncCall(service, call, request, response, stubmap=None):
  """The APIProxy entry point for a synchronous API call.

  Args:
    service: string representing which service to call
    call: string representing which function to call
    request: protocol buffer for the request
    response: protocol buffer for the response
    stubmap: optional APIProxyStubMap instance, for dependency injection.

  Returns:
    Response protocol buffer or None. Some implementations may return
    a response protocol buffer instead of modifying 'response'.
    Caller must use returned value in such cases. If 'response' is modified
    then returns None.

  Raises:
    apiproxy_errors.Error or a subclass.
  """
  if stubmap is None:
    stubmap = apiproxy
  return stubmap.MakeSyncCall(service, call, request, response) 
Example 2
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: apiproxy_stub.py    License: Apache License 2.0 6 votes vote down vote up
def SetError(self, error, method=None, error_rate=1):
    """Set an error condition that may be raised when calls made to stub.

    If a method is specified, the error will only apply to that call.
    The error rate is applied to the method specified or all calls if
    method is not set.

    Args:
      error: An instance of apiproxy_errors.Error or None for no error.
      method: A string representing the method that the error will affect.
      error_rate: a number from [0, 1] that sets the chance of the error,
        defaults to 1.
    """
    assert error is None or isinstance(error, apiproxy_errors.Error)
    if method and error:
      self.__error_dict[method] = error, error_rate
    else:
      self.__error_rate = error_rate
      self.__error = error 
Example 3
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: __init__.py    License: Apache License 2.0 6 votes vote down vote up
def __get_stats_hook(self, rpc):
    try:
      rpc.check_success()
    except apiproxy_errors.Error:
      return None
    response = rpc.response
    if not response.has_stats():
      return {
          STAT_HITS: 0,
          STAT_MISSES: 0,
          STAT_BYTE_HITS: 0,
          STAT_ITEMS: 0,
          STAT_BYTES: 0,
          STAT_OLDEST_ITEM_AGES: 0,
      }

    stats = response.stats()
    return {
        STAT_HITS: stats.hits(),
        STAT_MISSES: stats.misses(),
        STAT_BYTE_HITS: stats.byte_hits(),
        STAT_ITEMS: stats.items(),
        STAT_BYTES: stats.bytes(),
        STAT_OLDEST_ITEM_AGES: stats.oldest_item_age(),
    } 
Example 4
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: __init__.py    License: Apache License 2.0 6 votes vote down vote up
def __delete_hook(self, rpc):
    try:
      rpc.check_success()
    except apiproxy_errors.Error:
      return None
    result = []
    for status in rpc.response.delete_status_list():
      if status == MemcacheDeleteResponse.DELETED:
        result.append(DELETE_SUCCESSFUL)
      elif status == MemcacheDeleteResponse.NOT_FOUND:
        result.append(DELETE_ITEM_MISSING)
      else:



        return None
    return result 
Example 5
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: __init__.py    License: Apache License 2.0 6 votes vote down vote up
def __set_with_policy_hook(self, rpc):
    try:
      rpc.check_success()
    except apiproxy_errors.Error:
      return None

    response = rpc.response
    server_keys, user_key = rpc.user_data
    assert response.set_status_size() == len(server_keys)
    status_dict = {}
    for server_key, status in zip(server_keys, response.set_status_list()):


      if status in (MemcacheSetResponse.DEADLINE_EXCEEDED,
                    MemcacheSetResponse.UNREACHABLE,
                    MemcacheSetResponse.OTHER_ERROR):
        status = MemcacheSetResponse.ERROR
      status_dict[user_key[server_key]] = status
    return status_dict 
Example 6
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: __init__.py    License: Apache License 2.0 6 votes vote down vote up
def __offset_hook(self, rpc):
    mapping = rpc.user_data
    try:
      rpc.check_success()
    except apiproxy_errors.Error:
      return dict((k, None) for k in mapping.iterkeys())

    response = rpc.response
    assert response.item_size() == len(mapping)

    result_dict = {}
    for key, resp_item in zip(mapping.iterkeys(), response.item_list()):
      if (resp_item.increment_status() == MemcacheIncrementResponse.OK and
          resp_item.has_new_value()):
        result_dict[key] = resp_item.new_value()
      else:
        result_dict[key] = None

    return result_dict 
Example 7
Project: luci-py   Author: luci   File: config.py    License: Apache License 2.0 5 votes vote down vote up
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 
Example 8
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: apiproxy_stub_map.py    License: Apache License 2.0 5 votes vote down vote up
def MakeSyncCall(self, service, call, request, response):
    """The APIProxy entry point.

    Args:
      service: string representing which service to call
      call: string representing which function to call
      request: protocol buffer for the request
      response: protocol buffer for the response

    Returns:
      Response protocol buffer or None. Some implementations may return
      a response protocol buffer instead of modifying 'response'.
      Caller must use returned value in such cases. If 'response' is modified
      then returns None.

    Raises:
      apiproxy_errors.Error or a subclass.
    """


    stub = self.GetStub(service)
    assert stub, 'No api proxy found for service "%s"' % service
    if hasattr(stub, 'CreateRPC'):
      rpc = stub.CreateRPC()
      self.__precall_hooks.Call(service, call, request, response, rpc)
      try:
        rpc.MakeCall(service, call, request, response)
        rpc.Wait()
        rpc.CheckSuccess()
      except Exception, err:
        self.__postcall_hooks.Call(service, call, request, response, rpc, err)
        raise
      else:
        self.__postcall_hooks.Call(service, call, request, response, rpc) 
Example 9
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def __flush_all_hook(self, rpc):
    try:
      rpc.check_success()
    except apiproxy_errors.Error:
      return False
    return True 
Example 10
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def __incrdecr_hook(self, rpc):
    try:
      rpc.check_success()
    except apiproxy_errors.Error:
      return None

    response = rpc.response
    if response.has_new_value():
      return response.new_value()
    return None 
Example 11
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: api_server.py    License: Apache License 2.0 5 votes vote down vote up
def start(self):
    with threading.Lock():
      self._server_thread = threading.Thread(target=self._start_server)
      self._server_thread.start()
      self._server_thread.join()
      if not self._port:
        raise errors.GrpcPortError('Error assigning grpc api port!')