summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorR. Tyler Ballance <tyler@monkeypox.org>2010-01-27 20:39:01 -0800
committerR. Tyler Ballance <tyler@monkeypox.org>2010-01-27 20:39:01 -0800
commit5d931545fcde3029a5e4f49d9d72533c0bd0f667 (patch)
tree38fe3bc8aa5d8defae00a343a39ce3e87899a5cf
parent46df95cf55fc1d9b9bb2513d47e3e1c9aa401b21 (diff)
downloadpython-cheetah-5d931545fcde3029a5e4f49d9d72533c0bd0f667.tar.gz
Find the #encoding directive even if it's after a comment (for example)
Added a test and applied Juan's patch, everything seems to check out alright with it Reported-by: Juan Fiol <fiolj@yahoo.com>
-rw-r--r--cheetah/Compiler.py2
-rw-r--r--cheetah/Tests/SyntaxAndOutput.py6
2 files changed, 7 insertions, 1 deletions
diff --git a/cheetah/Compiler.py b/cheetah/Compiler.py
index f4c7668..ee55868 100644
--- a/cheetah/Compiler.py
+++ b/cheetah/Compiler.py
@@ -1556,7 +1556,7 @@ class ModuleCompiler(SettingsManager, GenUtils):
else:
unicodeMatch = unicodeDirectiveRE.search(source)
- encodingMatch = encodingDirectiveRE.match(source)
+ encodingMatch = encodingDirectiveRE.search(source)
if unicodeMatch:
if encodingMatch:
raise ParseError(
diff --git a/cheetah/Tests/SyntaxAndOutput.py b/cheetah/Tests/SyntaxAndOutput.py
index 4fc467c..e052e6e 100644
--- a/cheetah/Tests/SyntaxAndOutput.py
+++ b/cheetah/Tests/SyntaxAndOutput.py
@@ -742,6 +742,12 @@ class EncodingDirective(OutputTest):
self.verify("#encoding latin-1\nAndr\202",
u'Andr\202')
+ def test6(self):
+ '''Using #encoding on the second line'''
+ self.verify("""### Comments on the first line
+#encoding utf-8\n\xe1\x88\xb4""",
+ u'\u1234', outputEncoding='utf8')
+
class UnicodeDirective(OutputTest):
def test1(self):
"""basic #unicode """