def getstatementrange(self, lineno): |
""" return (start, end) tuple which spans the minimal |
statement region which containing the given lineno. |
""" |
|
|
-> if not (0 <= lineno < len(self)): |
raise IndexError("lineno out of range") |
|
|
from codeop import compile_command |
for start in range(lineno, -1, -1): |
trylines = self.lines[start:lineno+1] |
|
trylines.insert(0, 'if 0:') |
trysource = '\n '.join(trylines) |
|
try: |
compile_command(trysource) |
except (SyntaxError, OverflowError, ValueError): |
pass |
else: |
break |
|
|
for end in range(lineno+1, len(self)+1): |
trysource = self[start:end] |
if trysource.isparseable(): |
break |
|
return start, end |