MCPcopy Create free account
hub / github.com/fabioz/PyDev.Debugger / interact

Method interact

_pydevd_bundle/pydevconsole_code.py:430–480  ·  view source on GitHub ↗

Closely emulate the interactive Python console. The optional banner argument specifies the banner to print before the first interaction; by default it prints a banner similar to the one printed by the real Python interpreter, followed by the current class name in par

(self, banner=None, exitmsg=None)

Source from the content-addressed store, hash-verified

428 self.buffer = []
429
430 def interact(self, banner=None, exitmsg=None):
431 """Closely emulate the interactive Python console.
432
433 The optional banner argument specifies the banner to print
434 before the first interaction; by default it prints a banner
435 similar to the one printed by the real Python interpreter,
436 followed by the current class name in parentheses (so as not
437 to confuse this with the real interpreter -- since it's so
438 close!).
439
440 The optional exitmsg argument specifies the exit message
441 printed when exiting. Pass the empty string to suppress
442 printing an exit message. If exitmsg is not given or None,
443 a default message is printed.
444
445 """
446 try:
447 sys.ps1
448 except AttributeError:
449 sys.ps1 = ">>> "
450 try:
451 sys.ps2
452 except AttributeError:
453 sys.ps2 = "... "
454 cprt = 'Type "help", "copyright", "credits" or "license" for more information.'
455 if banner is None:
456 self.write("Python %s on %s\n%s\n(%s)\n" % (sys.version, sys.platform, cprt, self.__class__.__name__))
457 elif banner:
458 self.write("%s\n" % str(banner))
459 more = 0
460 while 1:
461 try:
462 if more:
463 prompt = sys.ps2
464 else:
465 prompt = sys.ps1
466 try:
467 line = self.raw_input(prompt)
468 except EOFError:
469 self.write("\n")
470 break
471 else:
472 more = self.push(line)
473 except KeyboardInterrupt:
474 self.write("\nKeyboardInterrupt\n")
475 self.resetbuffer()
476 more = 0
477 if exitmsg is None:
478 self.write("now exiting %s...\n" % self.__class__.__name__)
479 elif exitmsg != "":
480 self.write("%s\n" % exitmsg)
481
482 def push(self, line):
483 """Push a line to the interpreter.

Callers 2

interactFunction · 0.95
_spawn_python_shellMethod · 0.80

Calls 4

raw_inputMethod · 0.95
pushMethod · 0.95
resetbufferMethod · 0.95
writeMethod · 0.45

Tested by

no test coverage detected