<s> import glob <EOL> import os <EOL> import threading <EOL> import importlib <EOL> from django . conf import settings <EOL> localdata = threading . local ( ) <EOL> localdata . TEMPLATES = tuple ( ) <EOL> TEMPLATES = localdata . TEMPLATES <EOL> def autodiscover_templates ( ) : <EOL> '''<STR_LIT>''' <EOL> def sorted_templates ( templates ) : <EOL> '''<STR_LIT>''' <EOL> TEMPLATES = sorted ( templates , key = lambda template : template [ <NUM_LIT:1> ] ) <EOL> return TEMPLATES <EOL> global TEMPLATES <EOL> if TEMPLATES : <EOL> return TEMPLATES <EOL> override_dir = getattr ( settings , '<STR_LIT>' , None ) <EOL> if override_dir : <EOL> return sorted_templates ( override_dir ) <EOL> templates = [ ] <EOL> dirs_to_scan = [ ] <EOL> if '<STR_LIT>' in settings . TEMPLATE_LOADERS : <EOL> for app in settings . INSTALLED_APPS : <EOL> _ = __import__ ( app ) <EOL> dir = os . path . dirname ( _ . __file__ ) <EOL> if not dir in dirs_to_scan : <EOL> dirs_to_scan . append ( os . path . join ( dir , '<STR_LIT>' ) ) <EOL> if '<STR_LIT>' in settings . TEMPLATE_LOADERS : <EOL> for dir in settings . TEMPLATE_DIRS : <EOL> if not dir in dirs_to_scan : <EOL> dirs_to_scan . append ( dir ) <EOL> for dir in dirs_to_scan : <EOL> found = glob . glob ( os . path . join ( dir , '<STR_LIT>' ) ) <EOL> for file in found : <EOL> dir , file = os . path . split ( file ) <EOL> key , value = os . path . join ( dir . split ( '<STR_LIT:/>' ) [ - <NUM_LIT:1> ] , file ) , file <EOL> f = False <EOL> for _ , template in templates : <EOL> if template == file : <EOL> f = True <EOL> if not f : <EOL> templates . append ( ( key , value , ) ) <EOL> return sorted_templates ( templates ) <EOL> def get_validators ( ) : <EOL> val = [ ] <EOL> if hasattr ( settings , '<STR_LIT>' ) : <EOL> validators = getattr ( settings , <EOL> '<STR_LIT>' ) <EOL> for validator in validators : <EOL> try : <EOL> f = getattr ( importlib . import_module ( validator [ <NUM_LIT:0> ] ) , <EOL> validator [ <NUM_LIT:1> ] ) <EOL> val . append ( f ) <EOL> except ImportError : <EOL> raise ImportError ( <EOL> "<STR_LIT>" . format ( <EOL> validator [ <NUM_LIT:1> ] , validator [ <NUM_LIT:0> ] ) ) <EOL> return val </s>
