コード例 #1
0
ファイル: component.py プロジェクト: altophen/autobahn-python
 def on_leave(session, details):
     self.log.info(
         "session leaving '{details.reason}'",
         details=details,
     )
     if self._entry and not txaio.is_called(done):
         txaio.resolve(done, None)
コード例 #2
0
 def on_leave(session, details):
     self.log.info(
         "session leaving '{details.reason}'",
         details=details,
     )
     if self._entry and not txaio.is_called(done):
         txaio.resolve(done, None)
コード例 #3
0
 def on_leave(session, details):
     self.log.debug("session on_leave: {details}", details=details)
     # this could be a "leave" that's expected e.g. our
     # main() exited, or it could be an error
     if not txaio.is_called(done):
         if details.reason.startswith('wamp.error.'):
             txaio.reject(done, ApplicationError(details.reason, details.message))
         else:
             txaio.resolve(done, None)
コード例 #4
0
 def lost(fail):
     rtn = orig(fail)
     if not txaio.is_called(done):
         # asyncio will call connection_lost(None) in case of
         # a transport failure, in which case we create an
         # appropriate exception
         if fail is None:
             fail = TransportLost("failed to complete connection")
         txaio.reject(done, fail)
     return rtn
コード例 #5
0
 def lost(fail):
     rtn = orig(fail)
     if not txaio.is_called(done):
         # asyncio will call connection_lost(None) in case of
         # a transport failure, in which case we create an
         # appropriate exception
         if fail is None:
             fail = TransportLost("failed to complete connection")
         txaio.reject(done, fail)
     return rtn
コード例 #6
0
ファイル: component.py プロジェクト: yongyuwh/autobahn-python
 def on_disconnect(session, was_clean):
     self.log.debug(
         "session on_disconnect: was_clean={was_clean}",
         was_clean=was_clean,
     )
     if not txaio.is_called(done):
         if not was_clean:
             self.log.warn(u"Session disconnected uncleanly")
         # eg the session has left the realm, and the transport was properly
         # shut down. successfully finish the connection
         txaio.resolve(done, None)
コード例 #7
0
ファイル: component.py プロジェクト: marc1n/autobahn-python
 def on_error(err):
     """
     this may seem redundant after looking at _connect_transport, but
     it will handle a case where something goes wrong in
     _connect_transport itself -- as the only connect our
     caller has is the 'done' future
     """
     transport.connect_failures += 1
     # something bad has happened, and maybe didn't get caught
     # upstream yet
     if not txaio.is_called(done):
         txaio.reject(done, err)
コード例 #8
0
 def on_disconnect(session, was_clean):
     self.log.debug(
         "session on_disconnect: was_clean={was_clean}",
         was_clean=was_clean,
     )
     if not txaio.is_called(done):
         if was_clean:
             # eg the session has left the realm, and the transport was properly
             # shut down. successfully finish the connection
             txaio.resolve(done, None)
         else:
             txaio.reject(done, RuntimeError('transport closed uncleanly'))
コード例 #9
0
ファイル: component.py プロジェクト: marc1n/autobahn-python
 def on_leave(session, details):
     self.log.info(
         "session leaving '{details.reason}'",
         details=details,
     )
     if not txaio.is_called(done):
         if details.reason in [u"wamp.close.normal"]:
             txaio.resolve(done, None)
         else:
             f = txaio.create_failure(
                 ApplicationError(details.reason))
             txaio.reject(done, f)
コード例 #10
0
ファイル: component.py プロジェクト: potens1/autobahn-python
 def on_error(err):
     """
     this may seem redundant after looking at _connect_transport, but
     it will handle a case where something goes wrong in
     _connect_transport itself -- as the only connect our
     caller has is the 'done' future
     """
     transport.connect_failures += 1
     # something bad has happened, and maybe didn't get caught
     # upstream yet
     if not txaio.is_called(done):
         txaio.reject(done, err)
