From 69e05a124cc22e3eb35be442ac83a0d1c8e79575 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 13 Feb 2003 22:07:59 +0000 Subject: - Finally fixed the bug in compile() and exec where a string ending with an indented code block but no newline would raise SyntaxError. This would have been a four-line change in parsetok.c... Except codeop.py depends on this behavior, so a compilation flag had to be invented that causes the tokenizer to revert to the old behavior; this required extra changes to 2 .h files, 2 .c files, and 2 .py files. (Fixes SF bug #501622.) --- Lib/codeop.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'Lib/codeop.py') diff --git a/Lib/codeop.py b/Lib/codeop.py index c97b4df293..cc9d5b26f1 100644 --- a/Lib/codeop.py +++ b/Lib/codeop.py @@ -63,6 +63,8 @@ _features = [getattr(__future__, fname) __all__ = ["compile_command", "Compile", "CommandCompiler"] +PyCF_DONT_IMPLY_DEDENT = 0x200 # Matches pythonrun.h + def _maybe_compile(compiler, source, filename, symbol): # Check for source consisting of only blank lines and comments for line in source.split("\n"): @@ -103,6 +105,9 @@ def _maybe_compile(compiler, source, filename, symbol): if not code1 and e1 == e2: raise SyntaxError, err1 +def _compile(source, filename, symbol): + return compile(source, filename, symbol, PyCF_DONT_IMPLY_DEDENT) + def compile_command(source, filename="", symbol="single"): r"""Compile a command and determine whether it is incomplete. @@ -121,7 +126,7 @@ def compile_command(source, filename="", symbol="single"): syntax error (OverflowError and ValueError can be produced by malformed literals). """ - return _maybe_compile(compile, source, filename, symbol) + return _maybe_compile(_compile, source, filename, symbol) class Compile: """Instances of this class behave much like the built-in compile @@ -129,7 +134,7 @@ class Compile: statement, it "remembers" and compiles all subsequent program texts with the statement in force.""" def __init__(self): - self.flags = 0 + self.flags = PyCF_DONT_IMPLY_DEDENT def __call__(self, source, filename, symbol): codeob = compile(source, filename, symbol, self.flags, 1) -- cgit v1.2.1