예제 #1
0
    def _MakeCallImpl(self):
        assert isinstance(
            self.request, ProtocolBuffer.ProtocolMessage
        ), 'not isinstance(%r, %r): sys.modules=%r, sys.path=%r' % (
            self.request.__class__, ProtocolBuffer.ProtocolMessage,
            sys.modules, sys.path)
        assert isinstance(
            self.response, ProtocolBuffer.ProtocolMessage
        ), 'not isinstance(%r, %r): sys.modules=%r, sys.path=%r' % (
            self.response.__class__, ProtocolBuffer.ProtocolMessage,
            sys.modules, sys.path)

        e = ProtocolBuffer.Encoder()
        self.request.Output(e)

        self.__state = RPC.RUNNING

        _apphosting_runtime___python__apiproxy.MakeCall(self.package,
                                                        self.call,
                                                        e.buffer(),
                                                        self.__result_dict,
                                                        self.__MakeCallDone,
                                                        self,
                                                        deadline=(self.deadline
                                                                  or -1))
예제 #2
0
    def _MakeCallImpl(self):
        assert isinstance(
            self.request, PROTO_BASE_CLASSES
        ), 'not isinstance(%r, %r): sys.modules=%r, sys.path=%r' % (
            self.request.__class__, PROTO_BASE_CLASSES, sys.modules, sys.path)
        assert isinstance(
            self.response, PROTO_BASE_CLASSES
        ), 'not isinstance(%r, %r): sys.modules=%r, sys.path=%r' % (
            self.response.__class__, PROTO_BASE_CLASSES, sys.modules, sys.path)

        if isinstance(self.request, ProtocolBuffer.ProtocolMessage):
            e = ProtocolBuffer.Encoder()
            self.request.Output(e)
            request_data = e.buffer()
        else:
            request_data = self.request.SerializeToString()

        self.__state = RPC.RUNNING

        _apphosting_runtime___python__apiproxy.MakeCall(self.package,
                                                        self.call,
                                                        request_data,
                                                        self.__result_dict,
                                                        self.__MakeCallDone,
                                                        self,
                                                        deadline=(self.deadline
                                                                  or -1))
예제 #3
0
    def MakeCall(self,
                 package=None,
                 call=None,
                 request=None,
                 response=None,
                 callback=None):
        """Makes an asynchronous (i.e. non-blocking) API call within the
    specified package for the specified call method. request and response must
    be the appropriately typed ProtocolBuffers for the API call.
    callback, if provided, will be called when the request completes
    successfully or when an error occurs.  If an error has ocurred, the
    exception() method on this class will return the error, which can be
    accessed from the callback.

    Args:
      Same as constructor; see __init__.

    Raises:
      TypeError or AssertionError if an argument is of an invalid type.
      AssertionError or RuntimeError is an RPC is already in use.
    """
        self.callback = callback or self.callback
        self.package = package or self.package
        self.call = call or self.call
        self.request = request or self.request
        self.response = response or self.response

        assert self.__state is RPC.IDLE, (
            "RPC for %s.%s has already been started" %
            (self.package, self.call))
        assert self.callback is None or callable(self.callback)
        assert isinstance(self.request, ProtocolBuffer.ProtocolMessage)
        assert isinstance(self.response, ProtocolBuffer.ProtocolMessage)

        e = ProtocolBuffer.Encoder()
        self.request.Output(e)

        self.__state = RPC.RUNNING
        _apphosting_runtime___python__apiproxy.MakeCall(
            self.package, self.call, e.buffer(), self.__result_dict,
            self.__MakeCallDone, self)