<s> '''<STR_LIT>''' <EOL> __all__ = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> _contexts = { } <EOL> _default_context = None <EOL> _context_stack = [ ] <EOL> class ProxyContext ( object ) : <EOL> __slots__ = [ '<STR_LIT>' ] <EOL> def __init__ ( self , obj ) : <EOL> object . __init__ ( self ) <EOL> object . __setattr__ ( self , '<STR_LIT>' , obj ) <EOL> def __getattribute__ ( self , name ) : <EOL> return getattr ( object . __getattribute__ ( self , '<STR_LIT>' ) , name ) <EOL> def __delattr__ ( self , name ) : <EOL> delattr ( object . __getattribute__ ( self , '<STR_LIT>' ) , name ) <EOL> def __setattr__ ( self , name , value ) : <EOL> setattr ( object . __getattribute__ ( self , '<STR_LIT>' ) , name , value ) <EOL> def __bool__ ( self ) : <EOL> return bool ( object . __getattribute__ ( self , '<STR_LIT>' ) ) <EOL> def __str__ ( self ) : <EOL> return str ( object . __getattribute__ ( self , '<STR_LIT>' ) ) <EOL> def __repr__ ( self ) : <EOL> return repr ( object . __getattribute__ ( self , '<STR_LIT>' ) ) <EOL> class Context ( dict ) : <EOL> def __init__ ( self , init = False ) : <EOL> dict . __init__ ( self ) <EOL> self . sandbox = None <EOL> if not init : <EOL> return <EOL> for name in _contexts : <EOL> context = _contexts [ name ] <EOL> instance = context [ '<STR_LIT>' ] ( * context [ '<STR_LIT:args>' ] , ** context [ '<STR_LIT>' ] ) <EOL> self [ name ] = instance <EOL> def push ( self ) : <EOL> _context_stack . append ( self ) <EOL> for name , instance in self . items ( ) : <EOL> object . __setattr__ ( _contexts [ name ] [ '<STR_LIT>' ] , '<STR_LIT>' , instance ) <EOL> def pop ( self ) : <EOL> _context_stack . pop ( - <NUM_LIT:1> ) <EOL> for name , instance in get_current_context ( ) . items ( ) : <EOL> object . __setattr__ ( _contexts [ name ] [ '<STR_LIT>' ] , '<STR_LIT>' , instance ) <EOL> def register_context ( name , cls , * args , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> instance = cls ( * args , ** kwargs ) <EOL> proxy = ProxyContext ( instance ) <EOL> _contexts [ name ] = { <EOL> '<STR_LIT>' : cls , <EOL> '<STR_LIT:args>' : args , <EOL> '<STR_LIT>' : kwargs , <EOL> '<STR_LIT>' : proxy } <EOL> _default_context [ name ] = instance <EOL> return proxy <EOL> def get_current_context ( ) : <EOL> '''<STR_LIT>''' <EOL> if not _context_stack : <EOL> return _default_context <EOL> return _context_stack [ - <NUM_LIT:1> ] <EOL> _default_context = Context ( init = False ) </s>
