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 """ return True if source is parseable, heuristically
deindenting it by default. deindenting it by default.
""" """
try:
import parser
except ImportError:
syntax_checker = lambda x: compile(x, 'asd', 'exec')
else:
syntax_checker = parser.suite
if deindent: if deindent:
source = str(self.deindent()) source = str(self.deindent())
else: else:
source = str(self) source = str(self)
try: try:
compile(source+'\n', "x", "exec") #compile(source+'\n', "x", "exec")
syntax_checker(source+'\n')
except SyntaxError: except SyntaxError:
return False return False
else: else: