William, I'm attaching the patch as I just implemented it. This does the 'right thing' for binary extensions:
In [1]: import strop In [2]: strop?? Type: module Base Class: <type 'module'> String Form: <module 'strop' from '/usr/lib/python2.4/lib-dynload/strop.so'> Namespace: Interactive File: /usr/lib/python2.4/lib-dynload/strop.so Docstring [source file open failed]: Common string manipulations, optimized for speed. Always use "import string" rather than referencing this module directly. Please let me know if it also provides what you need for SAGE, so I can commit it to IPython's trunk. Cheers, f --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~----------~----~----~----~------~----~------~--~---
Index: OInspect.py =================================================================== --- OInspect.py (revision 1843) +++ OInspect.py (working copy) @@ -136,6 +136,27 @@ ds = '%s\n%s' % (ds,ds2) return ds +def getsource(obj,is_binary=False): + """Wrapper around inspect.getsource. + + This can be modified by other projects to provide customized source + extraction. + + Inputs: + + - obj: an object whose source code we will attempt to extract. + + Optional inputs: + + - is_binary: whether the object is known to come from a binary source. + This implementation will skip returning any output for binary objects, but + custom extractors may know how to meaninfully process them.""" + + if is_binary: + return None + else: + return inspect.getsource(obj) + #**************************************************************************** # Class definitions @@ -262,7 +283,7 @@ # Flush the source cache because inspect can return out-of-date source linecache.checkcache() try: - src = inspect.getsource(obj) + src = getsource(obj) except: self.noinfo('source',oname) else: @@ -402,15 +423,16 @@ linecache.checkcache() source_success = False try: - if not binary_file: - source = self.format(inspect.getsource(obj)) + source = self.format(getsource(obj,binary_file)) + if source: out.write(header('Source:\n')+source.rstrip()) source_success = True - except: + except Exception, msg: pass if ds and not source_success: - out.writeln(header('Docstring [source file open failed]:\n') + indent(ds)) + out.writeln(header('Docstring [source file open failed]:\n') + + indent(ds)) # Constructor docstring for classes if obj_type is types.ClassType: