def blocking(f, app_name, result_cb, error_cb): """Run f in a thread; return or throw an exception thru the callbacks.""" d = deferToThread(f) # the calls in twisted will be called with the args in a diff order, # in order to follow the linux api, we swap them around with a lambda d.addCallback(lambda result, app: result_cb(app, result), app_name) d.addErrback(lambda err, app: error_cb(app, except_to_errdict(err.value)), app_name)
def _in_thread(): """The part that runs inside the thread.""" try: result_cb(app_name, f()) except Exception, e: # pylint: disable=W0703 msg = "Exception while running DBus blocking code in a thread:" logger.exception(msg) error_cb(app_name, except_to_errdict(e))
def f(*args): """Process arguments and call remote.""" try: args = list(args) if args: args[-1] = except_to_errdict(args[-1].value) return handler.callRemote('execute', *args) # Yes, I want to catch everything # pylint: disable=W0703 except Exception: logger.exception("Remote handler argument processing error:")
def _process_failure(self, failure, app_name): """Process the 'failure' and emit CredentialsError.""" self.emit_credentials_error(app_name, except_to_errdict(failure.value))
def emit_password_change_error(self, app_name, raised_error): """Signal thrown when there's a problem sending the token.""" logger.debug('SSOLogin: emitting PasswordChangeError with ' 'app_name "%s" and error %r', app_name, raised_error) self.emit_signal('on_password_change_error', app_name, except_to_errdict(raised_error.value))
def emit_email_validation_error(self, app_name, raised_error): """Signal thrown when there's a problem validating the email.""" logger.debug('SSOLogin: emitting EmailValidationError with ' 'app_name "%s" and error %r', app_name, raised_error) self.emit_signal('on_email_validation_error', app_name, except_to_errdict(raised_error.value))
def emit_login_error(self, app_name, raised_error): """Signal thrown when there is a problem in the login.""" logger.debug('SSOLogin: emitting LoginError with ' 'app_name "%s" and error %r', app_name, raised_error) self.emit_signal('on_login_error', app_name, except_to_errdict(raised_error.value))
def emit_user_registration_error(self, app_name, raised_error): """Signal thrown when there's a problem registering the user.""" logger.debug('SSOLogin: emitting UserRegistrationError with ' 'app_name "%s" and error %r', app_name, raised_error) self.emit_signal('on_user_registration_error', app_name, except_to_errdict(raised_error.value))
def emit_captcha_generation_error(self, app_name, raised_error): """Signal thrown when there's a problem generating the captcha.""" logger.debug('SSOLogin: emitting CaptchaGenerationError with ' 'app_name "%s" and error %r', app_name, raised_error) self.emit_signal('on_captcha_generation_error', app_name, except_to_errdict(raised_error.value))