Show More
@@ -155,7 +155,12 b' def getsource(obj,is_binary=False):' | |||
|
155 | 155 | if is_binary: |
|
156 | 156 | return None |
|
157 | 157 | else: |
|
158 | return inspect.getsource(obj) | |
|
158 | try: | |
|
159 | src = inspect.getsource(obj) | |
|
160 | except TypeError: | |
|
161 | if hasattr(obj,'__class__'): | |
|
162 | src = inspect.getsource(obj.__class__) | |
|
163 | return src | |
|
159 | 164 | |
|
160 | 165 | #**************************************************************************** |
|
161 | 166 | # Class definitions |
@@ -278,7 +283,7 b' class Inspector:' | |||
|
278 | 283 | self.noinfo('documentation',oname) |
|
279 | 284 | return |
|
280 | 285 | page(output) |
|
281 | ||
|
286 | ||
|
282 | 287 | def psource(self,obj,oname=''): |
|
283 | 288 | """Print the source code for an object.""" |
|
284 | 289 | |
@@ -293,23 +298,35 b' class Inspector:' | |||
|
293 | 298 | |
|
294 | 299 | def pfile(self,obj,oname=''): |
|
295 | 300 | """Show the whole file where an object was defined.""" |
|
301 | ||
|
296 | 302 | try: |
|
297 | sourcelines,lineno = inspect.getsourcelines(obj) | |
|
303 | try: | |
|
304 | lineno = inspect.getsourcelines(obj)[1] | |
|
305 | except TypeError: | |
|
306 | # For instances, try the class object like getsource() does | |
|
307 | if hasattr(obj,'__class__'): | |
|
308 | lineno = inspect.getsourcelines(obj.__class__)[1] | |
|
309 | # Adjust the inspected object so getabsfile() below works | |
|
310 | obj = obj.__class__ | |
|
298 | 311 | except: |
|
299 | 312 | self.noinfo('file',oname) |
|
313 | return | |
|
314 | ||
|
315 | # We only reach this point if object was successfully queried | |
|
316 | ||
|
317 | # run contents of file through pager starting at line | |
|
318 | # where the object is defined | |
|
319 | ofile = inspect.getabsfile(obj) | |
|
320 | ||
|
321 | if (ofile.endswith('.so') or ofile.endswith('.dll')): | |
|
322 | print 'File %r is binary, not printing.' % ofile | |
|
323 | elif not os.path.isfile(ofile): | |
|
324 | print 'File %r does not exist, not printing.' % ofile | |
|
300 | 325 | else: |
|
301 | # run contents of file through pager starting at line | |
|
302 | # where the object is defined | |
|
303 | ofile = inspect.getabsfile(obj) | |
|
304 | ||
|
305 | if (ofile.endswith('.so') or ofile.endswith('.dll')): | |
|
306 | print 'File %r is binary, not printing.' % ofile | |
|
307 | elif not os.path.isfile(ofile): | |
|
308 | print 'File %r does not exist, not printing.' % ofile | |
|
309 | else: | |
|
310 | # Print only text files, not extension binaries. | |
|
311 | page(self.format(open(ofile).read()),lineno) | |
|
312 | #page(self.format(open(inspect.getabsfile(obj)).read()),lineno) | |
|
326 | # Print only text files, not extension binaries. Note that | |
|
327 | # getsourcelines returns lineno with 1-offset and page() uses | |
|
328 | # 0-offset, so we must adjust. | |
|
329 | page(self.format(open(ofile).read()),lineno-1) | |
|
313 | 330 | |
|
314 | 331 | def pinfo(self,obj,oname='',formatter=None,info=None,detail_level=0): |
|
315 | 332 | """Show detailed information about an object. |
@@ -1528,7 +1528,10 b' def page(strng,start=0,screen_lines=0,pager_cmd = None):' | |||
|
1528 | 1528 | If no system pager works, the string is sent through a 'dumb pager' |
|
1529 | 1529 | written in python, very simplistic. |
|
1530 | 1530 | """ |
|
1531 | ||
|
1531 | ||
|
1532 | # Some routines may auto-compute start offsets incorrectly and pass a | |
|
1533 | # negative value. Offset to 0 for robustness. | |
|
1534 | start = max(0,start) | |
|
1532 | 1535 | |
|
1533 | 1536 | # first, try the hook |
|
1534 | 1537 | ip = IPython.ipapi.get() |
General Comments 0
You need to be logged in to leave comments.
Login now