<s> from django . template . base import Library , Node <EOL> from django . template import defaulttags <EOL> from django . templatetags import future <EOL> register = Library ( ) <EOL> error_on_old_style_url_tag = False <EOL> new_style_url_tag = False <EOL> errors = [ ] <EOL> def before_new_template ( force_new_urls ) : <EOL> """<STR_LIT>""" <EOL> global new_style_url_tag , error_on_old_style_url_tag , errors <EOL> new_style_url_tag = False <EOL> error_on_old_style_url_tag = force_new_urls <EOL> errors = [ ] <EOL> def get_template_errors ( ) : <EOL> return errors <EOL> class NoOpNode ( Node ) : <EOL> def render ( self , context ) : <EOL> return '<STR_LIT>' <EOL> @ register . tag <EOL> def extends ( parser , token ) : <EOL> return NoOpNode ( ) <EOL> @ register . tag <EOL> def include ( parser , token ) : <EOL> return NoOpNode ( ) <EOL> @ register . tag <EOL> def load ( parser , token ) : <EOL> global new_style_url_tag <EOL> bits = token . contents . split ( ) <EOL> reloaded_url_tag = False <EOL> if len ( bits ) >= <NUM_LIT:4> and bits [ - <NUM_LIT:2> ] == "<STR_LIT>" and bits [ - <NUM_LIT:1> ] == "<STR_LIT>" : <EOL> for name in bits [ <NUM_LIT:1> : - <NUM_LIT:2> ] : <EOL> if name == "<STR_LIT:url>" : <EOL> new_style_url_tag = True <EOL> reloaded_url_tag = True <EOL> try : <EOL> return defaulttags . load ( parser , token ) <EOL> finally : <EOL> if reloaded_url_tag : <EOL> parser . tags [ '<STR_LIT:url>' ] = new_style_url <EOL> @ register . tag ( name = '<STR_LIT:url>' ) <EOL> def old_style_url ( parser , token ) : <EOL> global error_on_old_style_url_tag <EOL> bits = token . split_contents ( ) <EOL> view = bits [ <NUM_LIT:1> ] <EOL> if error_on_old_style_url_tag : <EOL> _error ( "<STR_LIT>" % ( "<STR_LIT:U+0020>" . join ( bits ) ) , token ) <EOL> error_on_old_style_url_tag = False <EOL> if view [ <NUM_LIT:0> ] in "<STR_LIT>" and view [ <NUM_LIT:0> ] == view [ - <NUM_LIT:1> ] : <EOL> _error ( "<STR_LIT>" % ( "<STR_LIT:U+0020>" . join ( bits ) ) , token ) <EOL> return defaulttags . url ( parser , token ) <EOL> def new_style_url ( parser , token ) : <EOL> bits = token . split_contents ( ) <EOL> view = bits [ <NUM_LIT:1> ] <EOL> if view [ <NUM_LIT:0> ] not in "<STR_LIT>" or view [ <NUM_LIT:0> ] != view [ - <NUM_LIT:1> ] : <EOL> _error ( "<STR_LIT>" % ( "<STR_LIT:U+0020>" . join ( bits ) ) , token ) <EOL> return future . url ( parser , token ) <EOL> def _error ( message , token ) : <EOL> origin , ( start , upto ) = token . source <EOL> source = origin . reload ( ) <EOL> line = source . count ( "<STR_LIT:\n>" , <NUM_LIT:0> , start ) + <NUM_LIT:1> <EOL> errors . append ( ( origin , line , message ) ) </s>
