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): ...@@ -92,9 +92,10 @@ class RecipeBaseLoader(BaseLoader):
""" """
Base class for import classes altering import path. 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.base = os.path.normpath(path)
self.delimiter = delimiter self.delimiter = delimiter
self.encoding = encoding
def get_source(self, environment, template): def get_source(self, environment, template):
path = self._getPath(template) path = self._getPath(template)
...@@ -103,7 +104,7 @@ class RecipeBaseLoader(BaseLoader): ...@@ -103,7 +104,7 @@ class RecipeBaseLoader(BaseLoader):
raise TemplateNotFound(template) raise TemplateNotFound(template)
mtime = os.path.getmtime(path) mtime = os.path.getmtime(path)
with file(path) as f: 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) return source, path, lambda: mtime == os.path.getmtime(path)
def _getPath(self, template): def _getPath(self, template):
...@@ -171,7 +172,7 @@ class Recipe(object): ...@@ -171,7 +172,7 @@ class Recipe(object):
expression_type] expression_type]
import_dict[alias] = loader_type( import_dict[alias] = loader_type(
expression_handler(expression, buildout, name, options), expression_handler(expression, buildout, name, options),
import_delimiter, import_delimiter, self.encoding,
) )
if import_dict: if import_dict:
loader = RelaxedPrefixLoader(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