Refactor horizon TemplateLoader

Here we can use `with` statement to keep
horizon code clean.

Change-Id: I98ffc3fbcb6892a3739f2de1936c54e868f8908f
This commit is contained in:
lawrancejing 2013-10-08 17:28:33 +08:00 committed by lawrancejing
parent 950bd9a4f3
commit bebeaa6e11

View File

@ -35,11 +35,8 @@ class TemplateLoader(BaseLoader):
def load_template_source(self, template_name, template_dirs=None):
for path in self.get_template_sources(template_name):
try:
file = open(path)
try:
with open(path) as file:
return (file.read().decode(settings.FILE_CHARSET), path)
finally:
file.close()
except IOError:
pass
raise TemplateDoesNotExist(template_name)