<s> from django . conf import settings <EOL> import fnmatch <EOL> import os <EOL> class TemplateRepository ( object ) : <EOL> def __init__ ( self ) : <EOL> self . templates = self . _readTemplates ( ) <EOL> def getTemplate ( self , templateName ) : <EOL> return self . templates [ templateName ] <EOL> def _readTemplates ( self ) : <EOL> file = self . _findTemplateFile ( ) <EOL> templates = { } <EOL> for line in open ( file , "<STR_LIT:r>" ) : <EOL> keyValue = line . split ( "<STR_LIT:=>" ) <EOL> templates [ keyValue [ <NUM_LIT:0> ] . strip ( ) ] = keyValue [ <NUM_LIT:1> ] . strip ( ) <EOL> return templates <EOL> def _findTemplateFile ( self ) : <EOL> dirs = settings . TEMPLATE_DIRS <EOL> for dir in dirs : <EOL> for file in os . listdir ( dir ) : <EOL> if fnmatch . fnmatch ( file , '<STR_LIT>' ) : <EOL> return dir + '<STR_LIT:/>' + file <EOL> raise IOError ( '<STR_LIT>' + "<STR_LIT:U+002CU+0020>" . join ( dirs ) ) </s>