コード例 #11
0
    async def onJoin(self, details):  # noqa: N802
        self.log.info('{klass}.onJoin(details={details})',
                      klass=self.__class__.__name__,
                      details=details)

        done = self.config.extra.get('done', None)

        result = None
        error = None
        if self._command:
            self.log.info('{klass}: running command {command}',
                          klass=self.__class__.__name__,
                          command=self._command)
            try:
                result = await self._command.run(self)
                self.log.info('command run with result {result}',
                              result=result)
            except Exception as e:
                self.log.warn('command failed: {error}', error=e)
                error = e
        elif self._main:
            self.log.info('{klass}: running main function {main}',
                          klass=self.__class__.__name__,
                          main=self._main)
            try:
                result = await self._main(self)
                self.log.info('main run with result {result}', result=result)
            except Exception as e:
                self.log.warn('main failed: {error}', error=e)
                error = e
        else:
            self.log.info('{klass}: no command or main function to run!',
                          klass=self.__class__.__name__)

        if done and not txaio.is_called(done):
            if error:
                self.log.warn('{klass}: command returned with error ({error})',
                              klass=self.__class__.__name__,
                              error=error)
                txaio.reject(done, error)
            else:
                self.log.info(
                    '{klass}: command returned with success ({result})',
                    klass=self.__class__.__name__,
                    result=result)
                txaio.resolve(done, (details, result))

        self.log.info('{klass}.onJoin(): finished!',
                      klass=self.__class__.__name__)

        if self._main:
            self.leave()
コード例 #12
0
 def on_leave(session, details):
     self.log.debug("session on_leave: {details}",
                    details=details)
     # this could be a "leave" that's expected e.g. our
     # main() exited, or it could be an error
     if not txaio.is_called(done):
         if details.reason.startswith('wamp.error.'):
             txaio.reject(
                 done,
                 ApplicationError(details.reason,
                                  details.message))
         else:
             txaio.resolve(done, None)
コード例 #13
0
ファイル: component.py プロジェクト: potens1/autobahn-python
 def on_leave(session, details):
     self.log.info(
         "session leaving '{details.reason}'",
         details=details,
     )
     if not txaio.is_called(done):
         if details.reason in [u"wamp.close.normal"]:
             txaio.resolve(done, None)
         else:
             f = txaio.create_failure(
                 ApplicationError(details.reason)
             )
             txaio.reject(done, f)
コード例 #14
0
ファイル: component.py プロジェクト: Hrabal/autobahn-python
 def on_disconnect(session, was_clean):
     self.log.debug(
         "session on_disconnect: was_clean={was_clean}",
         was_clean=was_clean,
     )
     if not txaio.is_called(done):
         if not was_clean:
             self.log.warn(
                 u"Session disconnected uncleanly"
             )
         # eg the session has left the realm, and the transport was properly
         # shut down. successfully finish the connection
         txaio.resolve(done, None)
コード例 #15
0
ファイル: component.py プロジェクト: Hrabal/autobahn-python
 def on_leave(session, details):
     self.log.info(
         "session leaving '{details.reason}'",
         details=details,
     )
     if not txaio.is_called(done):
         if details.reason in [u"wamp.error.no_auth_method"]:
             txaio.resolve(done, txaio.create_failure(
                 ApplicationError(
                     u"wamp.error.no_auth_method"
                 )
             ))
         else:
             txaio.resolve(done, None)
コード例 #16
0
ファイル: component.py プロジェクト: altophen/autobahn-python
 def on_disconnect(session, was_clean):
     self.log.debug(
         "session on_disconnect: was_clean={was_clean}",
         was_clean=was_clean,
     )
     if not txaio.is_called(done):
         if was_clean:
             # eg the session has left the realm, and the transport was properly
             # shut down. successfully finish the connection
             txaio.resolve(done, None)
         else:
             txaio.reject(
                 done,
                 RuntimeError('transport closed uncleanly'))
コード例 #17
0
 def on_leave(session, details):
     self.log.info(
         "session leaving '{details.reason}'",
         details=details,
     )
     if not txaio.is_called(done):
         if details.reason in [u"wamp.error.no_auth_method"]:
             txaio.resolve(done, txaio.create_failure(
                 ApplicationError(
                     u"wamp.error.no_auth_method"
                 )
             ))
         else:
             txaio.resolve(done, None)
