def MonkeyPatchPdb(pdb):
 def NewSetTrace():
  'Replacement for set_trace() that uses the original i/o streams.\n\n    This is necessary because by the time the user code that might\n    invoke pdb.set_trace() runs, the default sys.stdin and sys.stdout\n    are redirected to the HTTP request and response streams instead,\n    so that pdb will encounter garbage (or EOF) in its input, and its\n    output will garble the HTTP response.  Fortunately, sys.__stdin__\n    and sys.__stderr__ retain references to the original streams --\n    this is a standard Python feature.  Also, fortunately, as of\n    Python 2.5, the Pdb class lets you easily override stdin and\n    stdout.  The original set_trace() function does essentially the\n    same thing as the code here except it instantiates Pdb() without\n    arguments.\n    '
  p = pdb.Pdb(stdin=sys.__stdin__, stdout=sys.__stdout__)
  p.set_trace(sys._getframe().f_back)
 pdb.set_trace = NewSetTrace

def MonkeyPatchPdb ( pdb ) : def NewSetTrace ( ) : p = pdb . Pdb ( stdin = sys . __stdin__ , stdout = sys . __stdout__ ) p . set_trace ( sys . _getframe ( ) . f_back ) pdb . set_trace = NewSetTrace
given a reference to the pdb module .