Compile and run some source in the interpreter. Arguments are as for compile_command(). One of several things can happen: 1) The input is incorrect; compile_command() raised an exception (SyntaxError or OverflowError). A syntax traceback will be printed by
(self, source, filename="<input>", symbol="single")
| 265 | self.compile = CommandCompiler() |
| 266 | |
| 267 | def runsource(self, source, filename="<input>", symbol="single"): |
| 268 | """Compile and run some source in the interpreter. |
| 269 | |
| 270 | Arguments are as for compile_command(). |
| 271 | |
| 272 | One of several things can happen: |
| 273 | |
| 274 | 1) The input is incorrect; compile_command() raised an |
| 275 | exception (SyntaxError or OverflowError). A syntax traceback |
| 276 | will be printed by calling the showsyntaxerror() method. |
| 277 | |
| 278 | 2) The input is incomplete, and more input is required; |
| 279 | compile_command() returned None. Nothing happens. |
| 280 | |
| 281 | 3) The input is complete; compile_command() returned a code |
| 282 | object. The code is executed by calling self.runcode() (which |
| 283 | also handles run-time exceptions, except for SystemExit). |
| 284 | |
| 285 | The return value is True in case 2, False in the other cases (unless |
| 286 | an exception is raised). The return value can be used to |
| 287 | decide whether to use sys.ps1 or sys.ps2 to prompt the next |
| 288 | line. |
| 289 | |
| 290 | """ |
| 291 | try: |
| 292 | code = self.compile(source, filename, symbol) |
| 293 | except (OverflowError, SyntaxError, ValueError): |
| 294 | # Case 1 |
| 295 | self.showsyntaxerror(filename) |
| 296 | return False |
| 297 | |
| 298 | if code is None: |
| 299 | # Case 2 |
| 300 | return True |
| 301 | |
| 302 | # Case 3 |
| 303 | self.runcode(code) |
| 304 | return False |
| 305 | |
| 306 | def runcode(self, code): |
| 307 | """Execute a code object. |
no test coverage detected