from flexget.manager import Session


def with_session(func):
    """"Creates a session if one was not passed via keyword argument to the function"""

    def wrapper(*args, **kwargs):
        passed_session = kwargs.get('session')
        if not passed_session:
            session = Session(autoflush=True)
            try:
                return func(*args, session=session, **kwargs)
            finally:
                session.close()
        else:
            return func(*args, **kwargs)
    return wrapper

from flexget.manager import Session


def with_session(func):
    """"Creates a session if one was not passed via keyword argument to the function"""

    def wrapper(*args, **kwargs):
        if not kwargs.get('session'):
            kwargs['session'] = Session(autoflush=True)
            try:
                return func(*args, **kwargs)
            finally:
                kwargs['session'].close()
        else:
            return func(*args, **kwargs)
    return wrapper

Fix with_session decorator for python 2.5
Fix with_session decorator for python 2.5

git-svn-id: ad91b9aa7ba7638d69f912c9f5d012e3326e9f74@1957 3942dd89-8c5d-46d7-aeed-044bccf3e60c
