diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-12-09 01:56:46 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-12-09 01:56:46 +0000 |
commit | ecc8dab3ab8d2d58a0faadc16fa928e8eda5f314 (patch) | |
tree | 456bd368b4aa623f153309e51f415e450ead3c47 /lib/mako/lexer.py | |
parent | 5d922a3b9133dac77ab7374868b91e79b1794dd1 (diff) | |
download | external_python_mako-ecc8dab3ab8d2d58a0faadc16fa928e8eda5f314.tar.gz external_python_mako-ecc8dab3ab8d2d58a0faadc16fa928e8eda5f314.tar.bz2 external_python_mako-ecc8dab3ab8d2d58a0faadc16fa928e8eda5f314.zip |
lexer picks up on magic encoding comment
Diffstat (limited to 'lib/mako/lexer.py')
-rw-r--r-- | lib/mako/lexer.py | 12 |
1 files changed, 12 insertions, 0 deletions
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 |