summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/code.py3
-rw-r--r--Lib/codeop.py9
-rw-r--r--Lib/test/test_codeop.py7
-rw-r--r--Lib/test/test_compile.py9
4 files changed, 22 insertions, 6 deletions
diff --git a/Lib/code.py b/Lib/code.py
index 75c64e6..6bdc658 100644
--- a/Lib/code.py
+++ b/Lib/code.py
@@ -303,4 +303,5 @@ def interact(banner=None, readfunc=None, local=None):
if __name__ == '__main__':
- interact()
+ import pdb
+ pdb.run("interact()\n")
diff --git a/Lib/codeop.py b/Lib/codeop.py
index c97b4df..cc9d5b2 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="<input>", symbol="single"):
r"""Compile a command and determine whether it is incomplete.
@@ -121,7 +126,7 @@ def compile_command(source, filename="<input>", 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)
diff --git a/Lib/test/test_codeop.py b/Lib/test/test_codeop.py
index a0ce0bc..7af83eb 100644
--- a/Lib/test/test_codeop.py
+++ b/Lib/test/test_codeop.py
@@ -5,13 +5,13 @@
import unittest
from test.test_support import run_unittest
-from codeop import compile_command
+from codeop import compile_command, PyCF_DONT_IMPLY_DEDENT
class CodeopTests(unittest.TestCase):
def assertValid(self, str, symbol='single'):
'''succeed iff str is a valid piece of code'''
- expected = compile(str, "<input>", symbol)
+ expected = compile(str, "<input>", symbol, PyCF_DONT_IMPLY_DEDENT)
self.assertEquals( compile_command(str, "<input>", symbol), expected)
@@ -42,7 +42,8 @@ class CodeopTests(unittest.TestCase):
# special case
self.assertEquals(compile_command(""),
- compile("pass", "<input>", 'single'))
+ compile("pass", "<input>", 'single',
+ PyCF_DONT_IMPLY_DEDENT))
av("3**3","eval")
av("(lambda z: \n z**3)","eval")
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 1fe7f52..1812fbc 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -89,6 +89,15 @@ expect_error("2.0e+")
expect_error("1e-")
expect_error("3-4e/21")
+if verbose:
+ print "testing compile() of indented block w/o trailing newline"
+
+s = """
+if 1:
+ if 2:
+ pass"""
+compile(s, "<string>", "exec")
+
if verbose:
print "testing literals with leading zeroes"