コード例 #18
0
ファイル: component.py プロジェクト: marc1n/autobahn-python
 def stop(self):
     self._stopping = True
     if self._session and self._session.is_attached():
         return self._session.leave()
     elif self._delay_f:
         # This cancel request will actually call the "error" callback of
         # the _delay_f future. Nothing to worry about.
         return txaio.as_future(txaio.cancel, self._delay_f)
     # if (for some reason -- should we log warning here to figure
     # out if this can evern happen?) we've not fired _done_f, we
     # do that now (causing our "main" to exit, and thus react() to
     # quit)
     if not txaio.is_called(self._done_f):
         txaio.resolve(self._done_f, None)
     return txaio.create_future_success(None)
コード例 #19
0
ファイル: component.py プロジェクト: potens1/autobahn-python
 def stop(self):
     self._stopping = True
     if self._session and self._session.is_attached():
         return self._session.leave()
     elif self._delay_f:
         # This cancel request will actually call the "error" callback of
         # the _delay_f future. Nothing to worry about.
         return txaio.as_future(txaio.cancel, self._delay_f)
     # if (for some reason -- should we log warning here to figure
     # out if this can evern happen?) we've not fired _done_f, we
     # do that now (causing our "main" to exit, and thus react() to
     # quit)
     if not txaio.is_called(self._done_f):
         txaio.resolve(self._done_f, None)
     return txaio.create_future_success(None)
コード例 #20
0
    def onLeave(self, details):  # noqa: N802
        self.log.info('{klass}.onLeave(details={details})',
                      klass=self.__class__.__name__,
                      details=details)

        # reason=<wamp.error.authentication_failed>
        if details.reason != 'wamp.close.normal':
            done = self.config.extra.get('done', None)
            error = ApplicationError(details.reason, details.message)
            if done and not txaio.is_called(done):
                self.log.warn('{klass}: command returned with error ({error})',
                              klass=self.__class__.__name__,
                              error=error)
                txaio.reject(done, error)

        self.disconnect()
コード例 #21
0
        def on_connect_success(result):
            # async connect call returns a 2-tuple
            transport, proto = result

            # in the case where we .abort() the transport / connection
            # during setup, we still get on_connect_success but our
            # transport is already closed (this will happen if
            # e.g. there's an "open handshake timeout") -- I don't
            # know if there's a "better" way to detect this? #python
            # doesn't know of one, anyway
            if transport.is_closing():
                if not txaio.is_called(done):
                    reason = getattr(proto, "_onclose_reason",
                                     "Connection already closed")
                    txaio.reject(done, TransportLost(reason))
                return

            # if e.g. an SSL handshake fails, we will have
            # successfully connected (i.e. get here) but need to
            # 'listen' for the "connection_lost" from the underlying
            # protocol in case of handshake failure .. so we wrap
            # it. Also, we don't increment transport.success_count
            # here on purpose (because we might not succeed).

            # XXX double-check that asyncio behavior on TLS handshake
            # failures is in fact as described above
            orig = proto.connection_lost

            @wraps(orig)
            def lost(fail):
                rtn = orig(fail)
                if not txaio.is_called(done):
                    # asyncio will call connection_lost(None) in case of
                    # a transport failure, in which case we create an
                    # appropriate exception
                    if fail is None:
                        fail = TransportLost("failed to complete connection")
                    txaio.reject(done, fail)
                return rtn

            proto.connection_lost = lost
コード例 #22
0
 def lost(fail):
     rtn = orig(fail)
     if not txaio.is_called(done):
         txaio.reject(done, fail)
     return rtn
コード例 #23
0
def test_is_called(framework):
    f = txaio.create_future_success(None)
    assert txaio.is_called(f)
コード例 #24
0
ファイル: component.py プロジェクト: Hrabal/autobahn-python
 def lost(fail):
     rtn = orig(fail)
     if not txaio.is_called(done):
         txaio.reject(done, fail)
     return rtn