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

The following are code examples for showing how to use google.appengine.runtime.apiproxy_errors.Error(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: apiproxy_stub_map.py    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    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    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    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    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    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: python-compat-runtime   Author: GoogleCloudPlatform   File: apiproxy_stub_map.py    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 8
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: __init__.py    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 9
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: __init__.py    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 10
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: api_server.py    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!')