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
This commit is contained in:
holger krekel 2009-09-06 12:35:52 +02:00
parent 518194537e
commit 734a40eb28
1 changed files with 9 additions and 1 deletions

View File

@ -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: