<s> from . tokens import get_request_token <EOL> class SessionMiddleware ( object ) : <EOL> def process_request ( self , request ) : <EOL> if getattr ( request , '<STR_LIT:user>' , None ) and request . user . is_authenticated ( ) : <EOL> return <EOL> if get_request_token ( request ) : <EOL> request . csrf_processing_done = True <EOL> return <EOL> session = request . session <EOL> if session . session_key is None : <EOL> if session . test_cookie_worked ( ) : <EOL> session . delete_test_cookie ( ) <EOL> request . session . create ( ) <EOL> else : <EOL> session . set_test_cookie ( ) </s>
