From 734a40eb280146bd8fd52b6a78761bbd54cd95e6 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Sun, 6 Sep 2009 12:35:52 +0200 Subject: [PATCH] seems like compile is way slower than just parser.suite so we try to see if it's available (only jython doesn't have it) --HG-- branch : trunk --- py/code/source.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/py/code/source.py b/py/code/source.py index 4e16e2094..ffe78716f 100644 --- a/py/code/source.py +++ b/py/code/source.py @@ -157,12 +157,20 @@ class Source(object): """ return True if source is parseable, heuristically deindenting it by default. """ + try: + import parser + except ImportError: + syntax_checker = lambda x: compile(x, 'asd', 'exec') + else: + syntax_checker = parser.suite + if deindent: source = str(self.deindent()) else: source = str(self) try: - compile(source+'\n', "x", "exec") + #compile(source+'\n', "x", "exec") + syntax_checker(source+'\n') except SyntaxError: return False else: