def parse(source, filename='<string>'):
# NOTE: the raw string should be given to `compile` function
if isinstance(source, unicode):
source = fscommands.unicode_to_file_data(source)
if '\r' in source:
source = source.replace('\r\n', '\n').replace('\r', '\n')
if not source.endswith('\n'):
source += '\n'
try:
return compile(source, filename, 'exec', _ast.PyCF_ONLY_AST)
except (TypeError, ValueError), e:
error = SyntaxError()
error.lineno = 1
error.filename = filename
error.msg = str(e)
raise error
评论列表
文章目录