passagemath-repl 10.4.62__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- passagemath_repl-10.4.62.data/scripts/sage-cachegrind +25 -0
- passagemath_repl-10.4.62.data/scripts/sage-callgrind +16 -0
- passagemath_repl-10.4.62.data/scripts/sage-cleaner +230 -0
- passagemath_repl-10.4.62.data/scripts/sage-coverage +327 -0
- passagemath_repl-10.4.62.data/scripts/sage-eval +14 -0
- passagemath_repl-10.4.62.data/scripts/sage-fixdoctests +708 -0
- passagemath_repl-10.4.62.data/scripts/sage-inline-fortran +12 -0
- passagemath_repl-10.4.62.data/scripts/sage-ipynb2rst +50 -0
- passagemath_repl-10.4.62.data/scripts/sage-ipython +16 -0
- passagemath_repl-10.4.62.data/scripts/sage-massif +25 -0
- passagemath_repl-10.4.62.data/scripts/sage-notebook +267 -0
- passagemath_repl-10.4.62.data/scripts/sage-omega +25 -0
- passagemath_repl-10.4.62.data/scripts/sage-preparse +302 -0
- passagemath_repl-10.4.62.data/scripts/sage-run +27 -0
- passagemath_repl-10.4.62.data/scripts/sage-run-cython +10 -0
- passagemath_repl-10.4.62.data/scripts/sage-runtests +9 -0
- passagemath_repl-10.4.62.data/scripts/sage-startuptime.py +163 -0
- passagemath_repl-10.4.62.data/scripts/sage-valgrind +34 -0
- passagemath_repl-10.4.62.dist-info/METADATA +77 -0
- passagemath_repl-10.4.62.dist-info/RECORD +162 -0
- passagemath_repl-10.4.62.dist-info/WHEEL +5 -0
- passagemath_repl-10.4.62.dist-info/top_level.txt +1 -0
- sage/all__sagemath_repl.py +119 -0
- sage/doctest/__init__.py +4 -0
- sage/doctest/__main__.py +236 -0
- sage/doctest/all.py +4 -0
- sage/doctest/check_tolerance.py +261 -0
- sage/doctest/control.py +1727 -0
- sage/doctest/external.py +534 -0
- sage/doctest/fixtures.py +383 -0
- sage/doctest/forker.py +2665 -0
- sage/doctest/marked_output.py +102 -0
- sage/doctest/parsing.py +1708 -0
- sage/doctest/parsing_test.py +79 -0
- sage/doctest/reporting.py +733 -0
- sage/doctest/rif_tol.py +124 -0
- sage/doctest/sources.py +1657 -0
- sage/doctest/test.py +584 -0
- sage/doctest/tests/1second.rst +4 -0
- sage/doctest/tests/99seconds.rst +4 -0
- sage/doctest/tests/abort.rst +5 -0
- sage/doctest/tests/atexit.rst +7 -0
- sage/doctest/tests/fail_and_die.rst +6 -0
- sage/doctest/tests/initial.rst +15 -0
- sage/doctest/tests/interrupt.rst +7 -0
- sage/doctest/tests/interrupt_diehard.rst +14 -0
- sage/doctest/tests/keyboardinterrupt.rst +11 -0
- sage/doctest/tests/longtime.rst +5 -0
- sage/doctest/tests/nodoctest +5 -0
- sage/doctest/tests/random_seed.rst +4 -0
- sage/doctest/tests/show_skipped.rst +18 -0
- sage/doctest/tests/sig_on.rst +9 -0
- sage/doctest/tests/simple_failure.rst +8 -0
- sage/doctest/tests/sleep_and_raise.rst +106 -0
- sage/doctest/tests/tolerance.rst +31 -0
- sage/doctest/util.py +750 -0
- sage/interfaces/cleaner.py +48 -0
- sage/interfaces/quit.py +163 -0
- sage/misc/all__sagemath_repl.py +51 -0
- sage/misc/banner.py +235 -0
- sage/misc/benchmark.py +221 -0
- sage/misc/classgraph.py +131 -0
- sage/misc/copying.py +22 -0
- sage/misc/cython.py +694 -0
- sage/misc/dev_tools.py +745 -0
- sage/misc/edit_module.py +304 -0
- sage/misc/explain_pickle.py +3079 -0
- sage/misc/gperftools.py +361 -0
- sage/misc/inline_fortran.py +212 -0
- sage/misc/messaging.py +86 -0
- sage/misc/pager.py +21 -0
- sage/misc/profiler.py +179 -0
- sage/misc/python.py +70 -0
- sage/misc/remote_file.py +53 -0
- sage/misc/sage_eval.py +246 -0
- sage/misc/sage_input.py +3621 -0
- sage/misc/sagedoc.py +1742 -0
- sage/misc/sh.py +38 -0
- sage/misc/trace.py +90 -0
- sage/repl/__init__.py +16 -0
- sage/repl/all.py +15 -0
- sage/repl/attach.py +625 -0
- sage/repl/configuration.py +186 -0
- sage/repl/display/__init__.py +1 -0
- sage/repl/display/fancy_repr.py +354 -0
- sage/repl/display/formatter.py +318 -0
- sage/repl/display/jsmol_iframe.py +290 -0
- sage/repl/display/pretty_print.py +153 -0
- sage/repl/display/util.py +163 -0
- sage/repl/image.py +302 -0
- sage/repl/inputhook.py +91 -0
- sage/repl/interface_magic.py +298 -0
- sage/repl/interpreter.py +854 -0
- sage/repl/ipython_extension.py +593 -0
- sage/repl/ipython_kernel/__init__.py +1 -0
- sage/repl/ipython_kernel/__main__.py +4 -0
- sage/repl/ipython_kernel/all_jupyter.py +10 -0
- sage/repl/ipython_kernel/install.py +301 -0
- sage/repl/ipython_kernel/interact.py +278 -0
- sage/repl/ipython_kernel/kernel.py +217 -0
- sage/repl/ipython_kernel/widgets.py +466 -0
- sage/repl/ipython_kernel/widgets_sagenb.py +587 -0
- sage/repl/ipython_tests.py +163 -0
- sage/repl/load.py +326 -0
- sage/repl/preparse.py +2218 -0
- sage/repl/prompts.py +90 -0
- sage/repl/rich_output/__init__.py +4 -0
- sage/repl/rich_output/backend_base.py +648 -0
- sage/repl/rich_output/backend_doctest.py +316 -0
- sage/repl/rich_output/backend_emacs.py +151 -0
- sage/repl/rich_output/backend_ipython.py +596 -0
- sage/repl/rich_output/buffer.py +311 -0
- sage/repl/rich_output/display_manager.py +829 -0
- sage/repl/rich_output/example.avi +0 -0
- sage/repl/rich_output/example.canvas3d +1 -0
- sage/repl/rich_output/example.dvi +0 -0
- sage/repl/rich_output/example.flv +0 -0
- sage/repl/rich_output/example.gif +0 -0
- sage/repl/rich_output/example.jpg +0 -0
- sage/repl/rich_output/example.mkv +0 -0
- sage/repl/rich_output/example.mov +0 -0
- sage/repl/rich_output/example.mp4 +0 -0
- sage/repl/rich_output/example.ogv +0 -0
- sage/repl/rich_output/example.pdf +0 -0
- sage/repl/rich_output/example.png +0 -0
- sage/repl/rich_output/example.svg +54 -0
- sage/repl/rich_output/example.webm +0 -0
- sage/repl/rich_output/example.wmv +0 -0
- sage/repl/rich_output/example_jmol.spt.zip +0 -0
- sage/repl/rich_output/example_wavefront_scene.mtl +7 -0
- sage/repl/rich_output/example_wavefront_scene.obj +17 -0
- sage/repl/rich_output/output_basic.py +391 -0
- sage/repl/rich_output/output_browser.py +103 -0
- sage/repl/rich_output/output_catalog.py +54 -0
- sage/repl/rich_output/output_graphics.py +320 -0
- sage/repl/rich_output/output_graphics3d.py +345 -0
- sage/repl/rich_output/output_video.py +231 -0
- sage/repl/rich_output/preferences.py +432 -0
- sage/repl/rich_output/pretty_print.py +339 -0
- sage/repl/rich_output/test_backend.py +201 -0
- sage/repl/user_globals.py +214 -0
- sage/tests/__init__.py +1 -0
- sage/tests/all.py +3 -0
- sage/tests/article_heuberger_krenn_kropf_fsm-in-sage.py +630 -0
- sage/tests/arxiv_0812_2725.py +351 -0
- sage/tests/benchmark.py +1923 -0
- sage/tests/book_schilling_zabrocki_kschur_primer.py +795 -0
- sage/tests/book_stein_ent.py +651 -0
- sage/tests/book_stein_modform.py +558 -0
- sage/tests/cmdline.py +790 -0
- sage/tests/combinatorial_hopf_algebras.py +52 -0
- sage/tests/finite_poset.py +623 -0
- sage/tests/functools_partial_src.py +27 -0
- sage/tests/gosper-sum.py +218 -0
- sage/tests/lazy_imports.py +28 -0
- sage/tests/modular_group_cohomology.py +80 -0
- sage/tests/numpy.py +21 -0
- sage/tests/parigp.py +76 -0
- sage/tests/startup.py +27 -0
- sage/tests/symbolic-series.py +76 -0
- sage/tests/sympy.py +16 -0
- sage/tests/test_deprecation.py +31 -0
@@ -0,0 +1,316 @@
|
|
1
|
+
# sage_setup: distribution = sagemath-repl
|
2
|
+
"""
|
3
|
+
The backend used for doctests
|
4
|
+
|
5
|
+
This backend is active during doctests. It should mimic the behavior
|
6
|
+
of the IPython command line as close as possible. Without actually
|
7
|
+
launching image viewers, of course.
|
8
|
+
|
9
|
+
EXAMPLES::
|
10
|
+
|
11
|
+
sage: from sage.repl.rich_output import get_display_manager
|
12
|
+
sage: get_display_manager()
|
13
|
+
The Sage display manager using the doctest backend
|
14
|
+
"""
|
15
|
+
|
16
|
+
#*****************************************************************************
|
17
|
+
# Copyright (C) 2015 Volker Braun <vbraun.name@gmail.com>
|
18
|
+
#
|
19
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
20
|
+
# as published by the Free Software Foundation; either version 2 of
|
21
|
+
# the License, or (at your option) any later version.
|
22
|
+
# http://www.gnu.org/licenses/
|
23
|
+
#*****************************************************************************
|
24
|
+
|
25
|
+
import sys
|
26
|
+
|
27
|
+
from sage.repl.rich_output.backend_base import BackendBase
|
28
|
+
from sage.repl.rich_output.output_catalog import *
|
29
|
+
|
30
|
+
|
31
|
+
class BackendDoctest(BackendBase):
|
32
|
+
|
33
|
+
def _repr_(self):
|
34
|
+
"""
|
35
|
+
Return a string representation.
|
36
|
+
|
37
|
+
OUTPUT: string
|
38
|
+
|
39
|
+
EXAMPLES::
|
40
|
+
|
41
|
+
sage: from sage.repl.rich_output.backend_doctest import BackendDoctest
|
42
|
+
sage: backend = BackendDoctest()
|
43
|
+
sage: backend._repr_()
|
44
|
+
'doctest'
|
45
|
+
"""
|
46
|
+
return 'doctest'
|
47
|
+
|
48
|
+
def default_preferences(self):
|
49
|
+
"""
|
50
|
+
Return the backend's display preferences.
|
51
|
+
|
52
|
+
Matches the IPython command line display preferences to keep
|
53
|
+
the differences between that and the doctests to a minimum.
|
54
|
+
|
55
|
+
OUTPUT:
|
56
|
+
|
57
|
+
Instance of
|
58
|
+
:class:`~sage.repl.rich_output.preferences.DisplayPreferences`.
|
59
|
+
|
60
|
+
EXAMPLES::
|
61
|
+
|
62
|
+
sage: from sage.repl.rich_output.backend_ipython import BackendIPythonCommandline
|
63
|
+
sage: backend = BackendIPythonCommandline()
|
64
|
+
sage: backend.default_preferences()
|
65
|
+
Display preferences:
|
66
|
+
* align_latex is not specified
|
67
|
+
* graphics is not specified
|
68
|
+
* supplemental_plot = never
|
69
|
+
* text is not specified
|
70
|
+
"""
|
71
|
+
from sage.repl.rich_output.preferences import DisplayPreferences
|
72
|
+
return DisplayPreferences(supplemental_plot='never')
|
73
|
+
|
74
|
+
def install(self, **kwds):
|
75
|
+
"""
|
76
|
+
Switch to the doctest backend.
|
77
|
+
|
78
|
+
This method is being called from within
|
79
|
+
:meth:`~sage.repl.rich_output.display_manager.DisplayManager.switch_backend`. You
|
80
|
+
should never call it by hand.
|
81
|
+
|
82
|
+
INPUT:
|
83
|
+
|
84
|
+
- ``**kwds`` -- none of the optional keyword arguments are used in the
|
85
|
+
doctest backend
|
86
|
+
|
87
|
+
EXAMPLES::
|
88
|
+
|
89
|
+
sage: from sage.repl.rich_output.backend_doctest import BackendDoctest
|
90
|
+
sage: backend = BackendDoctest()
|
91
|
+
sage: backend.install()
|
92
|
+
sage: backend.uninstall()
|
93
|
+
"""
|
94
|
+
self._old_displayhook = sys.displayhook
|
95
|
+
sys.displayhook = self.get_display_manager().displayhook
|
96
|
+
|
97
|
+
def uninstall(self):
|
98
|
+
"""
|
99
|
+
Switch away from the doctest backend.
|
100
|
+
|
101
|
+
This method is being called from within
|
102
|
+
:meth:`~sage.repl.rich_output.display_manager.DisplayManager.switch_backend`. You
|
103
|
+
should never call it by hand.
|
104
|
+
|
105
|
+
EXAMPLES::
|
106
|
+
|
107
|
+
sage: from sage.repl.rich_output.backend_doctest import BackendDoctest
|
108
|
+
sage: backend = BackendDoctest()
|
109
|
+
sage: backend.install()
|
110
|
+
sage: backend.uninstall()
|
111
|
+
"""
|
112
|
+
sys.displayhook = self._old_displayhook
|
113
|
+
|
114
|
+
def supported_output(self):
|
115
|
+
"""
|
116
|
+
Return the supported output types.
|
117
|
+
|
118
|
+
OUTPUT:
|
119
|
+
|
120
|
+
Set of subclasses of
|
121
|
+
:class:`~sage.repl.rich_output.output_basic.OutputBase`, the
|
122
|
+
supported output container types.
|
123
|
+
|
124
|
+
EXAMPLES::
|
125
|
+
|
126
|
+
sage: from sage.repl.rich_output.backend_doctest import BackendDoctest
|
127
|
+
sage: from sage.repl.rich_output.output_catalog import *
|
128
|
+
sage: backend = BackendDoctest()
|
129
|
+
sage: OutputPlainText in backend.supported_output()
|
130
|
+
True
|
131
|
+
sage: OutputSceneJmol in backend.supported_output()
|
132
|
+
True
|
133
|
+
"""
|
134
|
+
return set([
|
135
|
+
OutputPlainText, OutputAsciiArt, OutputUnicodeArt,
|
136
|
+
OutputImagePng, OutputImageGif, OutputImageJpg,
|
137
|
+
OutputImageSvg, OutputImagePdf, OutputImageDvi,
|
138
|
+
OutputSceneJmol, OutputSceneCanvas3d, OutputSceneWavefront,
|
139
|
+
OutputVideoOgg, OutputVideoWebM, OutputVideoMp4,
|
140
|
+
OutputVideoFlash, OutputVideoMatroska, OutputVideoAvi,
|
141
|
+
OutputVideoWmv, OutputVideoQuicktime,
|
142
|
+
])
|
143
|
+
|
144
|
+
def displayhook(self, plain_text, rich_output):
|
145
|
+
"""
|
146
|
+
Display object from displayhook.
|
147
|
+
|
148
|
+
INPUT:
|
149
|
+
|
150
|
+
- ``plain_text`` -- instance of
|
151
|
+
:class:`~sage.repl.rich_output.output_basic.OutputPlainText`. The
|
152
|
+
plain text version of the output.
|
153
|
+
|
154
|
+
- ``rich_output`` -- instance of an output container class
|
155
|
+
(subclass of
|
156
|
+
:class:`~sage.repl.rich_output.output_basic.OutputBase`). Guaranteed
|
157
|
+
to be one of the output containers returned from
|
158
|
+
:meth:`supported_output`, possibly the same as
|
159
|
+
``plain_text``.
|
160
|
+
|
161
|
+
EXAMPLES:
|
162
|
+
|
163
|
+
This ends up calling the displayhook::
|
164
|
+
|
165
|
+
sage: plt = plot(sin) # needs sage.plot sage.symbolic
|
166
|
+
sage: plt # needs sage.plot sage.symbolic
|
167
|
+
Graphics object consisting of 1 graphics primitive
|
168
|
+
sage: plt.show() # needs sage.plot sage.symbolic
|
169
|
+
|
170
|
+
sage: from sage.repl.rich_output import get_display_manager
|
171
|
+
sage: dm = get_display_manager()
|
172
|
+
sage: dm.displayhook(plt) # indirect doctest # needs sage.plot sage.symbolic
|
173
|
+
Graphics object consisting of 1 graphics primitive
|
174
|
+
"""
|
175
|
+
self.validate(rich_output)
|
176
|
+
if any(isinstance(rich_output, cls)
|
177
|
+
for cls in [OutputPlainText, OutputAsciiArt, OutputLatex, OutputHtml]):
|
178
|
+
rich_output.print_to_stdout()
|
179
|
+
else:
|
180
|
+
plain_text.print_to_stdout()
|
181
|
+
|
182
|
+
def display_immediately(self, plain_text, rich_output):
|
183
|
+
"""
|
184
|
+
Display object immediately.
|
185
|
+
|
186
|
+
INPUT:
|
187
|
+
|
188
|
+
Same as :meth:`displayhook`.
|
189
|
+
|
190
|
+
EXAMPLES:
|
191
|
+
|
192
|
+
The following example does not call the displayhook. More
|
193
|
+
precisely, the ``show()`` method returns ``None`` which is
|
194
|
+
ignored by the displayhook. When running the example on a Sage
|
195
|
+
display backend capable of displaying graphics outside of the
|
196
|
+
displayhook, the plot is still shown. Nothing is shown during
|
197
|
+
doctests::
|
198
|
+
|
199
|
+
sage: plt = plot(sin) # needs sage.plot sage.symbolic
|
200
|
+
sage: plt # needs sage.plot sage.symbolic
|
201
|
+
Graphics object consisting of 1 graphics primitive
|
202
|
+
sage: plt.show() # needs sage.plot sage.symbolic
|
203
|
+
|
204
|
+
sage: from sage.repl.rich_output import get_display_manager
|
205
|
+
sage: dm = get_display_manager()
|
206
|
+
sage: dm.display_immediately(plt) # indirect doctest # needs sage.plot sage.symbolic
|
207
|
+
"""
|
208
|
+
self.validate(rich_output)
|
209
|
+
types_to_print = [OutputPlainText, OutputAsciiArt, OutputUnicodeArt, OutputHtml]
|
210
|
+
if any(isinstance(rich_output, cls) for cls in types_to_print):
|
211
|
+
rich_output.print_to_stdout()
|
212
|
+
|
213
|
+
def validate(self, rich_output):
|
214
|
+
"""
|
215
|
+
Perform checks on ``rich_output``.
|
216
|
+
|
217
|
+
INPUT:
|
218
|
+
|
219
|
+
- ``rich_output`` -- instance of a subclass of
|
220
|
+
:class:`~sage.repl.rich_output.output_basic.OutputBase`
|
221
|
+
|
222
|
+
OUTPUT: an assertion is triggered if ``rich_output`` is invalid
|
223
|
+
|
224
|
+
EXAMPLES::
|
225
|
+
|
226
|
+
sage: from sage.repl.rich_output import get_display_manager
|
227
|
+
sage: dm = get_display_manager()
|
228
|
+
sage: invalid = dm.types.OutputImagePng('invalid')
|
229
|
+
sage: backend = dm._backend; backend
|
230
|
+
doctest
|
231
|
+
sage: backend.validate(invalid)
|
232
|
+
Traceback (most recent call last):
|
233
|
+
...
|
234
|
+
AssertionError
|
235
|
+
sage: backend.validate(dm.types.OutputPlainText.example())
|
236
|
+
sage: backend.validate(dm.types.OutputAsciiArt.example())
|
237
|
+
sage: backend.validate(dm.types.OutputLatex.example())
|
238
|
+
sage: backend.validate(dm.types.OutputImagePng.example())
|
239
|
+
sage: backend.validate(dm.types.OutputImageGif.example())
|
240
|
+
sage: backend.validate(dm.types.OutputImageJpg.example())
|
241
|
+
sage: backend.validate(dm.types.OutputImageSvg.example())
|
242
|
+
sage: backend.validate(dm.types.OutputImagePdf.example())
|
243
|
+
sage: backend.validate(dm.types.OutputImageDvi.example())
|
244
|
+
sage: backend.validate(dm.types.OutputSceneJmol.example())
|
245
|
+
sage: backend.validate(dm.types.OutputSceneWavefront.example())
|
246
|
+
sage: backend.validate(dm.types.OutputSceneCanvas3d.example())
|
247
|
+
sage: backend.validate(dm.types.OutputVideoOgg.example())
|
248
|
+
sage: backend.validate(dm.types.OutputVideoWebM.example())
|
249
|
+
sage: backend.validate(dm.types.OutputVideoMp4.example())
|
250
|
+
sage: backend.validate(dm.types.OutputVideoFlash.example())
|
251
|
+
sage: backend.validate(dm.types.OutputVideoMatroska.example())
|
252
|
+
sage: backend.validate(dm.types.OutputVideoAvi.example())
|
253
|
+
sage: backend.validate(dm.types.OutputVideoWmv.example())
|
254
|
+
sage: backend.validate(dm.types.OutputVideoQuicktime.example())
|
255
|
+
"""
|
256
|
+
if isinstance(rich_output, OutputPlainText):
|
257
|
+
pass
|
258
|
+
elif isinstance(rich_output, OutputAsciiArt):
|
259
|
+
pass
|
260
|
+
elif isinstance(rich_output, OutputUnicodeArt):
|
261
|
+
pass
|
262
|
+
elif isinstance(rich_output, OutputLatex):
|
263
|
+
pass
|
264
|
+
elif isinstance(rich_output, OutputHtml):
|
265
|
+
pass
|
266
|
+
elif isinstance(rich_output, OutputImagePng):
|
267
|
+
assert rich_output.png.get().startswith(b'\x89PNG')
|
268
|
+
elif isinstance(rich_output, OutputImageGif):
|
269
|
+
assert rich_output.gif.get().startswith(b'GIF89a')
|
270
|
+
elif isinstance(rich_output, OutputImageJpg):
|
271
|
+
assert rich_output.jpg.get().startswith(b'\xff\xd8\xff\xe0\x00\x10JFIF')
|
272
|
+
elif isinstance(rich_output, OutputImageSvg):
|
273
|
+
assert b'</svg>' in rich_output.svg.get()
|
274
|
+
elif isinstance(rich_output, OutputImagePdf):
|
275
|
+
assert rich_output.pdf.get().startswith(b'%PDF-')
|
276
|
+
elif isinstance(rich_output, OutputImageDvi):
|
277
|
+
assert b'TeX output' in rich_output.dvi.get()
|
278
|
+
elif isinstance(rich_output, OutputSceneJmol):
|
279
|
+
assert rich_output.preview_png.get().startswith(b'\x89PNG')
|
280
|
+
assert rich_output.scene_zip.get().startswith(b'PK') # zip archive
|
281
|
+
elif isinstance(rich_output, OutputSceneWavefront):
|
282
|
+
assert rich_output.obj.get().startswith(b'mtllib ')
|
283
|
+
assert rich_output.mtl.get().startswith(b'newmtl ')
|
284
|
+
elif isinstance(rich_output, OutputSceneCanvas3d):
|
285
|
+
assert rich_output.canvas3d.get().startswith(b'[{"vertices":')
|
286
|
+
elif isinstance(rich_output, OutputVideoOgg):
|
287
|
+
assert rich_output.video.get().startswith(b'OggS')
|
288
|
+
elif isinstance(rich_output, OutputVideoWebM):
|
289
|
+
data = rich_output.video.get()
|
290
|
+
assert data.startswith(b'\x1a\x45\xdf\xa3')
|
291
|
+
assert b'\x42\x82\x84webm' in data
|
292
|
+
elif isinstance(rich_output, OutputVideoMp4):
|
293
|
+
data = rich_output.video.get()
|
294
|
+
assert data[4:8] == b'ftyp'
|
295
|
+
assert data.startswith(b'\0\0\0')
|
296
|
+
# See http://www.ftyps.com/
|
297
|
+
ftyps = [data[i:i+4] for i in range(8, data[3], 4)]
|
298
|
+
del ftyps[1] # version number, not an ftyp
|
299
|
+
expected = [b'avc1', b'iso2', b'mp41', b'mp42']
|
300
|
+
assert any(i in ftyps for i in expected)
|
301
|
+
elif isinstance(rich_output, OutputVideoFlash):
|
302
|
+
assert rich_output.video.get().startswith(b'FLV\x01')
|
303
|
+
elif isinstance(rich_output, OutputVideoMatroska):
|
304
|
+
data = rich_output.video.get()
|
305
|
+
assert data.startswith(b'\x1a\x45\xdf\xa3')
|
306
|
+
assert b'\x42\x82\x88matroska' in data
|
307
|
+
elif isinstance(rich_output, OutputVideoAvi):
|
308
|
+
data = rich_output.video.get()
|
309
|
+
assert data[:4] == b'RIFF' and data[8:12] == b'AVI '
|
310
|
+
elif isinstance(rich_output, OutputVideoWmv):
|
311
|
+
assert rich_output.video.get().startswith(b'\x30\x26\xb2\x75')
|
312
|
+
elif isinstance(rich_output, OutputVideoQuicktime):
|
313
|
+
data = rich_output.video.get()
|
314
|
+
assert data[4:12] == b'ftypqt ' or data[4:8] == b'moov'
|
315
|
+
else:
|
316
|
+
raise TypeError('rich_output type not supported')
|
@@ -0,0 +1,151 @@
|
|
1
|
+
# sage_setup: distribution = sagemath-repl
|
2
|
+
r"""
|
3
|
+
Emacs sage-mode Backend for the Sage Rich Output System
|
4
|
+
|
5
|
+
This module defines the Emacs backend for :mod:`sage.repl.rich_output`
|
6
|
+
based on the IPython shell version.
|
7
|
+
"""
|
8
|
+
|
9
|
+
# ****************************************************************************
|
10
|
+
# Copyright (C) 2015 Ivan Andrus <darthandrus@gmail.com>
|
11
|
+
#
|
12
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
13
|
+
# as published by the Free Software Foundation; either version 2 of
|
14
|
+
# the License, or (at your option) any later version.
|
15
|
+
# https://www.gnu.org/licenses/
|
16
|
+
# ****************************************************************************
|
17
|
+
|
18
|
+
from sage.repl.rich_output.backend_ipython import BackendIPythonCommandline
|
19
|
+
from sage.repl.rich_output.output_catalog import *
|
20
|
+
|
21
|
+
|
22
|
+
class BackendEmacs(BackendIPythonCommandline):
|
23
|
+
"""
|
24
|
+
Emacs Backend.
|
25
|
+
|
26
|
+
This backend is used by Emacs' sage-mode to have typeset output
|
27
|
+
and inline images.
|
28
|
+
|
29
|
+
EXAMPLES::
|
30
|
+
|
31
|
+
sage: from sage.repl.rich_output.backend_emacs import BackendEmacs
|
32
|
+
sage: BackendEmacs()
|
33
|
+
Emacs sage-mode
|
34
|
+
"""
|
35
|
+
|
36
|
+
def _repr_(self):
|
37
|
+
r"""
|
38
|
+
Return string representation of the backend.
|
39
|
+
|
40
|
+
OUTPUT: string
|
41
|
+
|
42
|
+
EXAMPLES::
|
43
|
+
|
44
|
+
sage: from sage.repl.rich_output.backend_emacs import BackendEmacs
|
45
|
+
sage: backend = BackendEmacs()
|
46
|
+
sage: backend._repr_()
|
47
|
+
'Emacs sage-mode'
|
48
|
+
"""
|
49
|
+
return 'Emacs sage-mode'
|
50
|
+
|
51
|
+
def default_preferences(self):
|
52
|
+
"""
|
53
|
+
Return the backend's display preferences.
|
54
|
+
|
55
|
+
Override this method to change the default preferences when
|
56
|
+
using your backend.
|
57
|
+
|
58
|
+
OUTPUT:
|
59
|
+
|
60
|
+
Instance of
|
61
|
+
:class:`~sage.repl.rich_output.preferences.DisplayPreferences`.
|
62
|
+
|
63
|
+
EXAMPLES::
|
64
|
+
|
65
|
+
sage: from sage.repl.rich_output.backend_emacs import BackendEmacs
|
66
|
+
sage: backend = BackendEmacs()
|
67
|
+
sage: backend.default_preferences()
|
68
|
+
Display preferences:
|
69
|
+
* align_latex is not specified
|
70
|
+
* graphics is not specified
|
71
|
+
* supplemental_plot is not specified
|
72
|
+
* text is not specified
|
73
|
+
"""
|
74
|
+
from sage.repl.rich_output.preferences import DisplayPreferences
|
75
|
+
return DisplayPreferences()
|
76
|
+
|
77
|
+
def displayhook(self, plain_text, rich_output):
|
78
|
+
r"""
|
79
|
+
Backend implementation of the displayhook.
|
80
|
+
|
81
|
+
INPUT:
|
82
|
+
|
83
|
+
- ``plain_text`` -- instance of
|
84
|
+
:class:`~sage.repl.rich_output.output_basic.OutputPlainText`. The
|
85
|
+
plain text version of the output.
|
86
|
+
|
87
|
+
- ``rich_output`` -- instance of an output container class
|
88
|
+
(subclass of
|
89
|
+
:class:`~sage.repl.rich_output.output_basic.OutputBase`). Guaranteed
|
90
|
+
to be one of the output containers returned from
|
91
|
+
:meth:`supported_output`, possibly the same as
|
92
|
+
``plain_text``.
|
93
|
+
|
94
|
+
OUTPUT:
|
95
|
+
|
96
|
+
Because this is based on the IPython commandline display hook,
|
97
|
+
it returns the IPython display data, a pair of
|
98
|
+
dictionaries. The first dictionary contains mime types as keys
|
99
|
+
and the respective output as value. The second dictionary is
|
100
|
+
metadata.
|
101
|
+
|
102
|
+
EXAMPLES::
|
103
|
+
|
104
|
+
sage: from sage.repl.rich_output.output_basic import OutputPlainText, OutputLatex
|
105
|
+
sage: plain_text = OutputPlainText.example()
|
106
|
+
sage: from sage.repl.rich_output.backend_emacs import BackendEmacs
|
107
|
+
sage: backend = BackendEmacs()
|
108
|
+
sage: backend.displayhook(plain_text, plain_text)
|
109
|
+
({'text/plain': 'Example plain text output'}, {})
|
110
|
+
sage: latex_text = OutputLatex.example()
|
111
|
+
sage: backend.displayhook(plain_text, latex_text)
|
112
|
+
({'text/plain': 'BEGIN_TEXT:Example plain text output:END_TEXT\nBEGIN_LATEX:\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\int \\sin\\left(x\\right)\\,{d x}:END_LATEX'},
|
113
|
+
{})
|
114
|
+
"""
|
115
|
+
|
116
|
+
if isinstance(rich_output, OutputPlainText):
|
117
|
+
return ({'text/plain': rich_output.text.get_str()}, {})
|
118
|
+
elif isinstance(rich_output, OutputAsciiArt):
|
119
|
+
return ({'text/plain': rich_output.ascii_art.get_str()}, {})
|
120
|
+
elif isinstance(rich_output, OutputLatex):
|
121
|
+
text = "BEGIN_TEXT:" + plain_text.text.get_str() + ":END_TEXT\nBEGIN_LATEX:" + \
|
122
|
+
rich_output.latex.get_str() + ":END_LATEX"
|
123
|
+
return ({'text/plain': text}, {})
|
124
|
+
|
125
|
+
# TODO: perhaps handle these by returning the data inline,
|
126
|
+
# e.g. base64 encoded, so that sage-mode can show inline
|
127
|
+
# images for remotely running shells.
|
128
|
+
elif isinstance(rich_output, OutputImagePng):
|
129
|
+
msg = self.launch_viewer(
|
130
|
+
rich_output.png.filename(ext='png'), plain_text.text.get())
|
131
|
+
return ({'text/plain': msg}, {})
|
132
|
+
elif isinstance(rich_output, OutputImageGif):
|
133
|
+
msg = self.launch_viewer(
|
134
|
+
rich_output.gif.filename(ext='gif'), plain_text.text.get())
|
135
|
+
return ({'text/plain': msg}, {})
|
136
|
+
elif isinstance(rich_output, OutputImagePdf):
|
137
|
+
msg = self.launch_viewer(
|
138
|
+
rich_output.pdf.filename(ext='pdf'), plain_text.text.get())
|
139
|
+
return ({'text/plain': msg}, {})
|
140
|
+
elif isinstance(rich_output, OutputImageDvi):
|
141
|
+
msg = self.launch_viewer(
|
142
|
+
rich_output.dvi.filename(ext='dvi'), plain_text.text.get())
|
143
|
+
return ({'text/plain': msg}, {})
|
144
|
+
elif isinstance(rich_output, OutputSceneJmol):
|
145
|
+
msg = self.launch_jmol(rich_output, plain_text.text.get())
|
146
|
+
return ({'text/plain': msg}, {})
|
147
|
+
elif isinstance(rich_output, OutputSceneWavefront):
|
148
|
+
msg = self.launch_sage3d(rich_output, plain_text.text.get())
|
149
|
+
return ({'text/plain': msg}, {})
|
150
|
+
else:
|
151
|
+
raise TypeError('rich_output type not supported')
|