<s> """<STR_LIT>""" <EOL> import django <EOL> if django . VERSION < ( <NUM_LIT:1> , <NUM_LIT:4> ) : <EOL> from django . template import Node <EOL> from django . template import NodeList <EOL> from django . template import VariableDoesNotExist <EOL> from django . template import TemplateSyntaxError <EOL> try : <EOL> from django . template . base import TextNode <EOL> except ImportError : <EOL> from django . template import TextNode <EOL> class IfNode ( Node ) : <EOL> def __init__ ( self , conditions_nodelists ) : <EOL> self . conditions_nodelists = conditions_nodelists <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" <EOL> def __iter__ ( self ) : <EOL> for _ , nodelist in self . conditions_nodelists : <EOL> for node in nodelist : <EOL> yield node <EOL> @ property <EOL> def nodelist ( self ) : <EOL> return NodeList ( node for _ , nodelist in self . conditions_nodelists for node in nodelist ) <EOL> def render ( self , context ) : <EOL> for condition , nodelist in self . conditions_nodelists : <EOL> if condition is not None : <EOL> try : <EOL> match = condition . eval ( context ) <EOL> except VariableDoesNotExist : <EOL> match = None <EOL> else : <EOL> match = True <EOL> if match : <EOL> return nodelist . render ( context ) <EOL> return '<STR_LIT>' <EOL> def parse ( self , parse_until = None ) : <EOL> if parse_until is None : <EOL> parse_until = [ ] <EOL> nodelist = self . create_nodelist ( ) <EOL> while self . tokens : <EOL> token = self . next_token ( ) <EOL> if token . token_type == <NUM_LIT:0> : <EOL> self . extend_nodelist ( nodelist , TextNode ( token . contents ) , token ) <EOL> elif token . token_type == <NUM_LIT:1> : <EOL> if not token . contents : <EOL> self . empty_variable ( token ) <EOL> filter_expression = self . compile_filter ( token . contents ) <EOL> var_node = self . create_variable_node ( filter_expression ) <EOL> self . extend_nodelist ( nodelist , var_node , token ) <EOL> elif token . token_type == <NUM_LIT:2> : <EOL> try : <EOL> command = token . contents . split ( ) [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> self . empty_block_tag ( token ) <EOL> if command in parse_until : <EOL> self . prepend_token ( token ) <EOL> return nodelist <EOL> self . enter_command ( command , token ) <EOL> try : <EOL> compile_func = self . tags [ command ] <EOL> except KeyError : <EOL> self . invalid_block_tag ( token , command , parse_until ) <EOL> try : <EOL> compiled_result = compile_func ( self , token ) <EOL> except TemplateSyntaxError as e : <EOL> if not self . compile_function_error ( token , e ) : <EOL> raise <EOL> self . extend_nodelist ( nodelist , compiled_result , token ) <EOL> self . exit_command ( ) <EOL> if parse_until : <EOL> self . unclosed_block_tag ( parse_until ) <EOL> return nodelist <EOL> def parser_patch ( instance ) : <EOL> instance . __class__ . parse = parse <EOL> return instance <EOL> else : <EOL> from django . template . defaulttags import IfNode <EOL> parser_patch = lambda instance : instance </s>
