MCPcopy Index your code
hub / github.com/python/cpython / _OutputRedirectingPdb

Class _OutputRedirectingPdb

Lib/doctest.py:375–409  ·  view source on GitHub ↗

A specialized version of the python debugger that redirects stdout to a given stream when interacting with the user. Stdout is *not* redirected when traced code is executed.

Source from the content-addressed store, hash-verified

373 return msg[start: end]
374
375class _OutputRedirectingPdb(pdb.Pdb):
376 """
377 A specialized version of the python debugger that redirects stdout
378 to a given stream when interacting with the user. Stdout is *not*
379 redirected when traced code is executed.
380 """
381 def __init__(self, out):
382 self.__out = out
383 self.__debugger_used = False
384 # do not play signal games in the pdb
385 super().__init__(stdout=out, nosigint=True)
386 # still use input() to get user input
387 self.use_rawinput = 1
388
389 def set_trace(self, frame=None, *, commands=None):
390 self.__debugger_used = True
391 if frame is None:
392 frame = sys._getframe().f_back
393 pdb.Pdb.set_trace(self, frame, commands=commands)
394
395 def set_continue(self):
396 # Calling set_continue unconditionally would break unit test
397 # coverage reporting, as Bdb.set_continue calls sys.settrace(None).
398 if self.__debugger_used:
399 pdb.Pdb.set_continue(self)
400
401 def trace_dispatch(self, *args):
402 # Redirect stdout to the given stream.
403 save_stdout = sys.stdout
404 sys.stdout = self.__out
405 # Call Pdb's trace dispatch method.
406 try:
407 return pdb.Pdb.trace_dispatch(self, *args)
408 finally:
409 sys.stdout = save_stdout
410
411# [XX] Normalize with respect to os.path.pardir?
412def _module_relative_path(module, test_path):

Callers 1

runMethod · 0.85

Calls

no outgoing calls

Tested by 1

runMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…