aboutsummaryrefslogtreecommitdiffstats
path: root/lib/mako
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mako')
-rw-r--r--lib/mako/codegen.py3
-rw-r--r--lib/mako/lexer.py12
2 files changed, 15 insertions, 0 deletions
diff --git a/lib/mako/codegen.py b/lib/mako/codegen.py
index 71f8152..a06ef26 100644
--- a/lib/mako/codegen.py
+++ b/lib/mako/codegen.py
@@ -66,6 +66,8 @@ class _GenerateRenderMethod(object):
namespaces = {}
module_code = []
pagetag = [None]
+ encoding =[None]
+
class FindTopLevel(object):
def visitInheritTag(s, node):
inherit.append(node)
@@ -76,6 +78,7 @@ class _GenerateRenderMethod(object):
def visitCode(self, node):
if node.ismodule:
module_code.append(node)
+
f = FindTopLevel()
for n in self.node.nodes:
n.accept_visitor(f)
diff --git a/lib/mako/lexer.py b/lib/mako/lexer.py
index 921d206..d032b5a 100644
--- a/lib/mako/lexer.py
+++ b/lib/mako/lexer.py
@@ -88,7 +88,12 @@ class Lexer(object):
raise exceptions.SyntaxException("Keyword '%s' not a legal ternary for keyword '%s'" % (node.keyword, self.control_line[-1].keyword), self.matched_lineno, self.matched_charpos, self.filename)
def parse(self):
+ encoding = self.match_encoding()
+ if encoding:
+ self.text = self.text.decode(encoding)
+
length = len(self.text)
+
while (True):
if self.match_position > length:
break
@@ -116,6 +121,13 @@ class Lexer(object):
raise exceptions.SyntaxException("Unclosed tag: <%%%s>" % self.tag[-1].keyword, self.matched_lineno, self.matched_charpos, self.filename)
return self.template
+ def match_encoding(self):
+ match = self.match(r'#\s*-\*- encoding: (.+?) -\*-\n')
+ if match:
+ return match.group(1)
+ else:
+ return None
+
def match_tag_start(self):
match = self.match(r'''
\<% # opening tag