From: <zy...@us...> - 2010-07-20 03:50:57
|
Revision: 7079 http://jython.svn.sourceforge.net/jython/?rev=7079&view=rev Author: zyasoft Date: 2010-07-20 03:50:50 +0000 (Tue, 20 Jul 2010) Log Message: ----------- Fixed magic comments for source encoding so that it only looks at actual comments (first two lines), not other source text. Resolves #1506 Modified Paths: -------------- trunk/jython/Lib/test/test_grammar_jy.py trunk/jython/NEWS trunk/jython/src/org/python/core/ParserFacade.java Modified: trunk/jython/Lib/test/test_grammar_jy.py =================================================================== --- trunk/jython/Lib/test/test_grammar_jy.py 2010-07-14 05:12:19 UTC (rev 7078) +++ trunk/jython/Lib/test/test_grammar_jy.py 2010-07-20 03:50:50 UTC (rev 7079) @@ -2,6 +2,7 @@ """ from test import test_support +import sys import unittest class GrammarTest(unittest.TestCase): @@ -32,8 +33,21 @@ self.assertEquals(7, foo(1, 7)) self.assertEquals(10, foo(b=10)) -def test_main(): + +pep263 = """ + # verify that PEP263 encoding is only set by magic comments, not + # by other similar looking input; seen in issue 1506 + >>> line = '"Content-Transfer-Encoding: 8bit"' + >>> print line + "Content-Transfer-Encoding: 8bit" + """ + +__test__ = dict(pep263=pep263) + + +def test_main(verbose=None): test_support.run_unittest(GrammarTest) + test_support.run_doctest(sys.modules[__name__], verbose) if __name__ == '__main__': - test_main() + test_main(verbose=True) Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2010-07-14 05:12:19 UTC (rev 7078) +++ trunk/jython/NEWS 2010-07-20 03:50:50 UTC (rev 7079) @@ -2,6 +2,7 @@ Jython 2.5.2b2 Bugs Fixed + - [ 1506 ] Jython applies PEP263 pattern for determining source-code encoding on noncomments - [ 1630 ] threading.Thread lacks __tojava__ method Jython 2.5.2b1 Modified: trunk/jython/src/org/python/core/ParserFacade.java =================================================================== --- trunk/jython/src/org/python/core/ParserFacade.java 2010-07-14 05:12:19 UTC (rev 7078) +++ trunk/jython/src/org/python/core/ParserFacade.java 2010-07-20 03:50:50 UTC (rev 7079) @@ -344,9 +344,9 @@ } private static ExpectedEncodingBufferedReader prepBufReader(String string, - CompilerFlags cflags, - String filename) - throws IOException { + CompilerFlags cflags, + String filename) + throws IOException { if (cflags.source_is_utf8) return prepBufReader(new StringReader(string), cflags, filename); @@ -429,10 +429,10 @@ return encoding; } + private static final Pattern pep263EncodingPattern = Pattern.compile("#.*coding[:=]\\s*([-\\w.]+)"); + private static String matchEncoding(String inputStr) { - String patternStr = "coding[:=]\\s*([-\\w.]+)"; - Pattern pattern = Pattern.compile(patternStr); - Matcher matcher = pattern.matcher(inputStr); + Matcher matcher = pep263EncodingPattern.matcher(inputStr); boolean matchFound = matcher.find(); if (matchFound && matcher.groupCount() == 1) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |