<s> from django . core . exceptions import ImproperlyConfigured <EOL> from django . utils . importlib import import_module <EOL> _standard_context_processors = None <EOL> _builtin_context_processors = ( '<STR_LIT>' , ) <EOL> class ContextPopException ( Exception ) : <EOL> "<STR_LIT>" <EOL> pass <EOL> class BaseContext ( object ) : <EOL> def __init__ ( self , dict_ = None ) : <EOL> dict_ = dict_ or { } <EOL> self . dicts = [ dict_ ] <EOL> def __repr__ ( self ) : <EOL> return repr ( self . dicts ) <EOL> def __iter__ ( self ) : <EOL> for d in reversed ( self . dicts ) : <EOL> yield d <EOL> def push ( self ) : <EOL> d = { } <EOL> self . dicts . append ( d ) <EOL> return d <EOL> def pop ( self ) : <EOL> if len ( self . dicts ) == <NUM_LIT:1> : <EOL> raise ContextPopException <EOL> return self . dicts . pop ( ) <EOL> def __setitem__ ( self , key , value ) : <EOL> "<STR_LIT>" <EOL> self . dicts [ - <NUM_LIT:1> ] [ key ] = value <EOL> def __getitem__ ( self , key ) : <EOL> "<STR_LIT>" <EOL> for d in reversed ( self . dicts ) : <EOL> if key in d : <EOL> return d [ key ] <EOL> raise KeyError ( key ) <EOL> def __delitem__ ( self , key ) : <EOL> "<STR_LIT>" <EOL> del self . dicts [ - <NUM_LIT:1> ] [ key ] <EOL> def has_key ( self , key ) : <EOL> for d in self . dicts : <EOL> if key in d : <EOL> return True <EOL> return False <EOL> def __contains__ ( self , key ) : <EOL> return self . has_key ( key ) <EOL> def get ( self , key , otherwise = None ) : <EOL> for d in reversed ( self . dicts ) : <EOL> if key in d : <EOL> return d [ key ] <EOL> return otherwise <EOL> class Context ( BaseContext ) : <EOL> "<STR_LIT>" <EOL> def __init__ ( self , dict_ = None , autoescape = True , current_app = None ) : <EOL> self . autoescape = autoescape <EOL> self . current_app = current_app <EOL> self . render_context = RenderContext ( ) <EOL> super ( Context , self ) . __init__ ( dict_ ) <EOL> def update ( self , other_dict ) : <EOL> "<STR_LIT>" <EOL> if not hasattr ( other_dict , '<STR_LIT>' ) : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> self . dicts . append ( other_dict ) <EOL> return other_dict <EOL> class RenderContext ( BaseContext ) : <EOL> """<STR_LIT>""" <EOL> def __iter__ ( self ) : <EOL> for d in self . dicts [ - <NUM_LIT:1> ] : <EOL> yield d <EOL> def has_key ( self , key ) : <EOL> return key in self . dicts [ - <NUM_LIT:1> ] <EOL> def get ( self , key , otherwise = None ) : <EOL> d = self . dicts [ - <NUM_LIT:1> ] <EOL> if key in d : <EOL> return d [ key ] <EOL> return otherwise <EOL> def get_standard_processors ( ) : <EOL> from django . conf import settings <EOL> global _standard_context_processors <EOL> if _standard_context_processors is None : <EOL> processors = [ ] <EOL> collect = [ ] <EOL> collect . extend ( _builtin_context_processors ) <EOL> collect . extend ( settings . TEMPLATE_CONTEXT_PROCESSORS ) <EOL> for path in collect : <EOL> i = path . rfind ( '<STR_LIT:.>' ) <EOL> module , attr = path [ : i ] , path [ i + <NUM_LIT:1> : ] <EOL> try : <EOL> mod = import_module ( module ) <EOL> except ImportError , e : <EOL> raise ImproperlyConfigured ( '<STR_LIT>' % ( module , e ) ) <EOL> try : <EOL> func = getattr ( mod , attr ) <EOL> except AttributeError : <EOL> raise ImproperlyConfigured ( '<STR_LIT>' % ( module , attr ) ) <EOL> processors . append ( func ) <EOL> _standard_context_processors = tuple ( processors ) <EOL> return _standard_context_processors <EOL> class RequestContext ( Context ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , request , dict = None , processors = None , current_app = None ) : <EOL> Context . __init__ ( self , dict , current_app = current_app ) <EOL> if processors is None : <EOL> processors = ( ) <EOL> else : <EOL> processors = tuple ( processors ) <EOL> for processor in get_standard_processors ( ) + processors : <EOL> self . update ( processor ( request ) ) </s>
