Commit 3a43536a authored by Kirill Smelkov's avatar Kirill Smelkov

jinja2: Don't hardcode utf-8 encoding for imported files

UTF-8 encoding for template imports was hardcoded from the beginning -
from 320f29b2 (Add jinja2 "import" directive support.)

Since in the previous patch we added option for input/output encoding,
it makes sense to also use it, instead of hardcoding utf-8.

/reviewed-by @vpelletier  (on !1)
parent c901c411
......@@ -92,9 +92,10 @@ class RecipeBaseLoader(BaseLoader):
"""
Base class for import classes altering import path.
"""
def __init__(self, path, delimiter):
def __init__(self, path, delimiter, encoding):
self.base = os.path.normpath(path)
self.delimiter = delimiter
self.encoding = encoding
def get_source(self, environment, template):
path = self._getPath(template)
......@@ -103,7 +104,7 @@ class RecipeBaseLoader(BaseLoader):
raise TemplateNotFound(template)
mtime = os.path.getmtime(path)
with file(path) as f:
source = f.read().decode('utf-8')
source = f.read().decode(self.encoding)
return source, path, lambda: mtime == os.path.getmtime(path)
def _getPath(self, template):
......@@ -171,7 +172,7 @@ class Recipe(object):
expression_type]
import_dict[alias] = loader_type(
expression_handler(expression, buildout, name, options),
import_delimiter,
import_delimiter, self.encoding,
)
if import_dict:
loader = RelaxedPrefixLoader(import_dict,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment