authomatic/providers/__init__.py
def login_decorator(func):
    """
    Decorate the :meth:`.BaseProvider.login` implementations with this
    decorator.

    Provides mechanism for error reporting and returning result which
    makes the :meth:`.BaseProvider.login` implementation cleaner.

    """

    def wrap(provider, *args, **kwargs):
        error = None
        result = authomatic.core.LoginResult(provider)

        try:
            func(provider, *args, **kwargs)
        except Exception as e:  # pylint:disable=broad-except
            if provider.settings.report_errors:
                error = e
                if not isinstance(error, CancellationError):
                    provider._log(
                        logging.ERROR,
                        u'Reported suppressed exception: {0}!'.format(
                            repr(error)),
                        exc_info=1)
            else:
                if provider.settings.debug:
                    # TODO: Check whether it actually works without middleware
                    provider.write(
                        _error_traceback_html(
                            sys.exc_info(),
                            traceback.format_exc()))
                raise

        # If there is user or error the login procedure has finished
        if provider.user or error:
            result = authomatic.core.LoginResult(provider)
            # Add error to result
            result.error = error

            # delete session cookie
            if isinstance(provider.session, authomatic.core.Session):
                provider.session.delete()

            provider._log(logging.INFO, u'Procedure finished.')

            if provider.callback:
                provider.callback(result)
            return result
        else:
            # Save session
            provider.save_session()

    return wrap
def login_decorator(func):
    """
    Decorate the :meth:`.BaseProvider.login` implementations with this
    decorator.

    Provides mechanism for error reporting and returning result which
    makes the :meth:`.BaseProvider.login` implementation cleaner.

    """

    def wrap(provider, *args, **kwargs):
        error = None
        result = authomatic.core.LoginResult(provider)

        try:
            func(provider, *args, **kwargs)
        except Exception as e:  # pylint:disable=broad-except
            if provider.settings.report_errors:
                error = e
                if not isinstance(error, CancellationError):
                    provider._log(
                        logging.ERROR,
                        u'Reported suppressed exception: {0}!'.format(
                            repr(error)),
                        exc_info=1)
            else:
                if provider.settings.debug:
                    # TODO: Check whether it actually works without middleware
                    provider.write(
                        _error_traceback_html(
                            sys.exc_info(),
                            traceback.format_exc()))
                raise

        # If there is user or error the login procedure has finished
        if provider.user or error:
            result = authomatic.core.LoginResult(provider)
            # Add error to result
            result.error = error

            # delete session cookie
            if isinstance(provider.session, authomatic.core.Session):
                provider.session.delete()

            provider._log(logging.INFO, u'Procedure finished.')

            if provider.callback:
                provider.callback(result)
            return result
        else:
            # Save session
            provider.save_session()

    return wrap
def login_decorator ( func ) : def wrap ( provider , * args , * * kwargs ) : error = None result = authomatic . core . LoginResult ( provider ) try : func ( provider , * args , * * kwargs ) except Exception as e : # pylint:disable=broad-except if provider . settings . report_errors : error = e if not isinstance ( error , CancellationError ) : provider . _log ( logging . ERROR , u'Reported suppressed exception: {0}!' . format ( repr ( error ) ) , exc_info = 1 ) else : if provider . settings . debug : # TODO: Check whether it actually works without middleware provider . write ( _error_traceback_html ( sys . exc_info ( ) , traceback . format_exc ( ) ) ) raise # If there is user or error the login procedure has finished if provider . user or error : result = authomatic . core . LoginResult ( provider ) # Add error to result result . error = error # delete session cookie if isinstance ( provider . session , authomatic . core . Session ) : provider . session . delete ( ) provider . _log ( logging . INFO , u'Procedure finished.' ) if provider . callback : provider . callback ( result ) return result else : # Save session provider . save_session ( ) return wrap
Decorate the :meth:`.BaseProvider.login` implementations with this
    decorator.

    Provides mechanism for error reporting and returning result which
    makes the :meth:`.BaseProvider.login` implementation cleaner.
Decorate the : meth : . BaseProvider . login implementations with this decorator .