|
44 | 44 | # Caveat emptor: These flags are undocumented on purpose and depending
|
45 | 45 | # on their effect outside the standard library is **unsupported**.
|
46 | 46 | PyCF_DONT_IMPLY_DEDENT = 0x200
|
| 47 | +PyCF_ONLY_AST = 0x400 |
47 | 48 | PyCF_ALLOW_INCOMPLETE_INPUT = 0x4000
|
48 | 49 |
|
49 | 50 | def _maybe_compile(compiler, source, filename, symbol):
|
@@ -73,23 +74,13 @@ def _maybe_compile(compiler, source, filename, symbol):
|
73 | 74 |
|
74 | 75 | return compiler(source, filename, symbol, incomplete_input=False)
|
75 | 76 |
|
76 |
| -def _is_syntax_error(err1, err2): |
77 |
| - rep1 = repr(err1) |
78 |
| - rep2 = repr(err2) |
79 |
| - if "was never closed" in rep1 and "was never closed" in rep2: |
80 |
| - return False |
81 |
| - if rep1 == rep2: |
82 |
| - return True |
83 |
| - return False |
84 |
| - |
85 | 77 | def _compile(source, filename, symbol, incomplete_input=True):
|
86 | 78 | flags = 0
|
87 | 79 | if incomplete_input:
|
88 | 80 | flags |= PyCF_ALLOW_INCOMPLETE_INPUT
|
89 | 81 | flags |= PyCF_DONT_IMPLY_DEDENT
|
90 | 82 | return compile(source, filename, symbol, flags)
|
91 | 83 |
|
92 |
| - |
93 | 84 | def compile_command(source, filename="<input>", symbol="single"):
|
94 | 85 | r"""Compile a command and determine whether it is incomplete.
|
95 | 86 |
|
@@ -119,12 +110,14 @@ class Compile:
|
119 | 110 | def __init__(self):
|
120 | 111 | self.flags = PyCF_DONT_IMPLY_DEDENT | PyCF_ALLOW_INCOMPLETE_INPUT
|
121 | 112 |
|
122 |
| - def __call__(self, source, filename, symbol, **kwargs): |
123 |
| - flags = self.flags |
| 113 | + def __call__(self, source, filename, symbol, flags=0, **kwargs): |
| 114 | + flags |= self.flags |
124 | 115 | if kwargs.get('incomplete_input', True) is False:
|
125 | 116 | flags &= ~PyCF_DONT_IMPLY_DEDENT
|
126 | 117 | flags &= ~PyCF_ALLOW_INCOMPLETE_INPUT
|
127 | 118 | codeob = compile(source, filename, symbol, flags, True)
|
| 119 | + if flags & PyCF_ONLY_AST: |
| 120 | + return codeob # this is an ast.Module in this case |
128 | 121 | for feature in _features:
|
129 | 122 | if codeob.co_flags & feature.compiler_flag:
|
130 | 123 | self.flags |= feature.compiler_flag
|
|
0 commit comments