<s> """<STR_LIT>""" <EOL> from django . conf import settings as django_settings <EOL> from django . utils import timezone <EOL> from django . template import Context <EOL> from django import template <EOL> from datetime import datetime <EOL> dummy_context = Context ( ) <EOL> def get_now ( ) : <EOL> if django_settings . USE_TZ : <EOL> return datetime . utcnow ( ) . replace ( tzinfo = timezone . utc ) <EOL> else : <EOL> return datetime . now ( ) <EOL> def get_placeholders ( template_name ) : <EOL> """<STR_LIT>""" <EOL> dummy_context . template = template . Template ( "<STR_LIT>" ) <EOL> try : <EOL> temp_wrapper = template . loader . get_template ( template_name ) <EOL> except template . TemplateDoesNotExist : <EOL> return [ ] <EOL> plist , blist = [ ] , [ ] <EOL> temp = temp_wrapper . template <EOL> _placeholders_recursif ( temp . nodelist , plist , blist ) <EOL> previous = { } <EOL> block_to_remove = [ ] <EOL> for block in blist : <EOL> if block . name in previous : <EOL> if not hasattr ( block , '<STR_LIT>' ) : <EOL> block_to_remove . append ( previous [ block . name ] ) <EOL> previous [ block . name ] = block <EOL> def keep ( p ) : <EOL> return not p . found_in_block in block_to_remove <EOL> placeholders = [ p for p in plist if keep ( p ) ] <EOL> names = [ ] <EOL> pfiltered = [ ] <EOL> for p in placeholders : <EOL> if p . ctype not in names : <EOL> pfiltered . append ( p ) <EOL> names . append ( p . ctype ) <EOL> return pfiltered <EOL> def _placeholders_recursif ( nodelist , plist , blist ) : <EOL> """<STR_LIT>""" <EOL> from django . template . loader_tags import BlockNode <EOL> if len ( blist ) : <EOL> block = blist [ - <NUM_LIT:1> ] <EOL> else : <EOL> block = None <EOL> for node in nodelist : <EOL> if isinstance ( node , BlockNode ) : <EOL> if node not in blist : <EOL> blist . append ( node ) <EOL> if not block : <EOL> block = node <EOL> if block : <EOL> if isinstance ( node , template . base . VariableNode ) : <EOL> if ( node . filter_expression . var . var == u'<STR_LIT>' ) : <EOL> block . has_super_var = True <EOL> if hasattr ( node , '<STR_LIT>' ) : <EOL> dummy_context2 = Context ( ) <EOL> dummy_context2 . template = template . Template ( "<STR_LIT>" ) <EOL> _placeholders_recursif ( node . get_parent ( dummy_context2 ) . nodelist , <EOL> plist , blist ) <EOL> elif hasattr ( node , '<STR_LIT>' ) and hasattr ( node . template , '<STR_LIT>' ) : <EOL> _placeholders_recursif ( node . template . nodelist , plist , blist ) <EOL> if hasattr ( node , '<STR_LIT>' ) and hasattr ( node , '<STR_LIT>' ) and hasattr ( node , '<STR_LIT>' ) and hasattr ( node , '<STR_LIT:name>' ) : <EOL> if block : <EOL> node . found_in_block = block <EOL> plist . append ( node ) <EOL> node . render ( dummy_context ) <EOL> for key in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if hasattr ( node , key ) : <EOL> try : <EOL> _placeholders_recursif ( getattr ( node , key ) , plist , blist ) <EOL> except : <EOL> pass <EOL> def normalize_url ( url ) : <EOL> """<STR_LIT>""" <EOL> if not url or len ( url ) == <NUM_LIT:0> : <EOL> return '<STR_LIT:/>' <EOL> if not url . startswith ( '<STR_LIT:/>' ) : <EOL> url = '<STR_LIT:/>' + url <EOL> if len ( url ) > <NUM_LIT:1> and url . endswith ( '<STR_LIT:/>' ) : <EOL> url = url [ <NUM_LIT:0> : len ( url ) - <NUM_LIT:1> ] <EOL> return url </s>
