<s> import re <EOL> from copy import copy <EOL> from distutils . version import LooseVersion <EOL> from classytags . compat import compat_basestring <EOL> from django import get_version <EOL> from django . template import Context , RequestContext <EOL> from django . template . context import BaseContext <EOL> DJANGO_1_9_OR_HIGHER = ( <EOL> LooseVersion ( get_version ( ) ) >= LooseVersion ( '<STR_LIT>' ) <EOL> ) <EOL> class NULL : <EOL> """<STR_LIT>""" <EOL> class TemplateConstant ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , value ) : <EOL> self . literal = value <EOL> if isinstance ( value , compat_basestring ) : <EOL> self . value = value . strip ( '<STR_LIT>' ) <EOL> else : <EOL> self . value = value <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % repr ( self . value ) <EOL> def resolve ( self , context ) : <EOL> return self . value <EOL> class StructuredOptions ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , options , breakpoints , blocks , combind_breakpoints ) : <EOL> self . options = options <EOL> self . breakpoints = copy ( breakpoints ) <EOL> self . blocks = copy ( blocks ) <EOL> self . combined_breakpoints = dict ( combind_breakpoints . items ( ) ) <EOL> self . reversed_combined_breakpoints = dict ( <EOL> ( v , k ) for k , v in combind_breakpoints . items ( ) <EOL> ) <EOL> self . current_breakpoint = None <EOL> if self . breakpoints : <EOL> self . next_breakpoint = self . breakpoints . pop ( <NUM_LIT:0> ) <EOL> else : <EOL> self . next_breakpoint = None <EOL> def shift_breakpoint ( self ) : <EOL> """<STR_LIT>""" <EOL> self . current_breakpoint = self . next_breakpoint <EOL> if self . breakpoints : <EOL> self . next_breakpoint = self . breakpoints . pop ( <NUM_LIT:0> ) <EOL> else : <EOL> self . next_breakpoint = None <EOL> def get_arguments ( self ) : <EOL> """<STR_LIT>""" <EOL> return copy ( self . options [ self . current_breakpoint ] ) <EOL> _re1 = re . compile ( '<STR_LIT>' ) <EOL> _re2 = re . compile ( '<STR_LIT>' ) <EOL> def get_default_name ( name ) : <EOL> """<STR_LIT>""" <EOL> return _re2 . sub ( r'<STR_LIT>' , _re1 . sub ( r'<STR_LIT>' , name ) ) . lower ( ) <EOL> def mixin ( parent , child , attrs = None ) : <EOL> attrs = attrs or { } <EOL> return type ( <EOL> '<STR_LIT>' % ( parent . __name__ , child . __name__ ) , <EOL> ( child , parent ) , <EOL> attrs <EOL> ) <EOL> def flatten_context ( context ) : <EOL> def do_flatten ( context ) : <EOL> flat = { } <EOL> for d in context . dicts : <EOL> if isinstance ( d , ( Context , RequestContext ) ) : <EOL> flat . update ( do_flatten ( d ) ) <EOL> else : <EOL> flat . update ( d ) <EOL> return flat <EOL> if callable ( getattr ( context , '<STR_LIT>' , None ) ) and DJANGO_1_9_OR_HIGHER : <EOL> return context . flatten ( ) <EOL> elif isinstance ( context , BaseContext ) : <EOL> return do_flatten ( context ) <EOL> return context </s>
