Ticket #2992: sage-2992-part2.patch

File sage-2992-part2.patch, 1.7 KB (added by was, 13 years ago)
  • sage/server/support.py

    # HG changeset patch
    # User William Stein <wstein@gmail.com>
    # Date 1210816973 25200
    # Node ID 6eca3be50ce0dd16fe3fa31f53fd9f574fabf70d
    # Parent  feb0c046a6282033252a99f50fa13eac5b8ca034
    trac #2992 -- greatly improved robustness of help(foo)
    
    diff -r feb0c046a628 -r 6eca3be50ce0 sage/server/support.py
    a b def help(obj): 
    8989        For values ord < 0, the result is, strictly speaking, not a
    9090        mathematical 'norm', but it may still be useful for numerical purposes.
    9191        </font></tr></td></table></html>
    92     """   
    93     print '<html><table notruncate notracebacks bgcolor="#386074" cellpadding=10 cellspacing=10><tr><td bgcolor="#f5f5f5"><font color="#37546d">'
    94     pydoc.help(obj)
    95     print '</font></tr></td></table></html>'
     92    """
     93    from pydoc import resolve, html, describe
     94    import sage.server.notebook.interact as interact
     95
     96    print '<html><table notracebacks bgcolor="#386074" cellpadding=10 cellspacing=10><tr><td bgcolor="#f5f5f5"><font color="#37546d">'
     97    object, name = resolve(obj)
     98    page = html.page(describe(object), html.document(object, name))
     99    page = page.replace('<a href','<a ')
     100    n = 0
     101    while True:
     102        filename = 'docs-%s.html'%n
     103        if not os.path.exists(filename): break
     104        n += 1
     105    open(filename, 'w').write(page)
     106    print "&nbsp;&nbsp;&nbsp;<a target='_new' href='cell://%s'>Click to open help window</a>&nbsp;&nbsp;&nbsp;"%filename
     107    print '<br></font></tr></td></table></html>'
    96108   
    97109def get_rightmost_identifier(s):
    98110    X = string.ascii_letters + string.digits + '._'