def provide_session(func):
 @wraps(func)
 def wrapper(*args, **kwargs):
  needs_session = False
  arg_session = u'session'
  func_params = func.__code__.co_varnames
  session_in_args = ((arg_session in func_params) and (func_params.index(arg_session) < len(args)))
  if (not ((arg_session in kwargs) or session_in_args)):
   needs_session = True
   session = settings.Session()
   kwargs[arg_session] = session
  result = func(*args, **kwargs)
  if needs_session:
   session.expunge_all()
   session.commit()
   session.close()
  return result
 return wrapper

def provide_session ( func ) : @ wraps ( func ) def wrapper ( * args , ** kwargs ) : needs_session = False arg_session = u'session' func_params = func . __code__ . co_varnames session_in_args = ( ( arg_session in func_params ) and ( func_params . index ( arg_session ) < len ( args ) ) ) if ( not ( ( arg_session in kwargs ) or session_in_args ) ) : needs_session = True session = settings . Session ( ) kwargs [ arg_session ] = session result = func ( * args , ** kwargs ) if needs_session : session . expunge_all ( ) session . commit ( ) session . close ( ) return result return wrapper
function decorator that provides a session if it isnt provided .