From: <fwi...@us...> - 2008-08-12 18:11:41
|
Revision: 5157 http://jython.svn.sourceforge.net/jython/?rev=5157&view=rev Author: fwierzbicki Date: 2008-08-12 18:11:38 +0000 (Tue, 12 Aug 2008) Log Message: ----------- Disallow encodings from unicode input. Fixes one test in test_compile.py. Modified Paths: -------------- branches/asm/src/org/python/core/CompilerFlags.java branches/asm/src/org/python/core/ParserFacade.java branches/asm/src/org/python/core/PyTableCode.java branches/asm/src/org/python/core/__builtin__.java Modified: branches/asm/src/org/python/core/CompilerFlags.java =================================================================== --- branches/asm/src/org/python/core/CompilerFlags.java 2008-08-12 17:17:12 UTC (rev 5156) +++ branches/asm/src/org/python/core/CompilerFlags.java 2008-08-12 18:11:38 UTC (rev 5157) @@ -6,11 +6,13 @@ public boolean nested_scopes = true; public boolean division; public boolean generator_allowed = true; - public boolean only_ast = false; - public boolean dont_imply_dedent = false; public boolean with_statement = false; public boolean absolute_import = false; + public boolean only_ast = false; + public boolean dont_imply_dedent = false; + public boolean source_is_utf8 = false; + public String encoding; public CompilerFlags(){} @@ -37,13 +39,18 @@ if ((co_flags & org.python.core.PyTableCode.PyCF_DONT_IMPLY_DEDENT) != 0) { this.dont_imply_dedent = true; } + if ((co_flags & org.python.core.PyTableCode.PyCF_SOURCE_IS_UTF8) != 0) { + this.source_is_utf8 = true; + } + } - + public String toString() { return String.format("CompilerFlags[division=%s nested_scopes=%s generators=%s " + "with_statement=%s absolute_import=%s only_ast=%s " - + "dont_imply_dedent=%s]", division, nested_scopes, generator_allowed, - with_statement, absolute_import, only_ast, dont_imply_dedent); + + "dont_imply_dedent=%s source_is_utf8=%s]", division, nested_scopes, + generator_allowed, with_statement, absolute_import, only_ast, + dont_imply_dedent, source_is_utf8); } } Modified: branches/asm/src/org/python/core/ParserFacade.java =================================================================== --- branches/asm/src/org/python/core/ParserFacade.java 2008-08-12 17:17:12 UTC (rev 5156) +++ branches/asm/src/org/python/core/ParserFacade.java 2008-08-12 18:11:38 UTC (rev 5157) @@ -199,13 +199,17 @@ InputStream bstream = new BufferedInputStream(istream); bom = adjustForBOM(bstream); encoding = readEncoding(bstream); - if(encoding == null) { + + if (encoding == null) { if (bom) { encoding = "UTF-8"; } else if (cflags != null && cflags.encoding != null) { encoding = cflags.encoding; } + } else if (cflags.source_is_utf8) { + throw new ParseException("encoding declaration in Unicode string"); } + // Enable universal newlines mode on the input StreamIO rawIO = new StreamIO(bstream, true); org.python.core.io.BufferedReader bufferedIO = Modified: branches/asm/src/org/python/core/PyTableCode.java =================================================================== --- branches/asm/src/org/python/core/PyTableCode.java 2008-08-12 17:17:12 UTC (rev 5156) +++ branches/asm/src/org/python/core/PyTableCode.java 2008-08-12 18:11:38 UTC (rev 5157) @@ -32,17 +32,19 @@ final public static int CO_GENERATOR = 0x0020; // these are defined in __future__.py - final public static int CO_NESTED = 0x0010; - final public static int CO_GENERATOR_ALLOWED = 0x0; - final public static int CO_FUTUREDIVISION = 0x2000; + final public static int CO_NESTED = 0x0010; + final public static int CO_GENERATOR_ALLOWED = 0x0; + final public static int CO_FUTUREDIVISION = 0x2000; final public static int CO_FUTURE_ABSOLUTE_IMPORT = 0x4000; - final public static int CO_WITH_STATEMENT = 0x8000; + final public static int CO_WITH_STATEMENT = 0x8000; //XXX: I'm not positive that this is the right place for these constants. + final public static int PyCF_SOURCE_IS_UTF8 = 0x0100; final public static int PyCF_DONT_IMPLY_DEDENT = 0x0200; final public static int PyCF_ONLY_AST = 0x0400; - final public static int CO_ALL_FEATURES = PyCF_DONT_IMPLY_DEDENT|PyCF_ONLY_AST|CO_NESTED| + final public static int CO_ALL_FEATURES = PyCF_DONT_IMPLY_DEDENT|PyCF_ONLY_AST| + PyCF_SOURCE_IS_UTF8|CO_NESTED| CO_GENERATOR_ALLOWED| CO_FUTUREDIVISION| CO_FUTURE_ABSOLUTE_IMPORT|CO_WITH_STATEMENT; Modified: branches/asm/src/org/python/core/__builtin__.java =================================================================== --- branches/asm/src/org/python/core/__builtin__.java 2008-08-12 17:17:12 UTC (rev 5156) +++ branches/asm/src/org/python/core/__builtin__.java 2008-08-12 18:11:38 UTC (rev 5157) @@ -276,6 +276,9 @@ dont_inherit = Py.py2boolean(args[4]); } + if (args[0] instanceof PyUnicode) { + flags += PyTableCode.PyCF_SOURCE_IS_UTF8; + } return __builtin__.compile(args[0].toString(), args[1].toString(), args[2].toString(), flags, dont_inherit); case 29: return __builtin__.map(args); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |