be8404
From c8495264b503a595fbc89e6c8a83a402eff445c6 Mon Sep 17 00:00:00 2001
be8404
From: Mathieu Pillard <m@virgule.net>
be8404
Date: Sun, 25 May 2014 14:09:33 +0200
be8404
Subject: [PATCH] Use get_template() when dealing with django templates
be8404
be8404
---
be8404
 compressor/offline/django.py | 16 +++++++---------
be8404
 1 file changed, 7 insertions(+), 9 deletions(-)
be8404
be8404
diff --git a/compressor/offline/django.py b/compressor/offline/django.py
be8404
index 6541471..3986562 100644
be8404
--- a/compressor/offline/django.py
be8404
+++ b/compressor/offline/django.py
be8404
@@ -1,13 +1,12 @@
be8404
 from __future__ import absolute_import
be8404
-import io
be8404
 from copy import copy
be8404
 
be8404
 from django import template
be8404
 from django.conf import settings
be8404
-from django.template import Template
be8404
 from django.template import Context
be8404
 from django.template.base import Node, VariableNode, TextNode, NodeList
be8404
 from django.template.defaulttags import IfNode
be8404
+from django.template.loader import get_template
be8404
 from django.template.loader_tags import ExtendsNode, BlockNode, BlockContext
be8404
 
be8404
 
be8404
@@ -93,13 +92,12 @@ def __init__(self, charset):
be8404
         self.charset = charset
be8404
 
be8404
     def parse(self, template_name):
be8404
-        with io.open(template_name, mode='rb') as file:
be8404
-            try:
be8404
-                return Template(file.read().decode(self.charset))
be8404
-            except template.TemplateSyntaxError as e:
be8404
-                raise TemplateSyntaxError(str(e))
be8404
-            except template.TemplateDoesNotExist as e:
be8404
-                raise TemplateDoesNotExist(str(e))
be8404
+        try:
be8404
+            return get_template(template_name)
be8404
+        except template.TemplateSyntaxError as e:
be8404
+            raise TemplateSyntaxError(str(e))
be8404
+        except template.TemplateDoesNotExist as e:
be8404
+            raise TemplateDoesNotExist(str(e))
be8404
 
be8404
     def process_template(self, template, context):
be8404
         return True