Ticket #2992: sage-2992.patch

File sage-2992.patch, 3.4 KB (added by was, 13 years ago)
  • sage/all_notebook.py

    # HG changeset patch
    # User William Stein <wstein@gmail.com>
    # Date 1210484656 25200
    # Node ID bf1d49c9c7de5bcb0f4908dd626020b4869d5553
    # Parent  491affdce3fafbad8129208b2a5665497aaca464
    trac #2992 -- help(foo) in the notebook should not word wrap
    
      1. Wrote new version of help command for the notebook.
      2. Slightly modified how truncation is done to account for 1.  While I was at it, I fixed another
         but where reloading a page would put multiple "output truncated" messages at the top of the page.
    
    diff -r 491affdce3fa -r bf1d49c9c7de sage/all_notebook.py
    a b from sage.misc.python import python 
    2323
    2424from sage.misc.html import html
    2525
     26from sage.server.support import help
    2627
    2728
    2829
    2930
    3031
    3132
    32 
  • sage/server/notebook/cell.py

    diff -r 491affdce3fa -r bf1d49c9c7de sage/server/notebook/cell.py
    a b class Cell(Cell_generic): 
    496496            del self._html_cache
    497497
    498498        output = output.replace('\r','')
    499         if len(output) > MAX_OUTPUT or output.count('\n') > MAX_OUTPUT_LINES:
     499        # We do not truncate if "notruncate" or "Output truncated!" already
     500        # appears in the output.  This notruncate tag is used right now
     501        # in sage.server.support.help.
     502        if 'notruncate' not in output and 'Output truncated!' not in output and \
     503               (len(output) > MAX_OUTPUT or output.count('\n') > MAX_OUTPUT_LINES):
    500504            url = ""
    501505            if not self.computing():
    502506                file = "%s/full_output.txt"%self.directory()
  • sage/server/support.py

    diff -r 491affdce3fa -r bf1d49c9c7de sage/server/support.py
    a b import sage.misc.sageinspect as sageinsp 
    1818import sage.misc.sageinspect as sageinspect
    1919
    2020from sage.misc.preparser import preparse
     21
     22import pydoc
    2123
    2224######################################################################
    2325# Initialization
    def setup_systems(globs): 
    6466######################################################################
    6567# Introspection
    6668######################################################################
     69def help(obj):
     70    """
     71    Display help on s. 
    6772
     73    NOTE: This a wrapper around the builtin help.  If formats the
     74    output as HTML without word wrap, which looks better in the
     75    notebook.
     76
     77    INPUT:
     78        s -- Python object, module, etc.
     79
     80    OUTPUT:
     81        prints out help about s; it's often more more extensive than foo?
     82
     83    TESTS:
     84        sage: import numpy.linalg
     85        sage: sage.server.support.help(numpy.linalg.norm)
     86        <html><table notruncate bgcolor="#386074" cellpadding=10 cellspacing=10><tr><td bgcolor="#f5f5f5"><font color="#37546d">
     87        Help on function norm in module numpy.linalg.linalg:
     88        ...
     89        For values ord < 0, the result is, strictly speaking, not a
     90        mathematical 'norm', but it may still be useful for numerical purposes.
     91        </font></tr></td></table></html>
     92    """   
     93    print '<html><table notruncate bgcolor="#386074" cellpadding=10 cellspacing=10><tr><td bgcolor="#f5f5f5"><font color="#37546d">'
     94    pydoc.help(obj)
     95    print '</font></tr></td></table></html>'
     96   
    6897def get_rightmost_identifier(s):
    6998    X = string.ascii_letters + string.digits + '._'
    7099    i = len(s)-1