<s> from __future__ import absolute_import <EOL> import sys <EOL> def format_var ( name , obj ) : <EOL> if '<STR_LIT:password>' in name and isinstance ( obj , str ) : <EOL> obj = '<STR_LIT>' <EOL> res = repr ( obj ) <EOL> if len ( res ) > <NUM_LIT> and not env . verbose : <EOL> if isinstance ( obj , list ) : <EOL> noun = '<STR_LIT>' if len ( obj ) != <NUM_LIT:1> else '<STR_LIT>' <EOL> res = '<STR_LIT>' . format ( len ( obj ) , noun ) <EOL> elif isinstance ( obj , dict ) : <EOL> noun = '<STR_LIT>' if len ( obj ) != <NUM_LIT:1> else '<STR_LIT>' <EOL> res = '<STR_LIT>' . format ( len ( obj ) , noun ) <EOL> else : <EOL> res = res [ : <NUM_LIT> ] + '<STR_LIT>' + res [ - <NUM_LIT:1> ] <EOL> return res <EOL> def stack_vars ( stack ) : <EOL> """<STR_LIT>""" <EOL> result = [ ] <EOL> names = set ( ) <EOL> for scope in stack : <EOL> for name in scope : <EOL> names . add ( name ) <EOL> def get_var ( name ) : <EOL> depth = len ( stack ) <EOL> for scope in reversed ( stack ) : <EOL> depth -= <NUM_LIT:1> <EOL> if name in scope : <EOL> return depth , scope [ name ] <EOL> for name in sorted ( names ) : <EOL> depth , value = get_var ( name ) <EOL> result . append ( ( name , format_var ( name , value ) , depth ) ) <EOL> return result <EOL> class _Scope ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , env , kwargs ) : <EOL> self . env = env <EOL> self . kwargs = kwargs <EOL> def __enter__ ( self ) : <EOL> envdata = self . env . __dict__ <EOL> envdata [ '<STR_LIT>' ] . append ( self . kwargs ) <EOL> def __exit__ ( self , * exc_info ) : <EOL> envdata = self . env . __dict__ <EOL> if sys . exc_info ( ) [ <NUM_LIT:1> ] and envdata [ '<STR_LIT>' ] is not sys . exc_info ( ) [ <NUM_LIT:1> ] : <EOL> envdata [ '<STR_LIT>' ] = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> envdata [ '<STR_LIT>' ] = envdata [ '<STR_LIT>' ] [ : ] <EOL> envdata [ '<STR_LIT>' ] . pop ( ) <EOL> start = __enter__ <EOL> stop = __exit__ <EOL> class _Swapper ( object ) : <EOL> def __init__ ( self , cur , new ) : <EOL> self . _cur = cur <EOL> self . _new = new <EOL> def __enter__ ( self ) : <EOL> for key in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> tmp = self . _cur . __dict__ [ key ] <EOL> self . _cur . __dict__ [ key ] = self . _new . __dict__ [ key ] <EOL> self . _new . __dict__ [ key ] = tmp <EOL> def __exit__ ( self , * exc_info ) : <EOL> for key in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> tmp = self . _cur . __dict__ [ key ] <EOL> self . _cur . __dict__ [ key ] = self . _new . __dict__ [ key ] <EOL> self . _new . __dict__ [ key ] = tmp <EOL> class _Environment ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ** kwargs ) : <EOL> self . __dict__ [ '<STR_LIT>' ] = [ kwargs ] <EOL> self . __dict__ [ '<STR_LIT>' ] = None <EOL> self . __dict__ [ '<STR_LIT>' ] = [ ] <EOL> def __getattr__ ( self , name ) : <EOL> stack = self . __dict__ [ '<STR_LIT>' ] <EOL> for scope in reversed ( stack ) : <EOL> if name in scope : <EOL> return scope [ name ] <EOL> raise AttributeError ( name ) <EOL> def __setattr__ ( self , name , value ) : <EOL> """<STR_LIT>""" <EOL> stack = self . __dict__ [ '<STR_LIT>' ] <EOL> stack [ <NUM_LIT:0> ] [ name ] = value <EOL> def let ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> for key in kwargs : <EOL> if key . startswith ( '<STR_LIT:_>' ) : <EOL> msg = "<STR_LIT>" <EOL> raise RuntimeError ( msg . format ( key ) ) <EOL> return _Scope ( self , kwargs ) <EOL> def update ( self , env ) : <EOL> """<STR_LIT>""" <EOL> stack = env . __dict__ [ '<STR_LIT>' ] <EOL> for scope in stack : <EOL> for name , value in scope . items ( ) : <EOL> setattr ( self , name , value ) <EOL> def new ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> new = type ( self ) ( ** kwargs ) <EOL> return _Swapper ( self , new ) <EOL> def __repr__ ( self ) : <EOL> clsname = self . __class__ . __name__ <EOL> stack = self . __dict__ [ '<STR_LIT>' ] <EOL> header = '<STR_LIT>' . format ( clsname , len ( stack ) ) <EOL> exc_stack = self . __dict__ [ '<STR_LIT>' ] <EOL> show_exc_stack = sys . exc_info ( ) and exc_stack <EOL> if show_exc_stack : <EOL> header += '<STR_LIT>' . format ( len ( exc_stack ) ) <EOL> header += '<STR_LIT:>>' <EOL> lines = [ header ] <EOL> lines . append ( '<STR_LIT>' ) <EOL> for name , value , depth in stack_vars ( stack ) : <EOL> if not name . startswith ( '<STR_LIT:_>' ) or self . verbose : <EOL> lines . append ( '<STR_LIT>' . format ( name , depth , value ) ) <EOL> if show_exc_stack : <EOL> lines . append ( '<STR_LIT>' ) <EOL> for name , value , depth in stack_vars ( exc_stack ) : <EOL> if not name . startswith ( '<STR_LIT:_>' ) or self . verbose : <EOL> lines . append ( '<STR_LIT>' . format ( name , depth , value ) ) <EOL> lines . append ( '<STR_LIT>' ) <EOL> res = '<STR_LIT:\n>' . join ( lines ) <EOL> return res <EOL> env = _Environment ( ) </s>
