|
116 | 116 | * alt impl using a state machine (& tokenizer or split on delimiters) |
117 | 117 | """ |
118 | 118 |
|
| 119 | +import textwrap |
| 120 | + |
119 | 121 | from ..info import ParsedItem |
120 | 122 | from ._info import SourceInfo |
121 | 123 |
|
@@ -208,7 +210,27 @@ def _iter_source(lines, *, maxtext=11_000, maxlines=200, showtext=False): |
208 | 210 | return |
209 | 211 | # At this point either the file ended prematurely |
210 | 212 | # or there's "too much" text. |
211 | | - filename, lno, text = srcinfo.filename, srcinfo._start, srcinfo.text |
| 213 | + filename, lno_from, lno_to = srcinfo.filename, srcinfo.start, srcinfo.end |
| 214 | + text = srcinfo.text |
212 | 215 | if len(text) > 500: |
213 | 216 | text = text[:500] + '...' |
214 | | - raise Exception(f'unmatched text ({filename} starting at line {lno}):\n{text}') |
| 217 | + |
| 218 | + if srcinfo.too_much_text(maxtext): |
| 219 | + msg = f''' |
| 220 | + too much text, try to increase MAX_SIZES[MAXTEXT] in cpython/_parser.py |
| 221 | + {filename} starting at line {lno_from} to {lno_to} |
| 222 | + has code with length {len(text)} greater than {maxtext}: |
| 223 | + {text} |
| 224 | + ''' |
| 225 | + raise RuntimeError(textwrap.dedent(msg)) |
| 226 | + |
| 227 | + if srcinfo.too_many_lines(maxlines): |
| 228 | + msg = f''' |
| 229 | + too many lines, try to increase MAX_SIZES[MAXLINES] in cpython/_parser.py |
| 230 | + {filename} starting at line {lno_from} to {lno_to} |
| 231 | + has code with number of lines {lno_to - lno_from} greater than {maxlines}: |
| 232 | + {text} |
| 233 | + ''' |
| 234 | + raise RuntimeError(textwrap.dedent(msg)) |
| 235 | + |
| 236 | + raise RuntimeError(f'unmatched text ({filename} starting at line {lno_from}):\n{text}') |
0 commit comments