| OLD | NEW |
| 1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. | 1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
| 2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr | 2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
| 3 # | 3 # |
| 4 # This file is part of logilab-common. | 4 # This file is part of logilab-common. |
| 5 # | 5 # |
| 6 # logilab-common is free software: you can redistribute it and/or modify it unde
r | 6 # logilab-common is free software: you can redistribute it and/or modify it unde
r |
| 7 # the terms of the GNU Lesser General Public License as published by the Free | 7 # the terms of the GNU Lesser General Public License as published by the Free |
| 8 # Software Foundation, either version 2.1 of the License, or (at your option) an
y | 8 # Software Foundation, either version 2.1 of the License, or (at your option) an
y |
| 9 # later version. | 9 # later version. |
| 10 # | 10 # |
| 11 # logilab-common is distributed in the hope that it will be useful, but WITHOUT | 11 # logilab-common is distributed in the hope that it will be useful, but WITHOUT |
| 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | 13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
| 14 # details. | 14 # details. |
| 15 # | 15 # |
| 16 # You should have received a copy of the GNU Lesser General Public License along | 16 # You should have received a copy of the GNU Lesser General Public License along |
| 17 # with logilab-common. If not, see <http://www.gnu.org/licenses/>. | 17 # with logilab-common. If not, see <http://www.gnu.org/licenses/>. |
| 18 """Customized version of pdb's default debugger. | 18 """Customized version of pdb's default debugger. |
| 19 | 19 |
| 20 - sets up a history file | 20 - sets up a history file |
| 21 - uses ipython if available to colorize lines of code | 21 - uses ipython if available to colorize lines of code |
| 22 - overrides list command to search for current block instead | 22 - overrides list command to search for current block instead |
| 23 of using 5 lines of context | 23 of using 5 lines of context |
| 24 | 24 |
| 25 | 25 |
| 26 | 26 |
| 27 | 27 |
| 28 """ | 28 """ |
| 29 |
| 30 from __future__ import print_function |
| 31 |
| 29 __docformat__ = "restructuredtext en" | 32 __docformat__ = "restructuredtext en" |
| 30 | 33 |
| 31 try: | 34 try: |
| 32 import readline | 35 import readline |
| 33 except ImportError: | 36 except ImportError: |
| 34 readline = None | 37 readline = None |
| 35 import os | 38 import os |
| 36 import os.path as osp | 39 import os.path as osp |
| 37 import sys | 40 import sys |
| 38 from pdb import Pdb | 41 from pdb import Pdb |
| 39 from cStringIO import StringIO | |
| 40 import inspect | 42 import inspect |
| 41 | 43 |
| 44 from logilab.common.compat import StringIO |
| 45 |
| 42 try: | 46 try: |
| 43 from IPython import PyColorize | 47 from IPython import PyColorize |
| 44 except ImportError: | 48 except ImportError: |
| 45 def colorize(source, *args): | 49 def colorize(source, *args): |
| 46 """fallback colorize function""" | 50 """fallback colorize function""" |
| 47 return source | 51 return source |
| 48 def colorize_source(source, *args): | 52 def colorize_source(source, *args): |
| 49 return source | 53 return source |
| 50 else: | 54 else: |
| 51 def colorize(source, start_lineno, curlineno): | 55 def colorize(source, start_lineno, curlineno): |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 | 179 |
| 176 ## specific / overridden commands | 180 ## specific / overridden commands |
| 177 def do_list(self, arg): | 181 def do_list(self, arg): |
| 178 """overrides default list command to display the surrounding block | 182 """overrides default list command to display the surrounding block |
| 179 instead of 5 lines of context | 183 instead of 5 lines of context |
| 180 """ | 184 """ |
| 181 self.lastcmd = 'list' | 185 self.lastcmd = 'list' |
| 182 if not arg: | 186 if not arg: |
| 183 try: | 187 try: |
| 184 source, start_lineno = getsource(self.curframe) | 188 source, start_lineno = getsource(self.curframe) |
| 185 print colorize(''.join(source), start_lineno, | 189 print(colorize(''.join(source), start_lineno, |
| 186 self.curframe.f_lineno) | 190 self.curframe.f_lineno)) |
| 187 except KeyboardInterrupt: | 191 except KeyboardInterrupt: |
| 188 pass | 192 pass |
| 189 except IOError: | 193 except IOError: |
| 190 Pdb.do_list(self, arg) | 194 Pdb.do_list(self, arg) |
| 191 else: | 195 else: |
| 192 Pdb.do_list(self, arg) | 196 Pdb.do_list(self, arg) |
| 193 do_l = do_list | 197 do_l = do_list |
| 194 | 198 |
| 195 def do_open(self, arg): | 199 def do_open(self, arg): |
| 196 """opens source file corresponding to the current stack level""" | 200 """opens source file corresponding to the current stack level""" |
| 197 filename = self.curframe.f_code.co_filename | 201 filename = self.curframe.f_code.co_filename |
| 198 lineno = self.curframe.f_lineno | 202 lineno = self.curframe.f_lineno |
| 199 cmd = 'emacsclient --no-wait +%s %s' % (lineno, filename) | 203 cmd = 'emacsclient --no-wait +%s %s' % (lineno, filename) |
| 200 os.system(cmd) | 204 os.system(cmd) |
| 201 | 205 |
| 202 do_o = do_open | 206 do_o = do_open |
| 203 | 207 |
| 204 def pm(): | 208 def pm(): |
| 205 """use our custom debugger""" | 209 """use our custom debugger""" |
| 206 dbg = Debugger(sys.last_traceback) | 210 dbg = Debugger(sys.last_traceback) |
| 207 dbg.start() | 211 dbg.start() |
| 208 | 212 |
| 209 def set_trace(): | 213 def set_trace(): |
| 210 Debugger().set_trace(sys._getframe().f_back) | 214 Debugger().set_trace(sys._getframe().f_back) |
| OLD | NEW |