Esempio n. 1
0
def docstring(obj_name, globs, system='sage'):
    r"""
    Format ``obj_name``'s docstring for printing in Sage
    notebook.
    
    AUTHORS:

    - William Stein: partly taken from IPython for use in Sage

    - Nick Alexander: extensions
    """
    if system not in ['sage', 'python']:
        obj_name = system + '.' + obj_name
    try:
        obj = eval(obj_name, globs)
    except (AttributeError, NameError, SyntaxError):
        return "No object '%s' currently defined."%obj_name
    s  = ''
    try:
        filename = sageinspect.sage_getfile(obj)
        #i = filename.find('site-packages/sage/')
        #if i == -1:
        s += 'File:        %s\n'%filename
        #else:
        #    file = filename[i+len('site-packages/sage/'):]
        #    s += 'File:        <html><a href="src_browser?%s">%s</a></html>\n'%(file,file)
    except TypeError:
        pass
    s += 'Type:        %s\n'%type(obj)
    s += 'Definition:  %s\n'%sageinspect.sage_getdef(obj, obj_name)
    s += 'Docstring: \n%s\n'%sageinspect.sage_getdoc(obj, obj_name)
    return s.rstrip()
Esempio n. 2
0
def docstring(obj_name, globs, system='sage'):
    r"""
    Format an object's docstring to process and display in the Sage
    notebook.

    INPUT:

    - ``obj_name`` - a string; a name of an object

    - ``globs`` - a string:object dictionary; a context in which to
      evaluate ``obj_name``

    - ``system`` - a string (default: 'sage'); the system to which to
      confine the search

    OUTPUT:

    - a string containing the object's file, type, definition, and
      docstring or a message stating the object is not defined

    AUTHORS:

    - William Stein: partly taken from IPython for use in Sage

    - Nick Alexander: extensions
    """
    if system not in ['sage', 'python']:
        obj_name = system + '.' + obj_name
    try:
        obj = eval(obj_name, globs)
    except (AttributeError, NameError, SyntaxError):
        return "No object '%s' currently defined."%obj_name
    s  = ''
    newline = "\n\n"  # blank line to start new paragraph
    try:
        filename = sageinspect.sage_getfile(obj)
        #i = filename.find('site-packages/sage/')
        #if i == -1:
        s += '**File:** %s'%filename
        s += newline
        #else:
        #    file = filename[i+len('site-packages/sage/'):]
        #    s += 'File:        <html><a href="src_browser?%s">%s</a></html>\n'%(file,file)
    except TypeError:
        pass
    s += '**Type:** %s'%type(obj)
    s += newline
    s += '**Definition:** %s'%sageinspect.sage_getdef(obj, obj_name)
    s += newline
    s += '**Docstring:**'
    s += newline
    s += sageinspect.sage_getdoc(obj, obj_name)
    return s.rstrip()
Esempio n. 3
0
def docstring(obj_name, globs, system='sage'):
    r"""
    Format an object's docstring to process and display in the Sage
    notebook.

    INPUT:

    - ``obj_name`` - a string; a name of an object

    - ``globs`` - a string:object dictionary; a context in which to
      evaluate ``obj_name``

    - ``system`` - a string (default: 'sage'); the system to which to
      confine the search

    OUTPUT:

    - a string containing the object's file, type, definition, and
      docstring or a message stating the object is not defined

    AUTHORS:

    - William Stein: partly taken from IPython for use in Sage

    - Nick Alexander: extensions
    """
    if system not in ['sage', 'python']:
        obj_name = system + '.' + obj_name
    try:
        obj = eval(obj_name, globs)
    except (AttributeError, NameError, SyntaxError):
        return "No object '%s' currently defined."%obj_name
    s  = ''
    newline = "\n\n"  # blank line to start new paragraph
    try:
        filename = sageinspect.sage_getfile(obj)
        #i = filename.find('site-packages/sage/')
        #if i == -1:
        s += '**File:** %s'%filename
        s += newline
        #else:
        #    file = filename[i+len('site-packages/sage/'):]
        #    s += 'File:        <html><a href="src_browser?%s">%s</a></html>\n'%(file,file)
    except TypeError:
        pass
    s += '**Type:** %s'%type(obj)
    s += newline
    s += '**Definition:** %s'%sageinspect.sage_getdef(obj, obj_name)
    s += newline
    s += '**Docstring:**'
    s += newline
    s += sageinspect.sage_getdoc(obj, obj_name)
    return s.rstrip()
Esempio n. 4
0
    def _sage_doc_(self):
        """
        Returns the docstring for this object, which is just the
        docstring for the underlying function.  See
        :module:`sage.misc.sageinspect` for more information on this
        convention.

        EXAMPLES::

            sage: from sage.parallel.decorate import Parallel
            sage: p = Parallel(2)
            sage: def f(x, y):
            ....:     '''Test docstring'''
            ....:     return x + y
            sage: from sage.misc.sageinspect import sage_getdoc
            sage: sage_getdoc(p(f))
            'Test docstring\n'
        """
        from sage.misc.sageinspect import sage_getdoc
        return sage_getdoc(self.func)
Esempio n. 5
0
    def _sage_doc_(self):
        """
        Returns the docstring for this object, which is just the
        docstring for the underlying function.  See
        :module:`sage.misc.sageinspect` for more information on this
        convention.

        EXAMPLES::

            sage: from sage.parallel.decorate import Parallel
            sage: p = Parallel(2)
            sage: def f(x, y):
            ...       '''Test docstring'''
            ...       return x + y
            sage: from sage.misc.sageinspect import sage_getdoc
            sage: sage_getdoc(p(f))
            'Test docstring\n'
        """
        from sage.misc.sageinspect import sage_getdoc
        return sage_getdoc(self.func)