/usr/lib/python2.7/dist-packages/sagenb/misc/sageinspect.py is in python-sagenb 1.0.1+ds1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | # -*- coding: utf-8 -*
"""
This is a stand-in for Sage's inspection code in
sage.misc.sageinspect. If Sage is available, that code will be used
here. Otherwise, use simple-minded replacements based on Python's
inspect module.
AUTHORS:
- John Palmieri, Simon King
"""
def sagenb_getdef(obj, obj_name=''):
r"""
Return the definition header for any callable object.
INPUT:
- ``obj`` - function
- ``obj_name`` - string (optional, default '')
This calls inspect.getargspec, formats the result, and prepends
``obj_name``.
EXAMPLES::
sage: from sagenb.misc.sageinspect import sagenb_getdef
sage: def f(a, b=0, *args, **kwds): pass
sage: sagenb_getdef(f, 'hello')
'hello(a, b=0, *args, **kwds)'
"""
from inspect import formatargspec, getargspec
return obj_name + formatargspec(*getargspec(obj))
def sagenb_getdoc(obj, obj_name=''):
r"""
Return the docstring associated to ``obj`` as a string.
This is essentially a front end for inspect.getdoc.
INPUT: ``obj``, a function, module, etc.: something with a docstring.
If "self" is present in the docmentation, then replace it with `obj_name`.
EXAMPLES::
sage: from sagenb.misc.sageinspect import sagenb_getdoc
sage: sagenb_getdoc(sagenb.misc.sageinspect.sagenb_getdoc)[0:55]
'Return the docstring associated to ``obj`` as a string.'
"""
from inspect import getdoc
s = getdoc(obj)
if obj_name != '':
i = obj_name.find('.')
if i != -1:
obj_name = obj_name[:i]
s = s.replace('self.','%s.'%obj_name)
return s
try:
# If Sage is available, use sage.misc.sageinspect.
import sage.misc.sageinspect as si
sage_getargspec = si.sage_getargspec
sage_getdef = si.sage_getdef
sage_getdoc = si.sage_getdoc
sage_getfile = si.sage_getfile
sage_getsourcelines = si.sage_getsourcelines
except ImportError:
# If Sage is not available, use Python's inspect module where
# possible, and slight variants on its functions where needed.
import inspect
sage_getargspec = inspect.getargspec
sage_getfile = inspect.getfile
sage_getsourcelines = inspect.getsourcelines
sage_getdef = sagenb_getdef
sage_getdoc = sagenb_getdoc
|