home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 January / Chip_2003-01_cd2.bin / convert / eJayMp3Pro / mp3pro_demo.exe / PDB.PYC (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2000-06-29  |  35.3 KB  |  910 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4. import string
  5. import sys
  6. import linecache
  7. import cmd
  8. import bdb
  9. import repr
  10. import os
  11. line_prefix = '\n-> '
  12.  
  13. class Pdb(bdb.Bdb, cmd.Cmd):
  14.     
  15.     def __init__(self):
  16.         bdb.Bdb.__init__(self)
  17.         cmd.Cmd.__init__(self)
  18.         self.prompt = '(Pdb) '
  19.         self.lineinfoCmd = 'egrep -n "def *%s *[(:]" %s /dev/null'
  20.         self.aliases = { }
  21.         
  22.         try:
  23.             import readline
  24.         except ImportError:
  25.             pass
  26.  
  27.         self.rcLines = []
  28.         
  29.         try:
  30.             rcFile = open('./.pdbrc')
  31.         except IOError:
  32.             None if os.environ.has_key('HOME') else rcFile.readlines()
  33.             None if os.environ.has_key('HOME') else rcFile.readlines()
  34.         except:
  35.             None if os.environ.has_key('HOME') else rcFile.readlines()
  36.  
  37.         for line in rcFile.readlines():
  38.             self.rcLines.append(line)
  39.         
  40.         rcFile.close()
  41.  
  42.     
  43.     def reset(self):
  44.         bdb.Bdb.reset(self)
  45.         self.forget()
  46.  
  47.     
  48.     def forget(self):
  49.         self.lineno = None
  50.         self.stack = []
  51.         self.curindex = 0
  52.         self.curframe = None
  53.  
  54.     
  55.     def setup(self, f, t):
  56.         self.forget()
  57.         (self.stack, self.curindex) = self.get_stack(f, t)
  58.         self.curframe = self.stack[self.curindex][0]
  59.         self.execRcLines()
  60.  
  61.     
  62.     def execRcLines(self):
  63.         if self.rcLines:
  64.             rcLines = self.rcLines
  65.             self.rcLines = []
  66.             for line in rcLines:
  67.                 line = line[:-1]
  68.             
  69.         
  70.  
  71.     
  72.     def user_line(self, frame):
  73.         self.interaction(frame, None)
  74.  
  75.     
  76.     def user_return(self, frame, return_value):
  77.         frame.f_locals['__return__'] = return_value
  78.         print '--Return--'
  79.         self.interaction(frame, None)
  80.  
  81.     
  82.     def user_exception(self, frame, .4):
  83.         (exc_type, exc_value, exc_traceback) = .4
  84.         frame.f_locals['__exception__'] = (exc_type, exc_value)
  85.         if type(exc_type) == type(''):
  86.             exc_type_name = exc_type
  87.         else:
  88.             exc_type_name = exc_type.__name__
  89.         print exc_type_name + ':', repr.repr(exc_value)
  90.         self.interaction(frame, exc_traceback)
  91.  
  92.     
  93.     def interaction(self, frame, traceback):
  94.         self.setup(frame, traceback)
  95.         self.print_stack_entry(self.stack[self.curindex])
  96.         self.cmdloop()
  97.         self.forget()
  98.  
  99.     
  100.     def default(self, line):
  101.         if line[:1] == '!':
  102.             line = line[1:]
  103.         
  104.         locals = self.curframe.f_locals
  105.         globals = self.curframe.f_globals
  106.         
  107.         try:
  108.             code = compile(line + '\n', '<stdin>', 'single')
  109.             exec code in globals, locals
  110.         except:
  111.             (t, v) = sys.exc_info()[:2]
  112.             if type(t) == type(''):
  113.                 exc_type_name = t
  114.             else:
  115.                 exc_type_name = t.__name__
  116.             print '***', exc_type_name + ':', v
  117.  
  118.  
  119.     
  120.     def precmd(self, line):
  121.         if not line:
  122.             return line
  123.         
  124.         args = string.split(line)
  125.         while self.aliases.has_key(args[0]):
  126.             line = self.aliases[args[0]]
  127.             ii = 1
  128.             for tmpArg in args[1:]:
  129.                 line = string.replace(line, '%' + str(ii), tmpArg)
  130.                 ii = ii + 1
  131.             
  132.             line = string.replace(line, '%*', string.join(args[1:], ' '))
  133.             args = string.split(line)
  134.             continue
  135.             0
  136.         if args[0] != 'alias':
  137.             marker = string.find(line, ';;')
  138.             if marker >= 0:
  139.                 next = string.lstrip(line[marker + 2:])
  140.                 self.cmdqueue.append(next)
  141.                 line = string.rstrip(line[:marker])
  142.             
  143.         
  144.         return line
  145.  
  146.     do_h = cmd.Cmd.do_help
  147.     
  148.     def do_EOF(self, arg):
  149.         return 0
  150.  
  151.     
  152.     def do_break(self, arg, temporary = 0):
  153.         if not arg:
  154.             if self.breaks:
  155.                 print 'Num Type         Disp Enb   Where'
  156.                 for bp in bdb.Breakpoint.bpbynumber:
  157.                     pass
  158.                 
  159.             
  160.             return None
  161.         
  162.         filename = None
  163.         lineno = None
  164.         cond = None
  165.         comma = string.find(arg, ',')
  166.         if comma > 0:
  167.             cond = string.lstrip(arg[comma + 1:])
  168.             arg = string.rstrip(arg[:comma])
  169.         
  170.         colon = string.rfind(arg, ':')
  171.         if colon >= 0:
  172.             filename = string.rstrip(arg[:colon])
  173.             f = self.lookupmodule(filename)
  174.             if not f:
  175.                 print '*** ', `filename`, 'not found from sys.path'
  176.                 return None
  177.             else:
  178.                 filename = f
  179.             arg = string.lstrip(arg[colon + 1:])
  180.             
  181.             try:
  182.                 lineno = int(arg)
  183.             except ValueError:
  184.                 msg = None
  185.                 print '*** Bad lineno:', arg
  186.                 return None
  187.  
  188.         else:
  189.             
  190.             try:
  191.                 lineno = int(arg)
  192.             except ValueError:
  193.                 
  194.                 try:
  195.                     func = eval(arg, self.curframe.f_globals, self.curframe.f_locals)
  196.                 except:
  197.                     func = arg
  198.  
  199.                 
  200.                 try:
  201.                     if hasattr(func, 'im_func'):
  202.                         func = func.im_func
  203.                     
  204.                     code = func.func_code
  205.                     lineno = code.co_firstlineno
  206.                     filename = code.co_filename
  207.                 except:
  208.                     (ok, filename, ln) = self.lineinfo(arg)
  209.                     if not ok:
  210.                         print '*** The specified object', `arg`, 'is not a function'
  211.                         print 'or was not found along sys.path.'
  212.                         return None
  213.                     
  214.                     lineno = int(ln)
  215.  
  216.  
  217.         if not filename:
  218.             filename = self.defaultFile()
  219.         
  220.         line = self.checkline(filename, lineno)
  221.         if line:
  222.             err = self.set_break(filename, line, temporary, cond)
  223.             if err:
  224.                 print '***', err
  225.             else:
  226.                 bp = self.get_breaks(filename, line)[-1]
  227.                 print 'Breakpoint %d at %s:%d' % (bp.number, bp.file, bp.line)
  228.         
  229.  
  230.     
  231.     def defaultFile(self):
  232.         filename = self.curframe.f_code.co_filename
  233.         if filename == '<string>' and mainpyfile:
  234.             filename = mainpyfile
  235.         
  236.         return filename
  237.  
  238.     do_b = do_break
  239.     
  240.     def do_tbreak(self, arg):
  241.         self.do_break(arg, 1)
  242.  
  243.     
  244.     def lineinfo(self, identifier):
  245.         failed = (None, None, None)
  246.         idstring = string.split(identifier, "'")
  247.         if len(idstring) == 1:
  248.             id = string.strip(idstring[0])
  249.         elif len(idstring) == 3:
  250.             id = string.strip(idstring[1])
  251.         else:
  252.             return failed
  253.         if id == '':
  254.             return failed
  255.         
  256.         parts = string.split(id, '.')
  257.         if parts[0] == 'self':
  258.             del parts[0]
  259.             if len(parts) == 0:
  260.                 return failed
  261.             
  262.         
  263.         fname = self.defaultFile()
  264.         if len(parts) == 1:
  265.             item = parts[0]
  266.         else:
  267.             f = self.lookupmodule(parts[0])
  268.             if f:
  269.                 fname = f
  270.             
  271.             item = parts[1]
  272.         grepstring = self.lineinfoCmd % (item, fname)
  273.         answer = os.popen(grepstring, 'r').readline()
  274.         if answer:
  275.             (f, line, junk) = string.split(answer, ':', 2)
  276.             return (item, f, line)
  277.         else:
  278.             return failed
  279.  
  280.     
  281.     def checkline(self, filename, lineno):
  282.         """Return line number of first line at or after input
  283. \t\targument such that if the input points to a 'def', the
  284. \t\treturned line number is the first
  285. \t\tnon-blank/non-comment line to follow.  If the input
  286. \t\tpoints to a blank or comment line, return 0.  At end
  287. \t\tof file, also return 0."""
  288.         line = linecache.getline(filename, lineno)
  289.         if not line:
  290.             print 'End of file'
  291.             return 0
  292.         
  293.         line = string.strip(line)
  294.         if not line and line[0] == '#' and line[:3] == '"""' or line[:3] == "'''":
  295.             print '*** Blank or comment'
  296.             return 0
  297.         
  298.         if line[:3] == 'def':
  299.             incomment = ''
  300.             while 1:
  301.                 lineno = lineno + 1
  302.                 line = linecache.getline(filename, lineno)
  303.                 if not line:
  304.                     print 'end of file'
  305.                     return 0
  306.                 
  307.                 line = string.strip(line)
  308.                 if incomment:
  309.                     if len(line) < 3:
  310.                         continue
  311.                     
  312.                     if line[-3:] == incomment:
  313.                         incomment = ''
  314.                     
  315.                     continue
  316.                 
  317.                 if not line:
  318.                     continue
  319.                 
  320.                 if len(line) >= 3:
  321.                     if line[:3] == '"""' or line[:3] == "'''":
  322.                         incomment = line[:3]
  323.                         continue
  324.                     
  325.                 
  326.                 if line[0] != '#':
  327.                     break
  328.                 
  329.         
  330.         return lineno
  331.  
  332.     
  333.     def do_enable(self, arg):
  334.         args = string.split(arg)
  335.         for i in args:
  336.             bp = bdb.Breakpoint.bpbynumber[int(i)]
  337.         
  338.  
  339.     
  340.     def do_disable(self, arg):
  341.         args = string.split(arg)
  342.         for i in args:
  343.             bp = bdb.Breakpoint.bpbynumber[int(i)]
  344.         
  345.  
  346.     
  347.     def do_condition(self, arg):
  348.         args = string.split(arg, ' ', 1)
  349.         bpnum = int(string.strip(args[0]))
  350.         
  351.         try:
  352.             cond = args[1]
  353.         except:
  354.             cond = None
  355.  
  356.         bp = bdb.Breakpoint.bpbynumber[bpnum]
  357.         if bp:
  358.             bp.cond = cond
  359.             if not cond:
  360.                 print 'Breakpoint', bpnum, 'is now unconditional.'
  361.             
  362.         
  363.  
  364.     
  365.     def do_ignore(self, arg):
  366.         args = string.split(arg)
  367.         bpnum = int(string.strip(args[0]))
  368.         
  369.         try:
  370.             count = int(string.strip(args[1]))
  371.         except:
  372.             count = 0
  373.  
  374.         bp = bdb.Breakpoint.bpbynumber[bpnum]
  375.         if bp:
  376.             bp.ignore = count
  377.             if count > 0:
  378.                 reply = 'Will ignore next '
  379.                 if count > 1:
  380.                     reply = reply + '%d crossings' % count
  381.                 else:
  382.                     reply = reply + '1 crossing'
  383.                 print reply + ' of breakpoint %d.' % bpnum
  384.             else:
  385.                 print 'Will stop next time breakpoint', bpnum, 'is reached.'
  386.         
  387.  
  388.     
  389.     def do_clear(self, arg):
  390.         if not arg:
  391.             
  392.             try:
  393.                 reply = raw_input('Clear all breaks? ')
  394.             except EOFError:
  395.                 reply = 'no'
  396.  
  397.             reply = string.lower(string.strip(reply))
  398.             if reply in ('y', 'yes'):
  399.                 self.clear_all_breaks()
  400.             
  401.             return None
  402.         
  403.         if ':' in arg:
  404.             i = string.rfind(arg, ':')
  405.             filename = arg[:i]
  406.             arg = arg[i + 1:]
  407.             
  408.             try:
  409.                 lineno = int(arg)
  410.             except:
  411.                 err = 'Invalid line number (%s)' % arg
  412.  
  413.             err = self.clear_break(filename, lineno)
  414.             if err:
  415.                 print '***', err
  416.             
  417.             return None
  418.         
  419.         numberlist = string.split(arg)
  420.         for i in numberlist:
  421.             err = self.clear_bpbynumber(i)
  422.             if err:
  423.                 print '***', err
  424.             else:
  425.                 print 'Deleted breakpoint %s ' % (i,)
  426.         
  427.  
  428.     do_cl = do_clear
  429.     
  430.     def do_where(self, arg):
  431.         self.print_stack_trace()
  432.  
  433.     do_w = do_where
  434.     
  435.     def do_up(self, arg):
  436.         if self.curindex == 0:
  437.             print '*** Oldest frame'
  438.         else:
  439.             self.curindex = self.curindex - 1
  440.             self.curframe = self.stack[self.curindex][0]
  441.             self.print_stack_entry(self.stack[self.curindex])
  442.             self.lineno = None
  443.  
  444.     do_u = do_up
  445.     
  446.     def do_down(self, arg):
  447.         if self.curindex + 1 == len(self.stack):
  448.             print '*** Newest frame'
  449.         else:
  450.             self.curindex = self.curindex + 1
  451.             self.curframe = self.stack[self.curindex][0]
  452.             self.print_stack_entry(self.stack[self.curindex])
  453.             self.lineno = None
  454.  
  455.     do_d = do_down
  456.     
  457.     def do_step(self, arg):
  458.         self.set_step()
  459.         return 1
  460.  
  461.     do_s = do_step
  462.     
  463.     def do_next(self, arg):
  464.         self.set_next(self.curframe)
  465.         return 1
  466.  
  467.     do_n = do_next
  468.     
  469.     def do_return(self, arg):
  470.         self.set_return(self.curframe)
  471.         return 1
  472.  
  473.     do_r = do_return
  474.     
  475.     def do_continue(self, arg):
  476.         self.set_continue()
  477.         return 1
  478.  
  479.     do_c = do_cont = do_continue
  480.     
  481.     def do_quit(self, arg):
  482.         self.set_quit()
  483.         return 1
  484.  
  485.     do_q = do_quit
  486.     
  487.     def do_args(self, arg):
  488.         f = self.curframe
  489.         co = f.f_code
  490.         dict = f.f_locals
  491.         n = co.co_argcount
  492.         if co.co_flags & 4:
  493.             n = n + 1
  494.         
  495.         if co.co_flags & 8:
  496.             n = n + 1
  497.         
  498.         for i in range(n):
  499.             name = co.co_varnames[i]
  500.             print name, '=',
  501.             if dict.has_key(name):
  502.                 print dict[name]
  503.             else:
  504.                 print '*** undefined ***'
  505.         
  506.  
  507.     do_a = do_args
  508.     
  509.     def do_retval(self, arg):
  510.         if self.curframe.f_locals.has_key('__return__'):
  511.             print self.curframe.f_locals['__return__']
  512.         else:
  513.             print '*** Not yet returned!'
  514.  
  515.     do_rv = do_retval
  516.     
  517.     def do_p(self, arg):
  518.         
  519.         try:
  520.             value = eval(arg, self.curframe.f_globals, self.curframe.f_locals)
  521.         except:
  522.             (t, v) = sys.exc_info()[:2]
  523.             if type(t) == type(''):
  524.                 exc_type_name = t
  525.             else:
  526.                 exc_type_name = t.__name__
  527.             print '***', exc_type_name + ':', `v`
  528.             return None
  529.  
  530.         print `value`
  531.  
  532.     
  533.     def do_list(self, arg):
  534.         self.lastcmd = 'list'
  535.         last = None
  536.         if arg:
  537.             
  538.             try:
  539.                 x = eval(arg, { }, { })
  540.                 if type(x) == type(()):
  541.                     (first, last) = x
  542.                     first = int(first)
  543.                     last = int(last)
  544.                     if last < first:
  545.                         last = first + last
  546.                     
  547.                 else:
  548.                     first = max(1, int(x) - 5)
  549.             except:
  550.                 print '*** Error in argument:', `arg`
  551.                 return None
  552.  
  553.         elif self.lineno is None:
  554.             first = max(1, self.curframe.f_lineno - 5)
  555.         else:
  556.             first = self.lineno + 1
  557.         if last == None:
  558.             last = first + 10
  559.         
  560.         filename = self.curframe.f_code.co_filename
  561.         breaklist = self.get_file_breaks(filename)
  562.         
  563.         try:
  564.             for lineno in range(first, last + 1):
  565.                 line = linecache.getline(filename, lineno)
  566.                 if not line:
  567.                     print '[EOF]'
  568.                     break
  569.                 else:
  570.                     s = string.rjust(`lineno`, 3)
  571.                     if len(s) < 4:
  572.                         s = s + ' '
  573.                     
  574.                     if lineno in breaklist:
  575.                         s = s + 'B'
  576.                     else:
  577.                         s = s + ' '
  578.                     if lineno == self.curframe.f_lineno:
  579.                         s = s + '->'
  580.                     
  581.                     print s + '\t' + line,
  582.                     self.lineno = lineno
  583.         except KeyboardInterrupt:
  584.             pass
  585.  
  586.  
  587.     do_l = do_list
  588.     
  589.     def do_whatis(self, arg):
  590.         
  591.         try:
  592.             value = eval(arg, self.curframe.f_globals, self.curframe.f_locals)
  593.         except:
  594.             (t, v) = sys.exc_info()[:2]
  595.             if type(t) == type(''):
  596.                 exc_type_name = t
  597.             else:
  598.                 exc_type_name = t.__name__
  599.             print '***', exc_type_name + ':', `v`
  600.             return None
  601.  
  602.         code = None
  603.         
  604.         try:
  605.             code = value.func_code
  606.         except:
  607.             pass
  608.  
  609.         if code:
  610.             print 'Function', code.co_name
  611.             return None
  612.         
  613.         
  614.         try:
  615.             code = value.im_func.func_code
  616.         except:
  617.             pass
  618.  
  619.         if code:
  620.             print 'Method', code.co_name
  621.             return None
  622.         
  623.         print type(value)
  624.  
  625.     
  626.     def do_alias(self, arg):
  627.         args = string.split(arg)
  628.         if len(args) == 0:
  629.             keys = self.aliases.keys()
  630.             keys.sort()
  631.             for alias in keys:
  632.                 print '%s = %s' % (alias, self.aliases[alias])
  633.             
  634.             return None
  635.         
  636.         if self.aliases.has_key(args[0]) and len(args) == 1:
  637.             print '%s = %s' % (args[0], self.aliases[args[0]])
  638.         else:
  639.             self.aliases[args[0]] = string.join(args[1:], ' ')
  640.  
  641.     
  642.     def do_unalias(self, arg):
  643.         args = string.split(arg)
  644.         if len(args) == 0:
  645.             return None
  646.         
  647.         if self.aliases.has_key(args[0]):
  648.             del self.aliases[args[0]]
  649.         
  650.  
  651.     
  652.     def print_stack_trace(self):
  653.         
  654.         try:
  655.             for frame_lineno in self.stack:
  656.                 self.print_stack_entry(frame_lineno)
  657.         except KeyboardInterrupt:
  658.             pass
  659.  
  660.  
  661.     
  662.     def print_stack_entry(self, frame_lineno, prompt_prefix = line_prefix):
  663.         (frame, lineno) = frame_lineno
  664.         if frame is self.curframe:
  665.             print '>',
  666.         else:
  667.             print ' ',
  668.         print self.format_stack_entry(frame_lineno, prompt_prefix)
  669.  
  670.     
  671.     def help_help(self):
  672.         self.help_h()
  673.  
  674.     
  675.     def help_h(self):
  676.         print 'h(elp)\n\tWithout argument, print the list of available commands.\n\tWith a command name as argument, print help about that command\n\t"help pdb" pipes the full documentation file to the $PAGER\n\t"help exec" gives help on the ! command'
  677.  
  678.     
  679.     def help_where(self):
  680.         self.help_w()
  681.  
  682.     
  683.     def help_w(self):
  684.         print 'w(here)\n\tPrint a stack trace, with the most recent frame at the bottom.\n\tAn arrow indicates the "current frame", which determines the\n\tcontext of most commands.'
  685.  
  686.     
  687.     def help_down(self):
  688.         self.help_d()
  689.  
  690.     
  691.     def help_d(self):
  692.         print 'd(own)\n\tMove the current frame one level down in the stack trace\n\t(to an older frame).'
  693.  
  694.     
  695.     def help_up(self):
  696.         self.help_u()
  697.  
  698.     
  699.     def help_u(self):
  700.         print 'u(p)\n\tMove the current frame one level up in the stack trace\n\t(to a newer frame).'
  701.  
  702.     
  703.     def help_break(self):
  704.         self.help_b()
  705.  
  706.     
  707.     def help_b(self):
  708.         print "b(reak) ([file:]lineno | function) [, condition]\n\tWith a line number argument, set a break there in the current\n\tfile.  With a function name, set a break at first executable line\n\tof that function.  Without argument, list all breaks.  If a second\n\targument is present, it is a string specifying an expression\n\twhich must evaluate to true before the breakpoint is honored.\n\n\tThe line number may be prefixed with a filename and a colon,\n\tto specify a breakpoint in another file (probably one that\n\thasn't been loaded yet).  The file is searched for on sys.path;\n\tthe .py suffix may be omitted."
  709.  
  710.     
  711.     def help_clear(self):
  712.         self.help_cl()
  713.  
  714.     
  715.     def help_cl(self):
  716.         print 'cl(ear) filename:lineno'
  717.         print 'cl(ear) [bpnumber [bpnumber...]]\n\tWith a space separated list of breakpoint numbers, clear\n\tthose breakpoints.  Without argument, clear all breaks (but\n\tfirst ask confirmation).  With a filename:lineno argument,\n\tclear all breaks at that line in that file.\n\n\tNote that the argument is different from previous versions of\n\tthe debugger (in python distributions 1.5.1 and before) where\n\ta linenumber was used instead of either filename:lineno or\n\tbreakpoint numbers.'
  718.  
  719.     
  720.     def help_tbreak(self):
  721.         print 'tbreak  same arguments as break, but breakpoint is\n\tremoved when first hit.'
  722.  
  723.     
  724.     def help_enable(self):
  725.         print 'enable bpnumber [bpnumber ...]\n\tEnables the breakpoints given as a space separated list of\n\tbp numbers.'
  726.  
  727.     
  728.     def help_disable(self):
  729.         print 'disable bpnumber [bpnumber ...]\n\tDisables the breakpoints given as a space separated list of\n\tbp numbers.'
  730.  
  731.     
  732.     def help_ignore(self):
  733.         print 'ignore bpnumber count\n\tSets the ignore count for the given breakpoint number.  A breakpoint\n\tbecomes active when the ignore count is zero.  When non-zero, the\n\tcount is decremented each time the breakpoint is reached and the\n\tbreakpoint is not disabled and any associated condition evaluates\n\tto true.'
  734.  
  735.     
  736.     def help_condition(self):
  737.         print 'condition bpnumber str_condition\n\tstr_condition is a string specifying an expression which\n\tmust evaluate to true before the breakpoint is honored.\n\tIf str_condition is absent, any existing condition is removed;\n\ti.e., the breakpoint is made unconditional.'
  738.  
  739.     
  740.     def help_step(self):
  741.         self.help_s()
  742.  
  743.     
  744.     def help_s(self):
  745.         print 's(tep)\n\tExecute the current line, stop at the first possible occasion\n\t(either in a function that is called or in the current function).'
  746.  
  747.     
  748.     def help_next(self):
  749.         self.help_n()
  750.  
  751.     
  752.     def help_n(self):
  753.         print 'n(ext)\n\tContinue execution until the next line in the current function\n\tis reached or it returns.'
  754.  
  755.     
  756.     def help_return(self):
  757.         self.help_r()
  758.  
  759.     
  760.     def help_r(self):
  761.         print 'r(eturn)\n\tContinue execution until the current function returns.'
  762.  
  763.     
  764.     def help_continue(self):
  765.         self.help_c()
  766.  
  767.     
  768.     def help_cont(self):
  769.         self.help_c()
  770.  
  771.     
  772.     def help_c(self):
  773.         print 'c(ont(inue))\n\tContinue execution, only stop when a breakpoint is encountered.'
  774.  
  775.     
  776.     def help_list(self):
  777.         self.help_l()
  778.  
  779.     
  780.     def help_l(self):
  781.         print 'l(ist) [first [,last]]\n\tList source code for the current file.\n\tWithout arguments, list 11 lines around the current line\n\tor continue the previous listing.\n\tWith one argument, list 11 lines starting at that line.\n\tWith two arguments, list the given range;\n\tif the second argument is less than the first, it is a count.'
  782.  
  783.     
  784.     def help_args(self):
  785.         self.help_a()
  786.  
  787.     
  788.     def help_a(self):
  789.         print 'a(rgs)\n\tPrint the arguments of the current function.'
  790.  
  791.     
  792.     def help_p(self):
  793.         print 'p expression\n\tPrint the value of the expression.'
  794.  
  795.     
  796.     def help_exec(self):
  797.         print "(!) statement\n\tExecute the (one-line) statement in the context of\n\tthe current stack frame.\n\tThe exclamation point can be omitted unless the first word\n\tof the statement resembles a debugger command.\n\tTo assign to a global variable you must always prefix the\n\tcommand with a 'global' command, e.g.:\n\t(Pdb) global list_options; list_options = ['-l']\n\t(Pdb)"
  798.  
  799.     
  800.     def help_quit(self):
  801.         self.help_q()
  802.  
  803.     
  804.     def help_q(self):
  805.         print 'q(uit)\tQuit from the debugger.\n\tThe program being executed is aborted.'
  806.  
  807.     
  808.     def help_whatis(self):
  809.         print 'whatis arg\n\tPrints the type of the argument.'
  810.  
  811.     
  812.     def help_EOF(self):
  813.         print 'EOF\n\tHandles the receipt of EOF as a command.'
  814.  
  815.     
  816.     def help_alias(self):
  817.         print 'alias [name [command [parameter parameter ...] ]]\n\tCreates an alias called \'name\' the executes \'command\'.  The command\n\tmust *not* be enclosed in quotes.  Replaceable parameters are\n\tindicated by %1, %2, and so on, while %* is replaced by all the \n\tparameters.  If no command is given, the current alias for name\n\tis shown. If no name is given, all aliases are listed.\n\t\n\tAliases may be nested and can contain anything that can be\n\tlegally typed at the pdb prompt.  Note!  You *can* override\n\tinternal pdb commands with aliases!  Those internal commands\n\tare then hidden until the alias is removed.  Aliasing is recursively\n\tapplied to the first word of the command line; all other words\n\tin the line are left alone.\n\n\tSome useful aliases (especially when placed in the .pdbrc file) are:\n\n\t#Print instance variables (usage "pi classInst")\n\talias pi for k in %1.__dict__.keys(): print "%1.",k,"=",%1.__dict__[k]\n\n\t#Print instance variables in self\n\talias ps pi self\n\t'
  818.  
  819.     
  820.     def help_unalias(self):
  821.         print 'unalias name\n\tDeletes the specified alias.'
  822.  
  823.     
  824.     def help_pdb(self):
  825.         help()
  826.  
  827.     
  828.     def lookupmodule(self, filename):
  829.         (root, ext) = os.path.splitext(filename)
  830.         if ext == '':
  831.             filename = filename + '.py'
  832.         
  833.         if os.path.isabs(filename):
  834.             return filename
  835.         
  836.         for dirname in sys.path:
  837.             while os.path.islink(dirname):
  838.                 dirname = os.readlink(dirname)
  839.                 continue
  840.                 0
  841.             fullname = os.path.join(dirname, filename)
  842.             if os.path.exists(fullname):
  843.                 return fullname
  844.             
  845.         
  846.         return None
  847.  
  848.  
  849.  
  850. def run(statement, globals = None, locals = None):
  851.     Pdb().run(statement, globals, locals)
  852.  
  853.  
  854. def runeval(expression, globals = None, locals = None):
  855.     return Pdb().runeval(expression, globals, locals)
  856.  
  857.  
  858. def runctx(statement, globals, locals):
  859.     run(statement, globals, locals)
  860.  
  861.  
  862. def runcall(*args):
  863.     return apply(Pdb().runcall, args)
  864.  
  865.  
  866. def set_trace():
  867.     Pdb().set_trace()
  868.  
  869.  
  870. def post_mortem(t):
  871.     p = Pdb()
  872.     p.reset()
  873.     while t.tb_next != None:
  874.         t = t.tb_next
  875.     p.interaction(t.tb_frame, t)
  876.  
  877.  
  878. def pm():
  879.     post_mortem(sys.last_traceback)
  880.  
  881. TESTCMD = 'import x; x.main()'
  882.  
  883. def test():
  884.     run(TESTCMD)
  885.  
  886.  
  887. def help():
  888.     for dirname in sys.path:
  889.         fullname = os.path.join(dirname, 'pdb.doc')
  890.     else:
  891.         print 'Sorry, can\'t find the help file "pdb.doc"', 'along the Python search path'
  892.  
  893. mainmodule = ''
  894. mainpyfile = ''
  895. if __name__ == '__main__':
  896.     if not sys.argv[1:]:
  897.         print 'usage: pdb.py scriptfile [arg] ...'
  898.         sys.exit(2)
  899.     
  900.     mainpyfile = filename = sys.argv[1]
  901.     if not os.path.exists(filename):
  902.         print 'Error:', `filename`, 'does not exist'
  903.         sys.exit(1)
  904.     
  905.     mainmodule = os.path.basename(filename)
  906.     del sys.argv[0]
  907.     sys.path.insert(0, os.path.dirname(filename))
  908.     run('execfile(' + `filename` + ')')
  909.  
  910.