<s> """<STR_LIT>""" <EOL> import os <EOL> import sys <EOL> from django . conf import settings <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> from django . template . base import TemplateDoesNotExist <EOL> from django . template . loader import BaseLoader <EOL> from django . utils . _os import safe_join <EOL> from django . utils . importlib import import_module <EOL> from django . utils import six <EOL> if not six . PY3 : <EOL> fs_encoding = sys . getfilesystemencoding ( ) or sys . getdefaultencoding ( ) <EOL> app_template_dirs = [ ] <EOL> for app in settings . INSTALLED_APPS : <EOL> try : <EOL> mod = import_module ( app ) <EOL> except ImportError as e : <EOL> raise ImproperlyConfigured ( '<STR_LIT>' % ( app , e . args [ <NUM_LIT:0> ] ) ) <EOL> template_dir = os . path . join ( os . path . dirname ( mod . __file__ ) , '<STR_LIT>' ) <EOL> if os . path . isdir ( template_dir ) : <EOL> if not six . PY3 : <EOL> template_dir = template_dir . decode ( fs_encoding ) <EOL> app_template_dirs . append ( template_dir ) <EOL> app_template_dirs = tuple ( app_template_dirs ) <EOL> class Loader ( BaseLoader ) : <EOL> is_usable = True <EOL> def get_template_sources ( self , template_name , template_dirs = None ) : <EOL> """<STR_LIT>""" <EOL> if not template_dirs : <EOL> template_dirs = app_template_dirs <EOL> for template_dir in template_dirs : <EOL> try : <EOL> yield safe_join ( template_dir , template_name ) <EOL> except UnicodeDecodeError : <EOL> raise <EOL> except ValueError : <EOL> pass <EOL> def load_template_source ( self , template_name , template_dirs = None ) : <EOL> for filepath in self . get_template_sources ( template_name , template_dirs ) : <EOL> try : <EOL> with open ( filepath , '<STR_LIT:rb>' ) as fp : <EOL> return ( fp . read ( ) . decode ( settings . FILE_CHARSET ) , filepath ) <EOL> except IOError : <EOL> pass <EOL> raise TemplateDoesNotExist ( template_name ) </s>
