##// END OF EJS Templates
Oinspect.py: Only show docstring for nonexisting/binary files...
vivainio -
Show More
@@ -6,7 +6,7 b' Uses syntax highlighting for presenting the various information elements.'
6 Similar in spirit to the inspect module, but all calls take a name argument to
6 Similar in spirit to the inspect module, but all calls take a name argument to
7 reference the name under which an object is being read.
7 reference the name under which an object is being read.
8
8
9 $Id: OInspect.py 1058 2006-01-22 14:30:01Z vivainio $
9 $Id: OInspect.py 1300 2006-05-15 16:27:36Z vivainio $
10 """
10 """
11
11
12 #*****************************************************************************
12 #*****************************************************************************
@@ -29,7 +29,7 b' import linecache'
29 import string
29 import string
30 import StringIO
30 import StringIO
31 import types
31 import types
32
32 import os
33 # IPython's own
33 # IPython's own
34 from IPython import PyColorize
34 from IPython import PyColorize
35 from IPython.genutils import page,indent,Term,mkdict
35 from IPython.genutils import page,indent,Term,mkdict
@@ -239,6 +239,8 b' class Inspector:'
239
239
240 if (ofile.endswith('.so') or ofile.endswith('.dll')):
240 if (ofile.endswith('.so') or ofile.endswith('.dll')):
241 print 'File %r is binary, not printing.' % ofile
241 print 'File %r is binary, not printing.' % ofile
242 elif not os.path.isfile(ofile):
243 print 'File %r does not exist, not printing.' % ofile
242 else:
244 else:
243 # Print only text files, not extension binaries.
245 # Print only text files, not extension binaries.
244 page(self.format(open(ofile).read()),lineno)
246 page(self.format(open(ofile).read()),lineno)
@@ -331,7 +333,8 b' class Inspector:'
331 fname = inspect.getabsfile(obj)
333 fname = inspect.getabsfile(obj)
332 if fname.endswith('<string>'):
334 if fname.endswith('<string>'):
333 fname = 'Dynamically generated function. No source code available.'
335 fname = 'Dynamically generated function. No source code available.'
334 if fname.endswith('.so') or fname.endswith('.dll'):
336 if (fname.endswith('.so') or fname.endswith('.dll') or
337 not os.path.isfile(fname)):
335 binary_file = True
338 binary_file = True
336 out.writeln(header('File:\t\t')+fname)
339 out.writeln(header('File:\t\t')+fname)
337 except:
340 except:
@@ -349,17 +352,22 b' class Inspector:'
349 if ds and detail_level == 0:
352 if ds and detail_level == 0:
350 out.writeln(header('Docstring:\n') + indent(ds))
353 out.writeln(header('Docstring:\n') + indent(ds))
351
354
355
352 # Original source code for any callable
356 # Original source code for any callable
353 if detail_level:
357 if detail_level:
354 # Flush the source cache because inspect can return out-of-date source
358 # Flush the source cache because inspect can return out-of-date source
355 linecache.checkcache()
359 linecache.checkcache()
360 source_success = False
356 try:
361 try:
357 if not binary_file:
362 if not binary_file:
358 source = self.format(inspect.getsource(obj))
363 source = self.format(inspect.getsource(obj))
359 out.write(header('Source:\n')+source.rstrip())
364 out.write(header('Source:\n')+source.rstrip())
365 source_success = True
360 except:
366 except:
361 if ds:
367 pass
362 out.writeln(header('Docstring:\n') + indent(ds))
368
369 if ds and not source_success:
370 out.writeln(header('Docstring [source file open failed]:\n') + indent(ds))
363
371
364 # Constructor docstring for classes
372 # Constructor docstring for classes
365 if obj_type is types.ClassType:
373 if obj_type is types.ClassType:
@@ -1,6 +1,12 b''
1 2006-05-15 Ville Vainio <vivainio@gmail.com>
2
3 * Oinspect.py: Only show docstring for nonexisting/binary files
4 when doing object??, closing ticket #62
5
6
1 2006-05-13 Fernando Perez <Fernando.Perez@colorado.edu>
7 2006-05-13 Fernando Perez <Fernando.Perez@colorado.edu>
2
8
3 * IPython\Shell.py (MTInteractiveShell.runsource): Fix threading
9 * IPython/Shell.py (MTInteractiveShell.runsource): Fix threading
4 bug, closes http://www.scipy.net/roundup/ipython/issue55. A lock
10 bug, closes http://www.scipy.net/roundup/ipython/issue55. A lock
5 was being released in a routine which hadn't checked if it had
11 was being released in a routine which hadn't checked if it had
6 been the one to acquire it.
12 been the one to acquire it.
General Comments 0
You need to be logged in to leave comments. Login now