passagemath-repl 10.5.1__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.5.1.data/scripts/sage-cachegrind +25 -0
- passagemath_repl-10.5.1.data/scripts/sage-callgrind +16 -0
- passagemath_repl-10.5.1.data/scripts/sage-cleaner +230 -0
- passagemath_repl-10.5.1.data/scripts/sage-coverage +327 -0
- passagemath_repl-10.5.1.data/scripts/sage-eval +14 -0
- passagemath_repl-10.5.1.data/scripts/sage-fixdoctests +710 -0
- passagemath_repl-10.5.1.data/scripts/sage-inline-fortran +12 -0
- passagemath_repl-10.5.1.data/scripts/sage-ipynb2rst +50 -0
- passagemath_repl-10.5.1.data/scripts/sage-ipython +16 -0
- passagemath_repl-10.5.1.data/scripts/sage-massif +25 -0
- passagemath_repl-10.5.1.data/scripts/sage-notebook +267 -0
- passagemath_repl-10.5.1.data/scripts/sage-omega +25 -0
- passagemath_repl-10.5.1.data/scripts/sage-preparse +302 -0
- passagemath_repl-10.5.1.data/scripts/sage-run +27 -0
- passagemath_repl-10.5.1.data/scripts/sage-run-cython +10 -0
- passagemath_repl-10.5.1.data/scripts/sage-runtests +9 -0
- passagemath_repl-10.5.1.data/scripts/sage-startuptime.py +163 -0
- passagemath_repl-10.5.1.data/scripts/sage-valgrind +34 -0
- passagemath_repl-10.5.1.dist-info/METADATA +77 -0
- passagemath_repl-10.5.1.dist-info/RECORD +162 -0
- passagemath_repl-10.5.1.dist-info/WHEEL +5 -0
- passagemath_repl-10.5.1.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 +134 -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 +249 -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/all.py +0 -0
- sage/tests/all__sagemath_repl.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 +1925 -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 +796 -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,339 @@
|
|
1
|
+
# sage_setup: distribution = sagemath-repl
|
2
|
+
r"""
|
3
|
+
The ``pretty_print`` command
|
4
|
+
|
5
|
+
Works similar to the ``print`` function, except that it always tries
|
6
|
+
to use a rich output for an object, as specified via the text display
|
7
|
+
preference. If such a rich output is not available, it falls back on the
|
8
|
+
plain text.
|
9
|
+
|
10
|
+
EXAMPLES::
|
11
|
+
|
12
|
+
sage: pretty_print(1, 2, 3)
|
13
|
+
1 2 3
|
14
|
+
|
15
|
+
sage: pretty_print(x^2 / (x + 1)) # needs sage.symbolic
|
16
|
+
x^2/(x + 1)
|
17
|
+
|
18
|
+
TESTS::
|
19
|
+
|
20
|
+
sage: dm = get_display_manager()
|
21
|
+
sage: dm.preferences.text = 'ascii_art'
|
22
|
+
|
23
|
+
EXAMPLES::
|
24
|
+
|
25
|
+
sage: %display ascii_art # not tested
|
26
|
+
sage: pretty_print(x^2 / (x + 1)) # needs sage.symbolic
|
27
|
+
2
|
28
|
+
x
|
29
|
+
-----
|
30
|
+
x + 1
|
31
|
+
|
32
|
+
TESTS:
|
33
|
+
|
34
|
+
After the previous example, we need to reset the text display preferences::
|
35
|
+
|
36
|
+
sage: dm.preferences.text = None
|
37
|
+
|
38
|
+
EXAMPLES:
|
39
|
+
|
40
|
+
Printing a graphics object just prints a string, whereas
|
41
|
+
:func:`pretty_print` does not print anything and just shows the
|
42
|
+
graphics instead::
|
43
|
+
|
44
|
+
sage: print(plot(sin)) # needs sage.plot sage.symbolic
|
45
|
+
Graphics object consisting of 1 graphics primitive
|
46
|
+
sage: pretty_print(plot(sin)) # needs sage.plot sage.symbolic
|
47
|
+
"""
|
48
|
+
|
49
|
+
# ****************************************************************************
|
50
|
+
# Copyright (C) 2015 Volker Braun <vbraun.name@gmail.com>
|
51
|
+
#
|
52
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
53
|
+
# as published by the Free Software Foundation; either version 2 of
|
54
|
+
# the License, or (at your option) any later version.
|
55
|
+
# https://www.gnu.org/licenses/
|
56
|
+
# ****************************************************************************
|
57
|
+
from sage.structure.sage_object import SageObject
|
58
|
+
from sage.repl.rich_output import get_display_manager
|
59
|
+
|
60
|
+
|
61
|
+
class SequencePrettyPrinter(SageObject):
|
62
|
+
|
63
|
+
def __init__(self, *args, **kwds):
|
64
|
+
r"""
|
65
|
+
Pretty Printer for Multiple Arguments.
|
66
|
+
|
67
|
+
INPUT/OUTPUT:
|
68
|
+
|
69
|
+
Same as :func:`pretty_print`, except that the number of
|
70
|
+
arguments must be >= 2. Otherwise its not a sequence of things
|
71
|
+
to print.
|
72
|
+
|
73
|
+
EXAMPLES::
|
74
|
+
|
75
|
+
sage: pretty_print(1, 2, 3) # indirect doctest
|
76
|
+
1 2 3
|
77
|
+
sage: from sage.repl.rich_output.pretty_print import SequencePrettyPrinter
|
78
|
+
sage: SequencePrettyPrinter(1, 2, 3).pretty_print()
|
79
|
+
1 2 3
|
80
|
+
"""
|
81
|
+
self.args = args
|
82
|
+
assert len(self.args) >= 2
|
83
|
+
self.kwds = kwds
|
84
|
+
|
85
|
+
def is_homogeneous(self, common_type):
|
86
|
+
"""
|
87
|
+
Return whether the pretty print items are homogeneous.
|
88
|
+
|
89
|
+
INPUT:
|
90
|
+
|
91
|
+
- ``common_type`` -- a type
|
92
|
+
|
93
|
+
OUTPUT:
|
94
|
+
|
95
|
+
boolean; whether all items to be pretty printed are of said
|
96
|
+
type.
|
97
|
+
|
98
|
+
EXAMPLES::
|
99
|
+
|
100
|
+
sage: from sage.repl.rich_output.pretty_print import SequencePrettyPrinter
|
101
|
+
sage: seq = SequencePrettyPrinter(1, 2, 3)
|
102
|
+
sage: seq.is_homogeneous(Integer)
|
103
|
+
True
|
104
|
+
sage: seq.is_homogeneous(str)
|
105
|
+
False
|
106
|
+
"""
|
107
|
+
return all(isinstance(arg, common_type) for arg in self.args)
|
108
|
+
|
109
|
+
def _concatenate_graphs(self):
|
110
|
+
"""
|
111
|
+
Plot multiple graphs into a single plot.
|
112
|
+
|
113
|
+
OUTPUT: a graphics object
|
114
|
+
|
115
|
+
EXAMPLES::
|
116
|
+
|
117
|
+
sage: from sage.repl.rich_output.pretty_print import SequencePrettyPrinter
|
118
|
+
sage: plt = SequencePrettyPrinter(*list(graphs(3)))._concatenate_graphs() # needs sage.graphs sage.plot
|
119
|
+
sage: type(plt) # needs sage.graphs sage.plot
|
120
|
+
<class 'sage.plot.multigraphics.GraphicsArray'>
|
121
|
+
sage: plt # needs sage.graphs sage.plot
|
122
|
+
Graphics Array of size 1 x 4
|
123
|
+
"""
|
124
|
+
import sage.graphs.graph_list as graphs_list
|
125
|
+
return graphs_list.to_graphics_array(self.args, **self.kwds)
|
126
|
+
|
127
|
+
def _concatenate_graphics(self):
|
128
|
+
"""
|
129
|
+
Combine multiple graphics objects into one graphics array.
|
130
|
+
|
131
|
+
OUTPUT: a graphics array
|
132
|
+
|
133
|
+
EXAMPLES::
|
134
|
+
|
135
|
+
sage: from sage.repl.rich_output.pretty_print import SequencePrettyPrinter
|
136
|
+
sage: ga = SequencePrettyPrinter(*[Graphics()]*5)._concatenate_graphics() # needs sage.plot
|
137
|
+
sage: type(ga) # needs sage.plot
|
138
|
+
<class 'sage.plot.multigraphics.GraphicsArray'>
|
139
|
+
sage: ga.nrows(), ga.ncols() # needs sage.plot
|
140
|
+
(2, 4)
|
141
|
+
"""
|
142
|
+
from sage.plot.plot import graphics_array
|
143
|
+
return graphics_array(self.args, ncols=4, **self.kwds)
|
144
|
+
|
145
|
+
def pretty_print(self):
|
146
|
+
"""
|
147
|
+
Actually do the pretty print.
|
148
|
+
|
149
|
+
EXAMPLES::
|
150
|
+
|
151
|
+
sage: from sage.repl.rich_output.pretty_print import SequencePrettyPrinter
|
152
|
+
sage: SequencePrettyPrinter(1, 2, 3).pretty_print()
|
153
|
+
1 2 3
|
154
|
+
|
155
|
+
The keyword arguments are only used the first time graphics
|
156
|
+
output is generated::
|
157
|
+
|
158
|
+
sage: seq = SequencePrettyPrinter(Graph(), Graph(), edge_labels=True) # needs sage.graphs sage.plot
|
159
|
+
sage: seq.pretty_print() # does not pass edge_labels to graphics object # needs sage.graphs sage.plot
|
160
|
+
sage: seq._concatenate_graphs().show(edge_labels=True) # needs sage.graphs sage.plot
|
161
|
+
Traceback (most recent call last):
|
162
|
+
...
|
163
|
+
TypeError: ...matplotlib() got an unexpected keyword argument 'edge_labels'
|
164
|
+
"""
|
165
|
+
try:
|
166
|
+
from sage.plot.plot import Graphics
|
167
|
+
except ImportError:
|
168
|
+
Graphics = ()
|
169
|
+
try:
|
170
|
+
from sage.graphs.graph import GenericGraph
|
171
|
+
except ImportError:
|
172
|
+
GenericGraph = ()
|
173
|
+
if self.is_homogeneous(GenericGraph):
|
174
|
+
args = self._concatenate_graphs()
|
175
|
+
kwds = dict()
|
176
|
+
elif self.is_homogeneous(Graphics):
|
177
|
+
args = self._concatenate_graphics()
|
178
|
+
kwds = dict()
|
179
|
+
else:
|
180
|
+
args = self.args
|
181
|
+
kwds = dict(self.kwds)
|
182
|
+
kwds['concatenate'] = True
|
183
|
+
get_display_manager().display_immediately(args, **kwds)
|
184
|
+
|
185
|
+
|
186
|
+
def pretty_print(*args, **kwds):
|
187
|
+
r"""
|
188
|
+
Pretty print the arguments using rich output if available.
|
189
|
+
|
190
|
+
This function is similar to ``print()``, except that a rich output
|
191
|
+
representation such as ``ascii_art`` or Latex is printed instead of the
|
192
|
+
string representation.
|
193
|
+
|
194
|
+
Note that the output depends on the global display preferences specified
|
195
|
+
via
|
196
|
+
:meth:`~sage.repl.rich_output.display_manager.DisplayManager.preferences`.
|
197
|
+
If the display preference for ``text`` is not specified, Latex output is
|
198
|
+
preferred.
|
199
|
+
|
200
|
+
For graphical objects, a graphical output is used.
|
201
|
+
|
202
|
+
For certain homogeneous multiple positional arguments, a suitable
|
203
|
+
combined graphical output is generated. In particular, graphs and
|
204
|
+
plots are treated special. Otherwise this function concatenates the
|
205
|
+
textual representations.
|
206
|
+
|
207
|
+
INPUT:
|
208
|
+
|
209
|
+
- ``*args`` -- any number of positional arguments; the objects to
|
210
|
+
pretty print
|
211
|
+
|
212
|
+
- ``**kwds`` -- optional keyword arguments that are passed to the
|
213
|
+
rich representation. Examples include:
|
214
|
+
|
215
|
+
- ``dpi`` -- dots per inch
|
216
|
+
|
217
|
+
- ``figsize``- [width, height] (same for square aspect)
|
218
|
+
|
219
|
+
- ``axes`` -- (default: ``True``)
|
220
|
+
|
221
|
+
- ``fontsize`` -- positive integer
|
222
|
+
|
223
|
+
- ``frame`` -- boolean (default: ``False``); draw a MATLAB-like frame around
|
224
|
+
the image
|
225
|
+
|
226
|
+
EXAMPLES::
|
227
|
+
|
228
|
+
sage: pretty_print(ZZ)
|
229
|
+
Integer Ring
|
230
|
+
|
231
|
+
sage: pretty_print("Integers = ", ZZ) # trac 11775
|
232
|
+
'Integers = ' Integer Ring
|
233
|
+
|
234
|
+
To typeset LaTeX code as-is, use :class:`LatexExpr`::
|
235
|
+
|
236
|
+
sage: pretty_print(LatexExpr(r"\frac{x^2 + 1}{x - 2}"))
|
237
|
+
\frac{x^2 + 1}{x - 2}
|
238
|
+
|
239
|
+
For text-based backends, the default text display preference is to output
|
240
|
+
plain text which is usually the same as using ``print()``::
|
241
|
+
|
242
|
+
sage: pretty_print(x^2 / (x + 1)) # needs sage.symbolic
|
243
|
+
x^2/(x + 1)
|
244
|
+
|
245
|
+
sage: t = BinaryTrees(3).first() # needs sage.graphs
|
246
|
+
sage: pretty_print(t) # needs sage.graphs
|
247
|
+
[., [., [., .]]]
|
248
|
+
sage: print(t) # needs sage.graphs
|
249
|
+
[., [., [., .]]]
|
250
|
+
|
251
|
+
TESTS::
|
252
|
+
|
253
|
+
sage: dm = get_display_manager()
|
254
|
+
sage: dm.preferences.text = 'ascii_art'
|
255
|
+
|
256
|
+
EXAMPLES:
|
257
|
+
|
258
|
+
Changing the text display preference affects the output of this function.
|
259
|
+
The following illustrates a possible use-case::
|
260
|
+
|
261
|
+
sage: %display ascii_art # not tested
|
262
|
+
sage: for t in BinaryTrees(3)[:3]: # needs sage.graphs
|
263
|
+
....: pretty_print(t)
|
264
|
+
o
|
265
|
+
\
|
266
|
+
o
|
267
|
+
\
|
268
|
+
o
|
269
|
+
o
|
270
|
+
\
|
271
|
+
o
|
272
|
+
/
|
273
|
+
o
|
274
|
+
o
|
275
|
+
/ \
|
276
|
+
o o
|
277
|
+
|
278
|
+
sage: pretty_print(x^2 / (x + 1)) # needs sage.symbolic
|
279
|
+
2
|
280
|
+
x
|
281
|
+
-----
|
282
|
+
x + 1
|
283
|
+
|
284
|
+
TESTS:
|
285
|
+
|
286
|
+
After the previous example, we need to reset the text display preferences::
|
287
|
+
|
288
|
+
sage: dm.preferences.text = None
|
289
|
+
|
290
|
+
::
|
291
|
+
|
292
|
+
sage: # needs sage.plot sage.symbolic
|
293
|
+
sage: plt = plot(sin)
|
294
|
+
sage: pretty_print(plt) # graphics output
|
295
|
+
sage: pretty_print(plt, plt) # graphics output
|
296
|
+
sage: pretty_print(ZZ, 123, plt)
|
297
|
+
Integer Ring 123 Graphics object consisting of 1 graphics primitive
|
298
|
+
"""
|
299
|
+
dm = get_display_manager()
|
300
|
+
old_preferences_text = dm.preferences.text
|
301
|
+
try:
|
302
|
+
if dm.preferences.text is None:
|
303
|
+
dm.preferences.text = 'latex'
|
304
|
+
if len(args) == 0:
|
305
|
+
pass
|
306
|
+
elif len(args) == 1:
|
307
|
+
dm.display_immediately(*args, **kwds)
|
308
|
+
else:
|
309
|
+
SequencePrettyPrinter(*args, **kwds).pretty_print()
|
310
|
+
finally:
|
311
|
+
dm.preferences.text = old_preferences_text
|
312
|
+
|
313
|
+
|
314
|
+
def show(*args, **kwds):
|
315
|
+
r"""
|
316
|
+
Alias for ``pretty_print``.
|
317
|
+
|
318
|
+
This function is an alias for :func:`pretty_print`.
|
319
|
+
|
320
|
+
INPUT/OUTPUT:
|
321
|
+
|
322
|
+
See :func:`pretty_print`. Except if the argument is a graph, in
|
323
|
+
which case it is plotted instead.
|
324
|
+
|
325
|
+
EXAMPLES::
|
326
|
+
|
327
|
+
sage: show(1)
|
328
|
+
1
|
329
|
+
"""
|
330
|
+
try:
|
331
|
+
from sage.graphs.generic_graph import GenericGraph
|
332
|
+
except ImportError:
|
333
|
+
GenericGraph = ()
|
334
|
+
if len(args) == 1 and isinstance(args[0], GenericGraph):
|
335
|
+
# Graphs are special, they ride the short bus...
|
336
|
+
# Please, somebody help me get rid of this! #18289
|
337
|
+
args[0].show()
|
338
|
+
return
|
339
|
+
pretty_print(*args, **kwds)
|
@@ -0,0 +1,201 @@
|
|
1
|
+
# sage_setup: distribution = sagemath-repl
|
2
|
+
r"""
|
3
|
+
Test Backend
|
4
|
+
|
5
|
+
This backend is only for doctesting purposes.
|
6
|
+
|
7
|
+
EXAMPLES:
|
8
|
+
|
9
|
+
We switch to the test backend for the remainder of this file::
|
10
|
+
|
11
|
+
sage: from sage.repl.rich_output import get_display_manager
|
12
|
+
sage: dm = get_display_manager()
|
13
|
+
sage: from sage.repl.rich_output.test_backend import BackendTest, TestObject
|
14
|
+
sage: doctest_backend = dm.switch_backend(BackendTest())
|
15
|
+
sage: dm
|
16
|
+
The Sage display manager using the test backend
|
17
|
+
|
18
|
+
sage: dm._output_promotions
|
19
|
+
{<class 'sage.repl.rich_output.output_basic.OutputPlainText'>:
|
20
|
+
<class 'sage.repl.rich_output.test_backend.TestOutputPlainText'>}
|
21
|
+
sage: dm.displayhook(1/2)
|
22
|
+
1/2 [TestOutputPlainText]
|
23
|
+
TestOutputPlainText container
|
24
|
+
|
25
|
+
sage: test = TestObject()
|
26
|
+
sage: test
|
27
|
+
called the _repr_ method
|
28
|
+
sage: dm.displayhook(test)
|
29
|
+
called the _rich_repr_ method [TestOutputPlainText]
|
30
|
+
TestOutputPlainText container
|
31
|
+
"""
|
32
|
+
|
33
|
+
#*****************************************************************************
|
34
|
+
# Copyright (C) 2015 Volker Braun <vbraun.name@gmail.com>
|
35
|
+
#
|
36
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
37
|
+
# as published by the Free Software Foundation; either version 2 of
|
38
|
+
# the License, or (at your option) any later version.
|
39
|
+
# http://www.gnu.org/licenses/
|
40
|
+
#*****************************************************************************
|
41
|
+
|
42
|
+
|
43
|
+
from sage.structure.sage_object import SageObject
|
44
|
+
from sage.repl.rich_output.backend_base import BackendBase
|
45
|
+
from sage.repl.rich_output.output_catalog import OutputPlainText, OutputImagePng
|
46
|
+
|
47
|
+
|
48
|
+
class TestOutputPlainText(OutputPlainText):
|
49
|
+
|
50
|
+
def __init__(self, *args, **kwds):
|
51
|
+
"""
|
52
|
+
Backend-specific subclass of the plain text output container.
|
53
|
+
|
54
|
+
Backends must not influence how the display system constructs
|
55
|
+
output containers, they can only control how the output
|
56
|
+
container is displayed. In particular, we cannot override the
|
57
|
+
constructor (only the
|
58
|
+
:class:`~sage.repl.rich_output.output_basic.OutputPlainText`
|
59
|
+
constructor is used).
|
60
|
+
|
61
|
+
EXAMPLES::
|
62
|
+
|
63
|
+
sage: from sage.repl.rich_output.test_backend import TestOutputPlainText
|
64
|
+
sage: TestOutputPlainText()
|
65
|
+
Traceback (most recent call last):
|
66
|
+
...
|
67
|
+
AssertionError: cannot override constructor
|
68
|
+
"""
|
69
|
+
raise AssertionError('cannot override constructor')
|
70
|
+
|
71
|
+
def print_to_stdout(self):
|
72
|
+
"""
|
73
|
+
Write the data to stdout.
|
74
|
+
|
75
|
+
This is just a convenience method to help with debugging.
|
76
|
+
|
77
|
+
EXAMPLES::
|
78
|
+
|
79
|
+
sage: from sage.repl.rich_output import get_display_manager
|
80
|
+
sage: dm = get_display_manager()
|
81
|
+
sage: test_output = dm.displayhook(123)
|
82
|
+
123 [TestOutputPlainText]
|
83
|
+
sage: type(test_output)
|
84
|
+
<class 'sage.repl.rich_output.test_backend.TestOutputPlainText'>
|
85
|
+
sage: test_output.print_to_stdout()
|
86
|
+
123 [TestOutputPlainText]
|
87
|
+
"""
|
88
|
+
print('{0} [{1}]'.format(self.text.get_str(), self.__class__.__name__))
|
89
|
+
|
90
|
+
|
91
|
+
class TestObject(SageObject):
|
92
|
+
"""
|
93
|
+
Test object with both :meth:`_repr_` and :meth:`_rich_repr_`
|
94
|
+
"""
|
95
|
+
|
96
|
+
def _repr_(self):
|
97
|
+
"""
|
98
|
+
Return string representation.
|
99
|
+
|
100
|
+
OUTPUT: string
|
101
|
+
|
102
|
+
EXAMPLES::
|
103
|
+
|
104
|
+
sage: from sage.repl.rich_output.test_backend import TestObject
|
105
|
+
sage: obj = TestObject()
|
106
|
+
sage: obj._repr_()
|
107
|
+
'called the _repr_ method'
|
108
|
+
"""
|
109
|
+
return 'called the _repr_ method'
|
110
|
+
|
111
|
+
def _rich_repr_(self, display_manager):
|
112
|
+
"""
|
113
|
+
Rich Output Magic Method.
|
114
|
+
|
115
|
+
See :mod:`sage.repl.rich_output` for details.
|
116
|
+
|
117
|
+
EXAMPLES::
|
118
|
+
|
119
|
+
sage: display_manager = sage.repl.rich_output.get_display_manager()
|
120
|
+
sage: from sage.repl.rich_output.test_backend import TestObject
|
121
|
+
sage: obj = TestObject()
|
122
|
+
sage: rich_output = obj._rich_repr_(display_manager); rich_output
|
123
|
+
OutputPlainText container
|
124
|
+
sage: rich_output.text.get_str()
|
125
|
+
'called the _rich_repr_ method'
|
126
|
+
"""
|
127
|
+
tp = display_manager.types
|
128
|
+
if tp.OutputPlainText in display_manager.supported_output():
|
129
|
+
return tp.OutputPlainText('called the _rich_repr_ method')
|
130
|
+
|
131
|
+
|
132
|
+
class BackendTest(BackendBase):
|
133
|
+
|
134
|
+
def _repr_(self):
|
135
|
+
"""
|
136
|
+
Return the string representation.
|
137
|
+
|
138
|
+
OUTPUT: string
|
139
|
+
|
140
|
+
EXAMPLES::
|
141
|
+
|
142
|
+
sage: display_manager = sage.repl.rich_output.get_display_manager()
|
143
|
+
sage: backend = display_manager._backend
|
144
|
+
sage: backend._repr_()
|
145
|
+
'test'
|
146
|
+
"""
|
147
|
+
return 'test'
|
148
|
+
|
149
|
+
def supported_output(self):
|
150
|
+
"""
|
151
|
+
Return the outputs that are supported by the backend.
|
152
|
+
|
153
|
+
OUTPUT:
|
154
|
+
|
155
|
+
Iterable of output container classes. Only the
|
156
|
+
:class:`~sage.repl.rich_repr.test_backend.TestOutputPlainText`
|
157
|
+
output container is supported by the test backend.
|
158
|
+
|
159
|
+
EXAMPLES::
|
160
|
+
|
161
|
+
sage: display_manager = sage.repl.rich_output.get_display_manager()
|
162
|
+
sage: backend = display_manager._backend
|
163
|
+
sage: list(backend.supported_output())
|
164
|
+
[<class 'sage.repl.rich_output.test_backend.TestOutputPlainText'>]
|
165
|
+
|
166
|
+
The output of this method is used by the display manager to
|
167
|
+
set up the actual supported outputs. Compare::
|
168
|
+
|
169
|
+
sage: list(display_manager.supported_output())
|
170
|
+
[<class 'sage.repl.rich_output.output_basic.OutputPlainText'>]
|
171
|
+
"""
|
172
|
+
return set([TestOutputPlainText])
|
173
|
+
|
174
|
+
def display_immediately(self, plain_text, rich_output):
|
175
|
+
"""
|
176
|
+
Show output without going back to the command line prompt.
|
177
|
+
|
178
|
+
INPUT:
|
179
|
+
|
180
|
+
Same as :meth:`displayhook`.
|
181
|
+
|
182
|
+
OUTPUT:
|
183
|
+
|
184
|
+
This method returns the rich output for doctesting
|
185
|
+
convenience. The actual display framework ignores the return
|
186
|
+
value.
|
187
|
+
|
188
|
+
EXAMPLES::
|
189
|
+
|
190
|
+
sage: from sage.repl.rich_output.output_basic import OutputPlainText
|
191
|
+
sage: plain_text = OutputPlainText.example()
|
192
|
+
sage: from sage.repl.rich_output.test_backend import BackendTest
|
193
|
+
sage: backend = BackendTest()
|
194
|
+
sage: backend.display_immediately(plain_text, plain_text)
|
195
|
+
Example plain text output
|
196
|
+
OutputPlainText container
|
197
|
+
"""
|
198
|
+
plain_text.print_to_stdout()
|
199
|
+
if plain_text is not rich_output:
|
200
|
+
print('rich output type: [{0}]'.format(rich_output.__class__.__name__))
|
201
|
+
return rich_output
|