def run_rpc_handler(rpc): try: rpc.check_success() except apiproxy_errors.ApplicationError, err: try: _ToDatastoreError(err) except datastore_errors.NeedIndexError, exc: yaml = datastore_index.IndexYamlForQuery( *datastore_index.CompositeIndexForQuery(rpc.request)[1:-1]) raise datastore_errors.NeedIndexError( str(exc) + '\nThis query needs this index:\n' + yaml)
def MakeSyncCall(self, service, call, request, response): self._PreHookHandler(service, call, request, response) request_pb = remote_api_pb.Request() request_pb.set_service_name(service) request_pb.set_method(call) request_pb.mutable_request().set_contents(request.Encode()) response_pb = remote_api_pb.Response() encoded_request = request_pb.Encode() encoded_response = self._server.Send(self._path, encoded_request) response_pb.ParseFromString(encoded_response) try: if response_pb.has_application_error(): error_pb = response_pb.application_error() raise datastore._ToDatastoreError( apiproxy_errors.ApplicationError(error_pb.code(), error_pb.detail())) elif response_pb.has_exception(): raise pickle.loads(response_pb.exception().contents()) elif response_pb.has_java_exception(): raise UnknownJavaServerError("An unknown error has occured in the " "Java remote_api handler for this call.") else: response.ParseFromString(response_pb.response().contents()) finally: self._PostHookHandler(service, call, request, response)
def rpc_callback(self, rpc): try: rpc.check_success() except ApplicationError, err: try: raise _ToDatastoreError(err) except datastore_errors.NeedIndexError, exc: yaml = datastore_index.IndexYamlForQuery( *datastore_index.CompositeIndexForQuery(rpc.request)[1:-1]) raise datastore_errors.NeedIndexError( str(exc) + '\nThis query needs this index:\n' + yaml)
def GetIndices(_app=None): """Fetches all composite indices in the datastore for this app. Returns: list of entity_pb.CompositeIndex """ req = api_base_pb.StringProto() req.set_value(datastore_types.ResolveAppId(_app)) resp = datastore_pb.CompositeIndices() try: apiproxy_stub_map.MakeSyncCall('datastore_v3', 'GetIndices', req, resp) except apiproxy_errors.ApplicationError, err: raise datastore._ToDatastoreError(err)
def _Call(call, req, resp): """Generic method for making a datastore API call. Args: call: string, the name of the RPC call req: the request PB. if the app_id field is not set, it defaults to the local app. resp: the response PB """ if hasattr(req, 'app_id'): req.set_app_id(datastore_types.ResolveAppId(req.app_id(), 'req.app_id()')) try: apiproxy_stub_map.MakeSyncCall('datastore_v3', call, req, resp) except apiproxy_errors.ApplicationError, err: raise datastore._ToDatastoreError(err)
def _Call(call, req, resp): """Generic method for making a datastore API call. Args: call: string, the name of the RPC call req: the request PB. if the app_id field is not set, it defaults to the local app. resp: the response PB """ if hasattr(req, 'app_id'): req.set_app_id( datastore_types.ResolveAppId(req.app_id(), 'req.app_id()')) try: apiproxy_stub_map.MakeSyncCall('datastore_v3', call, req, resp) except apiproxy_errors.ApplicationError, err: raise datastore._ToDatastoreError(err)
def generic_rpc_handler(rpc): try: rpc.check_success() except apiproxy_errors.ApplicationError, err: raise _ToDatastoreError(err)
def next_rpc_handler(rpc): try: rpc.check_success() except apiproxy_errors.ApplicationError, err: logging.debug("next_rpc_handler") raise _ToDatastoreError(err)
def __TranslateError(error): """Translates a TaskQueueServiceError into an exception. Args: error: Value from TaskQueueServiceError enum. Raises: The corresponding Exception sub-class for that error code. """ if (error.application_error == taskqueue_service_pb.TaskQueueServiceError.UNKNOWN_QUEUE): raise UnknownQueueError(error.error_detail) elif (error.application_error == taskqueue_service_pb.TaskQueueServiceError.TRANSIENT_ERROR): raise TransientError(error.error_detail) elif (error.application_error == taskqueue_service_pb.TaskQueueServiceError.INTERNAL_ERROR): raise InternalError(error.error_detail) elif (error.application_error == taskqueue_service_pb.TaskQueueServiceError.TASK_TOO_LARGE): raise TaskTooLargeError(error.error_detail) elif (error.application_error == taskqueue_service_pb.TaskQueueServiceError.INVALID_TASK_NAME): raise InvalidTaskNameError(error.error_detail) elif (error.application_error == taskqueue_service_pb.TaskQueueServiceError.INVALID_QUEUE_NAME): raise InvalidQueueNameError(error.error_detail) elif (error.application_error == taskqueue_service_pb.TaskQueueServiceError.INVALID_URL): raise InvalidUrlError(error.error_detail) elif (error.application_error == taskqueue_service_pb.TaskQueueServiceError.INVALID_QUEUE_RATE): raise InvalidQueueError(error.error_detail) elif (error.application_error == taskqueue_service_pb.TaskQueueServiceError.PERMISSION_DENIED): raise PermissionDeniedError(error.error_detail) elif (error.application_error == taskqueue_service_pb.TaskQueueServiceError.TASK_ALREADY_EXISTS): raise TaskAlreadyExistsError(error.error_detail) elif (error.application_error == taskqueue_service_pb.TaskQueueServiceError.TOMBSTONED_TASK): raise TombstonedTaskError(error.error_detail) elif (error.application_error == taskqueue_service_pb.TaskQueueServiceError.INVALID_ETA): raise InvalidTaskError(error.error_detail) elif ((error.application_error >= taskqueue_service_pb.TaskQueueServiceError.DATASTORE_ERROR) and isinstance(error.application_error, int)): from google.appengine.api import datastore error.application_error = (error.application_error - taskqueue_service_pb.TaskQueueServiceError.DATASTORE_ERROR) datastore_exception = datastore._ToDatastoreError(error) class JointException(datastore_exception.__class__, DatastoreError): """There was a datastore error while accessing the queue.""" __msg = (u'taskqueue.DatastoreError caused by: %s %s' % (datastore_exception.__class__, error.error_detail)) def __str__(self): return JointException.__msg raise JointException else: raise Error('Application error %s: %s' % (error.application_error, error.error_detail))
def __TranslateError(error): """Translates a TaskQueueServiceError into an exception. Args: error: Value from TaskQueueServiceError enum. Raises: The corresponding Exception sub-class for that error code. """ if (error.application_error == taskqueue_service_pb.TaskQueueServiceError.UNKNOWN_QUEUE): raise UnknownQueueError(error.error_detail) elif (error.application_error == taskqueue_service_pb.TaskQueueServiceError.TRANSIENT_ERROR): raise TransientError(error.error_detail) elif (error.application_error == taskqueue_service_pb.TaskQueueServiceError.INTERNAL_ERROR): raise InternalError(error.error_detail) elif (error.application_error == taskqueue_service_pb.TaskQueueServiceError.TASK_TOO_LARGE): raise TaskTooLargeError(error.error_detail) elif (error.application_error == taskqueue_service_pb.TaskQueueServiceError.INVALID_TASK_NAME): raise InvalidTaskNameError(error.error_detail) elif (error.application_error == taskqueue_service_pb.TaskQueueServiceError.INVALID_QUEUE_NAME): raise InvalidQueueNameError(error.error_detail) elif (error.application_error == taskqueue_service_pb.TaskQueueServiceError.INVALID_URL): raise InvalidUrlError(error.error_detail) elif (error.application_error == taskqueue_service_pb.TaskQueueServiceError.INVALID_QUEUE_RATE): raise InvalidQueueError(error.error_detail) elif (error.application_error == taskqueue_service_pb.TaskQueueServiceError.PERMISSION_DENIED): raise PermissionDeniedError(error.error_detail) elif (error.application_error == taskqueue_service_pb.TaskQueueServiceError.TASK_ALREADY_EXISTS): raise TaskAlreadyExistsError(error.error_detail) elif (error.application_error == taskqueue_service_pb.TaskQueueServiceError.TOMBSTONED_TASK): raise TombstonedTaskError(error.error_detail) elif (error.application_error == taskqueue_service_pb.TaskQueueServiceError.INVALID_ETA): raise InvalidTaskError(error.error_detail) elif ((error.application_error >= taskqueue_service_pb.TaskQueueServiceError.DATASTORE_ERROR) and isinstance(error.application_error, int)): from google.appengine.api import datastore error.application_error = ( error.application_error - taskqueue_service_pb.TaskQueueServiceError.DATASTORE_ERROR) datastore_exception = datastore._ToDatastoreError(error) class JointException(datastore_exception.__class__, DatastoreError): """There was a datastore error while accessing the queue.""" __msg = (u'taskqueue.DatastoreError caused by: %s %s' % (datastore_exception.__class__, error.error_detail)) def __str__(self): return JointException.__msg raise JointException else: raise Error('Application error %s: %s' % (error.application_error, error.error_detail))