Esempio n. 1
0
    def GenerationMethod(resolve, reject):
      message = _GetMessage(method, flags, None, *args, **kwargs)
      if method.response_struct:
        def Accept(message):
          try:
            assert message.header.message_type == method.ordinal
            payload = message.payload
            response = method.response_struct.Deserialize(
                serialization.RootDeserializationContext(payload.data,
                                                         payload.handles))
            as_dict = response.AsDict()
            if len(as_dict) == 1:
              value = as_dict.values()[0]
              if not isinstance(value, dict):
                response = value
            resolve(response)
            return True
          except Exception as e:
            # Adding traceback similarly to python 3.0 (pep-3134)
            e.__traceback__ = sys.exc_info()[2]
            reject(e)
            return False
          finally:
            self._error_handler.RemoveCallback(reject)

        self._error_handler.AddCallback(reject)
        if not self._router.AcceptWithResponder(
            message, messaging.ForwardingMessageReceiver(Accept)):
          self._error_handler.RemoveCallback(reject)
          reject(messaging.MessagingException("Unable to send message."))
      else:
        if (self._router.Accept(message)):
          resolve(None)
        else:
          reject(messaging.MessagingException("Unable to send message."))
Esempio n. 2
0
 def OnError(self, result):
     if self._callbacks is None:
         return
     exception = messaging.MessagingException('Mojo error: %d' % result)
     for (callback, _) in self._callbacks.iteritems():
         callback(exception)
     self._callbacks = None
Esempio n. 3
0
 def OnClose(self):
     if self._callbacks is None:
         return
     exception = messaging.MessagingException('Router has been closed.')
     for (callback, call_on_close) in self._callbacks.iteritems():
         if call_on_close:
             callback(exception)
     self._callbacks = None
Esempio n. 4
0
 def OnError(self, result):
     exception = messaging.MessagingException('Mojo error: %d' % result)
     for callback in list(self._callbacks):
         callback(exception)
     self._callbacks = None