Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(658)

Side by Side Diff: third_party/logilab/common/debugger.py

Issue 719313003: Revert "pylint: upgrade to 1.3.1" (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/logilab/common/dbf.py ('k') | third_party/logilab/common/decorators.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
32 __docformat__ = "restructuredtext en" 29 __docformat__ = "restructuredtext en"
33 30
34 try: 31 try:
35 import readline 32 import readline
36 except ImportError: 33 except ImportError:
37 readline = None 34 readline = None
38 import os 35 import os
39 import os.path as osp 36 import os.path as osp
40 import sys 37 import sys
41 from pdb import Pdb 38 from pdb import Pdb
39 from cStringIO import StringIO
42 import inspect 40 import inspect
43 41
44 from logilab.common.compat import StringIO
45
46 try: 42 try:
47 from IPython import PyColorize 43 from IPython import PyColorize
48 except ImportError: 44 except ImportError:
49 def colorize(source, *args): 45 def colorize(source, *args):
50 """fallback colorize function""" 46 """fallback colorize function"""
51 return source 47 return source
52 def colorize_source(source, *args): 48 def colorize_source(source, *args):
53 return source 49 return source
54 else: 50 else:
55 def colorize(source, start_lineno, curlineno): 51 def colorize(source, start_lineno, curlineno):
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 175
180 ## specific / overridden commands 176 ## specific / overridden commands
181 def do_list(self, arg): 177 def do_list(self, arg):
182 """overrides default list command to display the surrounding block 178 """overrides default list command to display the surrounding block
183 instead of 5 lines of context 179 instead of 5 lines of context
184 """ 180 """
185 self.lastcmd = 'list' 181 self.lastcmd = 'list'
186 if not arg: 182 if not arg:
187 try: 183 try:
188 source, start_lineno = getsource(self.curframe) 184 source, start_lineno = getsource(self.curframe)
189 print(colorize(''.join(source), start_lineno, 185 print colorize(''.join(source), start_lineno,
190 self.curframe.f_lineno)) 186 self.curframe.f_lineno)
191 except KeyboardInterrupt: 187 except KeyboardInterrupt:
192 pass 188 pass
193 except IOError: 189 except IOError:
194 Pdb.do_list(self, arg) 190 Pdb.do_list(self, arg)
195 else: 191 else:
196 Pdb.do_list(self, arg) 192 Pdb.do_list(self, arg)
197 do_l = do_list 193 do_l = do_list
198 194
199 def do_open(self, arg): 195 def do_open(self, arg):
200 """opens source file corresponding to the current stack level""" 196 """opens source file corresponding to the current stack level"""
201 filename = self.curframe.f_code.co_filename 197 filename = self.curframe.f_code.co_filename
202 lineno = self.curframe.f_lineno 198 lineno = self.curframe.f_lineno
203 cmd = 'emacsclient --no-wait +%s %s' % (lineno, filename) 199 cmd = 'emacsclient --no-wait +%s %s' % (lineno, filename)
204 os.system(cmd) 200 os.system(cmd)
205 201
206 do_o = do_open 202 do_o = do_open
207 203
208 def pm(): 204 def pm():
209 """use our custom debugger""" 205 """use our custom debugger"""
210 dbg = Debugger(sys.last_traceback) 206 dbg = Debugger(sys.last_traceback)
211 dbg.start() 207 dbg.start()
212 208
213 def set_trace(): 209 def set_trace():
214 Debugger().set_trace(sys._getframe().f_back) 210 Debugger().set_trace(sys._getframe().f_back)
OLDNEW
« no previous file with comments | « third_party/logilab/common/dbf.py ('k') | third_party/logilab/common/decorators.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698