<s> from django import template <EOL> from django . template . loader_tags import ExtendsNode <EOL> register = template . Library ( ) <EOL> class IncludeExtendNode ( template . Node ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , nodelist , parent_name , parent_name_expr , template_dirs = None ) : <EOL> self . impl = ExtendsNode ( nodelist , parent_name , parent_name_expr , <EOL> template_dirs ) <EOL> def render ( self , context ) : <EOL> return self . impl . render ( context ) <EOL> def do_include_extend ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> bits = token . contents . split ( ) <EOL> if len ( bits ) != <NUM_LIT:2> : <EOL> raise template . TemplateSyntaxError , "<STR_LIT>" % bits [ <NUM_LIT:0> ] <EOL> parent_name , parent_name_expr = None , None <EOL> if bits [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] in ( '<STR_LIT:">' , "<STR_LIT:'>" ) and bits [ <NUM_LIT:1> ] [ - <NUM_LIT:1> ] == bits [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] : <EOL> parent_name = bits [ <NUM_LIT:1> ] [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> else : <EOL> parent_name_expr = parser . compile_filter ( bits [ <NUM_LIT:1> ] ) <EOL> nodelist = parser . parse ( ( '<STR_LIT:end>' + bits [ <NUM_LIT:0> ] , ) ) <EOL> parser . delete_first_token ( ) <EOL> return IncludeExtendNode ( nodelist , parent_name , parent_name_expr ) <EOL> register . tag ( '<STR_LIT>' , do_include_extend ) <EOL> class IfPredNode ( template . Node ) : <EOL> def __init__ ( self , var1 , var2 , predicate , nodelist_true , nodelist_false ) : <EOL> self . var1 , self . var2 = template . Variable ( var1 ) , template . Variable ( var2 ) <EOL> self . nodelist_true , self . nodelist_false = nodelist_true , nodelist_false <EOL> self . predicate = predicate <EOL> def render ( self , context ) : <EOL> try : <EOL> val1 = self . var1 . resolve ( context ) <EOL> except VariableDoesNotExist : <EOL> val1 = None <EOL> try : <EOL> val2 = self . var2 . resolve ( context ) <EOL> except VariableDoesNotExist : <EOL> val2 = None <EOL> predicate = self . predicate <EOL> if ( predicate ( val1 , val2 ) ) : <EOL> return self . nodelist_true . render ( context ) <EOL> return self . nodelist_false . render ( context ) <EOL> def if_pred ( parser , token , predicate ) : <EOL> bits = list ( token . split_contents ( ) ) <EOL> if len ( bits ) != <NUM_LIT:3> : <EOL> raise template . TemplateSyntaxError , "<STR_LIT>" % bits [ <NUM_LIT:0> ] <EOL> end_tag = '<STR_LIT:end>' + bits [ <NUM_LIT:0> ] <EOL> nodelist_true = parser . parse ( ( '<STR_LIT>' , end_tag ) ) <EOL> token = parser . next_token ( ) <EOL> if token . contents == '<STR_LIT>' : <EOL> nodelist_false = parser . parse ( ( end_tag , ) ) <EOL> parser . delete_first_token ( ) <EOL> else : <EOL> nodelist_false = template . NodeList ( ) <EOL> return IfPredNode ( bits [ <NUM_LIT:1> ] , bits [ <NUM_LIT:2> ] , predicate , nodelist_true , nodelist_false ) </s>
