<s> from werkzeug import Client as WerkZeugClient <EOL> from werkzeug import EnvironBuilder <EOL> from kay . utils import local <EOL> from jinja2 import Template <EOL> wrapped = False <EOL> render_orig = Template . render <EOL> class Client ( WerkZeugClient ) : <EOL> def __init__ ( self , application , response_wrapper = None , use_cookies = True ) : <EOL> super ( Client , self ) . __init__ ( application , <EOL> response_wrapper = response_wrapper , <EOL> use_cookies = True ) <EOL> builder = EnvironBuilder ( ) <EOL> try : <EOL> env = builder . get_environ ( ) <EOL> finally : <EOL> builder . close ( ) <EOL> self . application . app . _prepare ( env ) <EOL> for key , submount_app in self . application . mounts . iteritems ( ) : <EOL> if not hasattr ( submount_app , '<STR_LIT>' ) or key == "<STR_LIT>" : <EOL> continue <EOL> submount_app . _prepare ( env ) <EOL> def test_logout ( self , target_url = '<STR_LIT:/>' , ** kwargs ) : <EOL> self . test_login_or_logout ( '<STR_LIT>' , target_url = target_url , ** kwargs ) <EOL> def test_login ( self , target_url = '<STR_LIT:/>' , ** kwargs ) : <EOL> self . test_login_or_logout ( '<STR_LIT>' , target_url = target_url , ** kwargs ) <EOL> def test_login_or_logout ( self , method , target_url = '<STR_LIT:/>' , ** kwargs ) : <EOL> auth_backend = None <EOL> for key , submount_app in self . application . mounts . iteritems ( ) : <EOL> if not hasattr ( submount_app , '<STR_LIT>' ) or key == "<STR_LIT>" : <EOL> continue <EOL> if target_url . startswith ( key ) and hasattr ( submount_app , "<STR_LIT>" ) : <EOL> auth_backend = submount_app . auth_backend <EOL> if auth_backend is None and hasattr ( self . application . app , "<STR_LIT>" ) : <EOL> auth_backend = self . application . app . auth_backend <EOL> if auth_backend is None : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> try : <EOL> meth = getattr ( auth_backend , method ) <EOL> meth ( self , ** kwargs ) <EOL> except Exception , e : <EOL> raise <EOL> raise RuntimeError ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( method , auth_backend , e ) ) <EOL> def wrapper ( self , * args , ** kwargs ) : <EOL> vars = dict ( * args , ** kwargs ) <EOL> local . _used_templates . append ( self . name ) <EOL> local . _used_contexts . append ( vars ) <EOL> return render_orig ( self , * args , ** kwargs ) <EOL> def init_recordings ( ) : <EOL> local . _used_templates = [ ] <EOL> local . _used_contexts = [ ] <EOL> def disable_recording ( ) : <EOL> init_recordings ( ) <EOL> global wrapped <EOL> if wrapped : <EOL> Template . render = render_orig <EOL> wrapped = False <EOL> def init_recording ( ) : <EOL> init_recordings ( ) <EOL> global wrapped <EOL> if not wrapped : <EOL> Template . render = wrapper <EOL> wrapped = True <EOL> def get_templates ( ) : <EOL> if not hasattr ( local , '<STR_LIT>' ) : <EOL> local . _used_templates = [ ] <EOL> return local . _used_templates <EOL> def get_last_template ( ) : <EOL> templates = get_templates ( ) <EOL> if templates : <EOL> return templates [ - <NUM_LIT:1> ] <EOL> def get_contexts ( ) : <EOL> if not hasattr ( local , '<STR_LIT>' ) : <EOL> local . _used_contexts = [ ] <EOL> return local . _used_contexts <EOL> def get_last_context ( ) : <EOL> contexts = get_contexts ( ) <EOL> if contexts : <EOL> return contexts [ - <NUM_LIT:1> ] </s>
