Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
fix the remaining doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
vbraun committed Aug 27, 2015
1 parent 11ebe8a commit 553d2bb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 51 deletions.
12 changes: 8 additions & 4 deletions src/sage/databases/oeis.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
from sage.misc.flatten import flatten
from sage.misc.unknown import Unknown
from sage.misc.misc import embedded
from sage.misc.html import html
from sage.misc.html import HtmlFragment
from collections import defaultdict
from urllib import urlopen, urlencode
import re
Expand Down Expand Up @@ -1430,8 +1430,12 @@ def links(self, browse=None, format='guess'):
sage: s.links(format='url')[3]
'http://oeis.org/A000024'
sage: s.links(format="html")
'0: Wikipedia, <a href="http://en.wikipedia.org/wiki/42_(number)">42 (number)</a>\n1: See. also <a href="http://trac.sagemath.org/sage_trac/ticket/42">trac ticket #42</a>...'
sage: HTML = s.links(format="html"); HTML
0: Wikipedia, <a href="http://en.wikipedia.org/wiki/42_(number)">42 (number)</a>
1: See. also <a href="http://trac.sagemath.org/sage_trac/ticket/42">trac ticket #42</a>
...
sage: type(HTML)
<class 'sage.misc.html.HtmlFragment'>
"""
url_absolute = lambda s: re.sub('\"\/', '\"' + oeis_url, s)
if browse is None:
Expand All @@ -1443,7 +1447,7 @@ def links(self, browse=None, format='guess'):
elif format == 'raw':
return FancyTuple(self._fields['H'])
elif format == 'html':
return html(FancyTuple([url_absolute(_) for _ in self._fields['H']]))
return HtmlFragment(FancyTuple([url_absolute(_) for _ in self._fields['H']]))
elif format == 'url':
url_list = flatten([_urls(url_absolute(string)) for string in self._fields['H']])
return FancyTuple(url_list)
Expand Down
44 changes: 2 additions & 42 deletions src/sage/interacts/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,50 +40,10 @@ def interact(func, **kwds):
....: print(x)
<html>...</html>
"""
return _sagenb_interact(func, **kwds)


def _sagenb_interact(func, **kwds):
"""
Wrapper around the SageNB interact decorator
from sagenb.notebook.interact import interact as sagenb_interact
return sagenb_interact(func, **kwds)

Reverts to the old ``html`` behavior for SageNB interacts, where
calling ``html(x)`` prints html to stdout instead of returning a
:class:`sage.misc.html.HtmlFragment` instance.

EXAMPLES::
sage: from sage.interacts.decorator import _sagenb_interact
sage: g = Graphics()
sage: @_sagenb_interact
....: def f(x=[1,2,3], graph=g):
....: html(x)
<html>...</html>
sage: f(2)
<script type="math/tex">2</script>
"""
# Evil hack: can only generate function with given argspec via exec
argspec = inspect.getargspec(func)
defaults = ['_argspec_defaults[{0}]'.format(i) for i in range(len(argspec.defaults))]
signature = inspect.formatargspec(argspec[0], argspec[1], argspec[2], defaults)
func_src = textwrap.dedent("""
@sagenb_interact
def sagenb_func{signature}:
import sage.misc.html
try:
sage.misc.html._old_and_deprecated_behavior = True
return func{args}
finally:
sage.misc.html._old_and_deprecated_behavior = False
""").format(
signature=signature,
args=inspect.formatargspec(argspec[0]),
_argspec_defaults=argspec.defaults,
)
from sagenb.notebook.interact import interact as sagenb_interact
globals = dict(func=func, sagenb_interact=sagenb_interact)
exec func_src in globals
return globals['sagenb_func']



13 changes: 8 additions & 5 deletions src/sage/misc/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,11 @@ class table(SageObject):
| 4 | 5 | 60 |
+-----+---+----+
To generate HTML you should use ``html(table(...))``::
To generate HTML you should use ``html(table(...))`` but that
doesn't work :trac:`18292`; A workaround is ::
sage: output = html(table([["$x$", "$\sin(x)$"]] + [(x,n(sin(x), digits=2)) for x in [0..3]],
....: header_row=True, frame=True))
sage: output = table([["$x$", "$\sin(x)$"]] + [(x,n(sin(x), digits=2)) for x in [0..3]],
....: header_row=True, frame=True)._html_()
sage: type(output)
<class 'sage.misc.html.HtmlFragment'>
sage: print(output)
Expand Down Expand Up @@ -641,7 +642,7 @@ def _html_(self):
sage: T = table([[r'$\sin(x)$', '$x$', 'text'], [1,34342,3], [identity_matrix(2),5,6]])
sage: T._html_()
'<div.../div>'
<div.../div>
sage: print(T._html_())
<div class="notruncate">
<table class="table_form">
Expand All @@ -668,7 +669,9 @@ def _html_(self):
</table>
</div>
Note that calling ``html(table(...))`` has the same effect as ``table(...)._html_()`::
Note that calling ``html(table(...))`` will have the same
effect as ``table(...)._html_()` after the deprecation period
in :trac:`18292`::
sage: T = table([["$x$", "$\sin(x)$"]] + [(x,n(sin(x), digits=2)) for x in [0..3]], header_row=True, frame=True)
sage: T
Expand Down

0 comments on commit 553d2bb

Please sign in to comment.