<s> from flask import ( session , g , request_started , current_app ) <EOL> from contextlib import contextmanager <EOL> def auth_onrequest ( sender ) : <EOL> backend = current_app . config [ '<STR_LIT>' ] <EOL> try : <EOL> auth_key = session [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> return <EOL> user = backend . load_user ( auth_key ) <EOL> g . user = user <EOL> @ contextmanager <EOL> def setup ( app ) : <EOL> request_started . connect ( auth_onrequest , app ) <EOL> @ app . context_processor <EOL> def auth_context_processor ( ) : <EOL> try : <EOL> return { '<STR_LIT:user>' : g . user } <EOL> except AttributeError : <EOL> return { } <EOL> yield app </s>
