Ignore:
Timestamp:
Mar 19, 2014, 11:11:30 AM (11 years ago)
Author:
dmik
Message:

python: Update vendor to 2.7.6.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/vendor/current/Lib/pdb.py

    r2 r388  
    5959class Pdb(bdb.Bdb, cmd.Cmd):
    6060
    61     def __init__(self, completekey='tab', stdin=None, stdout=None):
    62         bdb.Bdb.__init__(self)
     61    def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None):
     62        bdb.Bdb.__init__(self, skip=skip)
    6363        cmd.Cmd.__init__(self, completekey, stdin, stdout)
    6464        if stdout:
     
    9696
    9797        self.commands = {} # associates a command list to breakpoint numbers
    98         self.commands_doprompt = {} # for each bp num, tells if the prompt must be disp. after execing the cmd list
    99         self.commands_silent = {} # for each bp num, tells if the stack trace must be disp. after execing the cmd list
    100         self.commands_defining = False # True while in the process of defining a command list
    101         self.commands_bnum = None # The breakpoint number for which we are defining a list
     98        self.commands_doprompt = {} # for each bp num, tells if the prompt
     99                                    # must be disp. after execing the cmd list
     100        self.commands_silent = {} # for each bp num, tells if the stack trace
     101                                  # must be disp. after execing the cmd list
     102        self.commands_defining = False # True while in the process of defining
     103                                       # a command list
     104        self.commands_bnum = None # The breakpoint number for which we are
     105                                  # defining a list
    102106
    103107    def reset(self):
     
    115119        self.stack, self.curindex = self.get_stack(f, t)
    116120        self.curframe = self.stack[self.curindex][0]
     121        # The f_locals dictionary is updated from the actual frame
     122        # locals whenever the .f_locals accessor is called, so we
     123        # cache it here to ensure that modifications are not overwritten.
     124        self.curframe_locals = self.curframe.f_locals
    117125        self.execRcLines()
    118126
     
    151159
    152160    def bp_commands(self,frame):
    153         """ Call every command that was set for the current active breakpoint (if there is one)
    154         Returns True if the normal interaction function must be called, False otherwise """
    155         #self.currentbp is set in bdb.py in bdb.break_here if a breakpoint was hit
    156         if getattr(self,"currentbp",False) and self.currentbp in self.commands:
     161        """Call every command that was set for the current active breakpoint
     162        (if there is one).
     163
     164        Returns True if the normal interaction function must be called,
     165        False otherwise."""
     166        # self.currentbp is set in bdb in Bdb.break_here if a breakpoint was hit
     167        if getattr(self, "currentbp", False) and \
     168               self.currentbp in self.commands:
    157169            currentbp = self.currentbp
    158170            self.currentbp = 0
     
    172184    def user_return(self, frame, return_value):
    173185        """This function is called when a return trap is set here."""
     186        if self._wait_for_mainpyfile:
     187            return
    174188        frame.f_locals['__return__'] = return_value
    175189        print >>self.stdout, '--Return--'
     
    177191
    178192    def user_exception(self, frame, exc_info):
    179         exc_type, exc_value, exc_traceback = exc_info
    180193        """This function is called if an exception occurs,
    181194        but only if we are to stop at or just below this level."""
     195        if self._wait_for_mainpyfile:
     196            return
     197        exc_type, exc_value, exc_traceback = exc_info
    182198        frame.f_locals['__exception__'] = exc_type, exc_value
    183199        if type(exc_type) == type(''):
     
    205221    def default(self, line):
    206222        if line[:1] == '!': line = line[1:]
    207         locals = self.curframe.f_locals
     223        locals = self.curframe_locals
    208224        globals = self.curframe.f_globals
    209225        try:
     
    266282
    267283    def handle_command_def(self,line):
    268         """ Handles one command line during command list definition. """
     284        """Handles one command line during command list definition."""
    269285        cmd, arg, line = self.parseline(line)
     286        if not cmd:
     287            return
    270288        if cmd == 'silent':
    271289            self.commands_silent[self.commands_bnum] = True
     
    275293            return 1 # end of cmd list
    276294        cmdlist = self.commands[self.commands_bnum]
    277         if (arg):
     295        if arg:
    278296            cmdlist.append(cmd+' '+arg)
    279297        else:
     
    284302        except AttributeError:
    285303            func = self.default
    286         if func.func_name in self.commands_resuming : # one of the resuming commands.
     304        # one of the resuming commands
     305        if func.func_name in self.commands_resuming:
    287306            self.commands_doprompt[self.commands_bnum] = False
    288307            self.cmdqueue = []
     
    297316
    298317    def do_commands(self, arg):
    299         """Defines a list of commands associated to a breakpoint
    300         Those commands will be executed whenever the breakpoint causes the program to stop execution."""
     318        """Defines a list of commands associated to a breakpoint.
     319
     320        Those commands will be executed whenever the breakpoint causes
     321        the program to stop execution."""
    301322        if not arg:
    302323            bnum = len(bdb.Breakpoint.bpbynumber)-1
     
    305326                bnum = int(arg)
    306327            except:
    307                 print >>self.stdout, "Usage : commands [bnum]\n        ...\n        end"
     328                print >>self.stdout, "Usage : commands [bnum]\n        ..." \
     329                                     "\n        end"
    308330                return
    309331        self.commands_bnum = bnum
     
    314336        self.prompt = '(com) '
    315337        self.commands_defining = True
    316         self.cmdloop()
    317         self.commands_defining = False
    318         self.prompt = prompt_back
     338        try:
     339            self.cmdloop()
     340        finally:
     341            self.commands_defining = False
     342            self.prompt = prompt_back
    319343
    320344    def do_break(self, arg, temporary = 0):
     
    363387                    func = eval(arg,
    364388                                self.curframe.f_globals,
    365                                 self.curframe.f_locals)
     389                                self.curframe_locals)
    366390                except:
    367391                    func = arg
     
    452476        line or EOF). Warning: testing is not comprehensive.
    453477        """
    454         line = linecache.getline(filename, lineno, self.curframe.f_globals)
     478        # this method should be callable before starting debugging, so default
     479        # to "no globals" if there is no current frame
     480        globs = self.curframe.f_globals if hasattr(self, 'curframe') else None
     481        line = linecache.getline(filename, lineno, globs)
    455482        if not line:
    456483            print >>self.stdout, 'End of file'
     
    611638            self.curindex = self.curindex - 1
    612639            self.curframe = self.stack[self.curindex][0]
     640            self.curframe_locals = self.curframe.f_locals
    613641            self.print_stack_entry(self.stack[self.curindex])
    614642            self.lineno = None
     
    621649            self.curindex = self.curindex + 1
    622650            self.curframe = self.stack[self.curindex][0]
     651            self.curframe_locals = self.curframe.f_locals
    623652            self.print_stack_entry(self.stack[self.curindex])
    624653            self.lineno = None
     
    641670
    642671    def do_run(self, arg):
    643         """Restart program by raising an exception to be caught in the main debugger
    644         loop. If arguments were given, set them in sys.argv."""
     672        """Restart program by raising an exception to be caught in the main
     673        debugger loop. If arguments were given, set them in sys.argv."""
    645674        if arg:
    646675            import shlex
     
    684713        sys.settrace(None)
    685714        globals = self.curframe.f_globals
    686         locals = self.curframe.f_locals
     715        locals = self.curframe_locals
    687716        p = Pdb(self.completekey, self.stdin, self.stdout)
    688717        p.prompt = "(%s) " % self.prompt.strip()
     
    708737
    709738    def do_args(self, arg):
    710         f = self.curframe
    711         co = f.f_code
    712         dict = f.f_locals
     739        co = self.curframe.f_code
     740        dict = self.curframe_locals
    713741        n = co.co_argcount
    714742        if co.co_flags & 4: n = n+1
     
    722750
    723751    def do_retval(self, arg):
    724         if '__return__' in self.curframe.f_locals:
    725             print >>self.stdout, self.curframe.f_locals['__return__']
     752        if '__return__' in self.curframe_locals:
     753            print >>self.stdout, self.curframe_locals['__return__']
    726754        else:
    727755            print >>self.stdout, '*** Not yet returned!'
     
    731759        try:
    732760            return eval(arg, self.curframe.f_globals,
    733                         self.curframe.f_locals)
     761                        self.curframe_locals)
    734762        except:
    735763            t, v = sys.exc_info()[:2]
     
    780808        try:
    781809            for lineno in range(first, last+1):
    782                 line = linecache.getline(filename, lineno, self.curframe.f_globals)
     810                line = linecache.getline(filename, lineno,
     811                                         self.curframe.f_globals)
    783812                if not line:
    784813                    print >>self.stdout, '[EOF]'
     
    800829        try:
    801830            value = eval(arg, self.curframe.f_globals,
    802                             self.curframe.f_locals)
     831                            self.curframe_locals)
    803832        except:
    804833            t, v = sys.exc_info()[:2]
     
    944973
    945974    def help_tbreak(self):
    946         print >>self.stdout, """tbreak  same arguments as break, but breakpoint is
    947 removed when first hit."""
     975        print >>self.stdout, """tbreak  same arguments as break, but breakpoint
     976is removed when first hit."""
    948977
    949978    def help_enable(self):
     
    10671096        print """run [args...]
    10681097Restart the debugged python program. If a string is supplied, it is
    1069 splitted with "shlex" and the result is used as the new sys.argv.
     1098split with "shlex" and the result is used as the new sys.argv.
    10701099History, breakpoints, actions and debugger options are preserved.
    10711100"restart" is an alias for "run"."""
     
    10911120
    10921121    def help_alias(self):
    1093         print >>self.stdout, """alias [name [command [parameter parameter ...] ]]
     1122        print >>self.stdout, """alias [name [command [parameter parameter ...]]]
    10941123Creates an alias called 'name' the executes 'command'.  The command
    10951124must *not* be enclosed in quotes.  Replaceable parameters are
     
    12011230        self.mainpyfile = self.canonic(filename)
    12021231        self._user_requested_quit = 0
    1203         statement = 'execfile( "%s")' % filename
     1232        statement = 'execfile(%r)' % filename
    12041233        self.run(statement)
    12051234
     
    12781307    # Note on saving/restoring sys.argv: it's a good idea when sys.argv was
    12791308    # modified by the script being debugged. It's a bad idea when it was
    1280     # changed by the user from the command line. There is a "restart" command which
    1281     # allows explicit specification of command line arguments.
     1309    # changed by the user from the command line. There is a "restart" command
     1310    # which allows explicit specification of command line arguments.
    12821311    pdb = Pdb()
    1283     while 1:
     1312    while True:
    12841313        try:
    12851314            pdb._runscript(mainpyfile)
     
    13001329            t = sys.exc_info()[2]
    13011330            pdb.interaction(None, t)
    1302             print "Post mortem debugger finished. The "+mainpyfile+" will be restarted"
     1331            print "Post mortem debugger finished. The " + mainpyfile + \
     1332                  " will be restarted"
    13031333
    13041334
Note: See TracChangeset for help on using the changeset viewer.