<s> def establish_session ( original_function ) : <EOL> '''<STR_LIT>''' <EOL> def new_function ( self , * args , ** kwargs ) : <EOL> from importlib import import_module <EOL> from django . conf import settings <EOL> engine = import_module ( settings . SESSION_ENGINE ) <EOL> store = engine . SessionStore ( ) <EOL> store . save ( ) <EOL> self . client . cookies [ settings . SESSION_COOKIE_NAME ] = store . session_key <EOL> self . session_key = store . session_key <EOL> original_function ( self , * args , ** kwargs ) <EOL> return new_function <EOL> def get_user_model ( ) : <EOL> try : <EOL> from django . contrib . auth import get_user_model <EOL> except ImportError : <EOL> from django . contrib . auth . models import User <EOL> return User <EOL> else : <EOL> return get_user_model ( ) <EOL> def create_random_temporary_file ( ) : <EOL> '''<STR_LIT>''' <EOL> def random_line ( ) : <EOL> import random , string <EOL> return '<STR_LIT>' . join ( random . choice ( string . ascii_letters ) for x in range ( <NUM_LIT> ) ) <EOL> import tempfile <EOL> with tempfile . NamedTemporaryFile ( '<STR_LIT:w>' , delete = False ) as f : <EOL> f . write ( '<STR_LIT:\n>' . join ( random_line ( ) for x in range ( <NUM_LIT:30> ) ) ) <EOL> return f . name </s>
