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,231 @@
|
|
1
|
+
# sage_setup: distribution = sagemath-repl
|
2
|
+
r"""
|
3
|
+
Video Output Types
|
4
|
+
|
5
|
+
This module defines the rich output types for video formats.
|
6
|
+
"""
|
7
|
+
# ****************************************************************************
|
8
|
+
# Copyright (C) 2015 Martin von Gagern <Martin.vGagern@gmx.net>
|
9
|
+
#
|
10
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
11
|
+
# as published by the Free Software Foundation; either version 2 of
|
12
|
+
# the License, or (at your option) any later version.
|
13
|
+
# https://www.gnu.org/licenses/
|
14
|
+
# ****************************************************************************
|
15
|
+
import importlib.resources
|
16
|
+
|
17
|
+
from sage.repl.rich_output.output_basic import OutputBase
|
18
|
+
from sage.repl.rich_output.buffer import OutputBuffer
|
19
|
+
|
20
|
+
|
21
|
+
class OutputVideoBase(OutputBase):
|
22
|
+
|
23
|
+
def __init__(self, video, loop=True):
|
24
|
+
"""
|
25
|
+
Abstract base class for rich video output.
|
26
|
+
|
27
|
+
INPUT:
|
28
|
+
|
29
|
+
- ``video`` -- :class:`~sage.repl.rich_output.buffer.OutputBuffer`;
|
30
|
+
the video data
|
31
|
+
- ``loop`` -- boolean; whether to repeat the video in an endless loop
|
32
|
+
|
33
|
+
EXAMPLES::
|
34
|
+
|
35
|
+
sage: from sage.repl.rich_output.output_catalog import OutputVideoOgg
|
36
|
+
sage: OutputVideoOgg.example() # indirect doctest
|
37
|
+
OutputVideoOgg container
|
38
|
+
"""
|
39
|
+
assert isinstance(video, OutputBuffer)
|
40
|
+
self.video = video
|
41
|
+
self.loop = loop
|
42
|
+
|
43
|
+
@classmethod
|
44
|
+
def example(cls):
|
45
|
+
r"""
|
46
|
+
Construct a sample video output container.
|
47
|
+
|
48
|
+
This static method is meant for doctests, so they can easily
|
49
|
+
construct an example. The method is implemented in the abstract
|
50
|
+
:class:`OutputVideoBase` class, but should get invoked on a
|
51
|
+
concrete subclass for which an actual example can exist.
|
52
|
+
|
53
|
+
OUTPUT: an instance of the class on which this method is called
|
54
|
+
|
55
|
+
EXAMPLES::
|
56
|
+
|
57
|
+
sage: from sage.repl.rich_output.output_catalog import OutputVideoOgg
|
58
|
+
sage: OutputVideoOgg.example()
|
59
|
+
OutputVideoOgg container
|
60
|
+
sage: OutputVideoOgg.example().video
|
61
|
+
buffer containing 5612 bytes
|
62
|
+
sage: OutputVideoOgg.example().ext
|
63
|
+
'.ogv'
|
64
|
+
sage: OutputVideoOgg.example().mimetype
|
65
|
+
'video/ogg'
|
66
|
+
"""
|
67
|
+
with importlib.resources.path(__package__, 'example' + cls.ext) as filename:
|
68
|
+
return cls(OutputBuffer.from_file(filename),
|
69
|
+
{'controls': True, 'loop': False})
|
70
|
+
|
71
|
+
def html_fragment(self, url, link_attrs=''):
|
72
|
+
r"""
|
73
|
+
Construct a HTML fragment for embedding this video.
|
74
|
+
|
75
|
+
INPUT:
|
76
|
+
|
77
|
+
- ``url`` -- string; the URL where the data of this video can be found
|
78
|
+
|
79
|
+
- ``link_attrs`` -- string; can be used to style the fallback link
|
80
|
+
which is presented to the user if the video is not supported
|
81
|
+
|
82
|
+
EXAMPLES::
|
83
|
+
|
84
|
+
sage: from sage.repl.rich_output.output_catalog import OutputVideoOgg
|
85
|
+
sage: print(OutputVideoOgg.example().html_fragment
|
86
|
+
....: ('foo', 'class="bar"').replace('><','>\n<'))
|
87
|
+
<video autoplay="autoplay" controls="controls" loop="loop">
|
88
|
+
<source src="foo" type="video/ogg" />
|
89
|
+
<p>
|
90
|
+
<a target="_new" href="foo" class="bar">Download video/ogg video</a>
|
91
|
+
</p>
|
92
|
+
</video>
|
93
|
+
"""
|
94
|
+
attrs = {
|
95
|
+
'autoplay': 'autoplay',
|
96
|
+
'controls': 'controls',
|
97
|
+
}
|
98
|
+
if self.loop:
|
99
|
+
attrs['loop'] = 'loop'
|
100
|
+
attrs = ''.join(' {}="{}"'.format(k, v)
|
101
|
+
for k, v in sorted(attrs.items()))
|
102
|
+
txt = ('<video{attrs}>'
|
103
|
+
'<source src="{url}" type="{mimetype}" /><p>'
|
104
|
+
'<a target="_new" href="{url}" {link_attrs}>'
|
105
|
+
'Download {mimetype} video</a></p></video>')
|
106
|
+
return txt.format(url=url,
|
107
|
+
mimetype=self.mimetype,
|
108
|
+
attrs=attrs,
|
109
|
+
link_attrs=link_attrs)
|
110
|
+
|
111
|
+
|
112
|
+
class OutputVideoOgg(OutputVideoBase):
|
113
|
+
"""
|
114
|
+
Ogg video, Ogg Theora in particular.
|
115
|
+
|
116
|
+
EXAMPLES::
|
117
|
+
|
118
|
+
sage: from sage.repl.rich_output.output_catalog import OutputVideoOgg
|
119
|
+
sage: OutputVideoOgg.example()
|
120
|
+
OutputVideoOgg container
|
121
|
+
"""
|
122
|
+
|
123
|
+
ext = ".ogv"
|
124
|
+
mimetype = "video/ogg"
|
125
|
+
|
126
|
+
|
127
|
+
class OutputVideoWebM(OutputVideoBase):
|
128
|
+
"""
|
129
|
+
WebM video.
|
130
|
+
|
131
|
+
The video can be encoded using VP8, VP9 or an even more recent codec.
|
132
|
+
|
133
|
+
EXAMPLES::
|
134
|
+
|
135
|
+
sage: from sage.repl.rich_output.output_catalog import OutputVideoWebM
|
136
|
+
sage: OutputVideoWebM.example()
|
137
|
+
OutputVideoWebM container
|
138
|
+
"""
|
139
|
+
|
140
|
+
ext = ".webm"
|
141
|
+
mimetype = "video/webm"
|
142
|
+
|
143
|
+
|
144
|
+
class OutputVideoMp4(OutputVideoBase):
|
145
|
+
"""
|
146
|
+
MPEG 4 video.
|
147
|
+
|
148
|
+
EXAMPLES::
|
149
|
+
|
150
|
+
sage: from sage.repl.rich_output.output_catalog import OutputVideoMp4
|
151
|
+
sage: OutputVideoMp4.example()
|
152
|
+
OutputVideoMp4 container
|
153
|
+
"""
|
154
|
+
|
155
|
+
ext = ".mp4"
|
156
|
+
mimetype = "video/mp4"
|
157
|
+
|
158
|
+
|
159
|
+
class OutputVideoFlash(OutputVideoBase):
|
160
|
+
"""
|
161
|
+
Flash video.
|
162
|
+
|
163
|
+
EXAMPLES::
|
164
|
+
|
165
|
+
sage: from sage.repl.rich_output.output_catalog import OutputVideoFlash
|
166
|
+
sage: OutputVideoFlash.example()
|
167
|
+
OutputVideoFlash container
|
168
|
+
"""
|
169
|
+
|
170
|
+
ext = ".flv"
|
171
|
+
mimetype = "video/x-flv"
|
172
|
+
|
173
|
+
|
174
|
+
class OutputVideoMatroska(OutputVideoBase):
|
175
|
+
"""
|
176
|
+
Matroska Video.
|
177
|
+
|
178
|
+
EXAMPLES::
|
179
|
+
|
180
|
+
sage: from sage.repl.rich_output.output_catalog import OutputVideoMatroska
|
181
|
+
sage: OutputVideoMatroska.example()
|
182
|
+
OutputVideoMatroska container
|
183
|
+
"""
|
184
|
+
|
185
|
+
ext = ".mkv"
|
186
|
+
mimetype = "video/x-matroska"
|
187
|
+
|
188
|
+
|
189
|
+
class OutputVideoAvi(OutputVideoBase):
|
190
|
+
"""
|
191
|
+
AVI video.
|
192
|
+
|
193
|
+
EXAMPLES::
|
194
|
+
|
195
|
+
sage: from sage.repl.rich_output.output_catalog import OutputVideoAvi
|
196
|
+
sage: OutputVideoAvi.example()
|
197
|
+
OutputVideoAvi container
|
198
|
+
"""
|
199
|
+
|
200
|
+
ext = ".avi"
|
201
|
+
mimetype = "video/x-msvideo"
|
202
|
+
|
203
|
+
|
204
|
+
class OutputVideoWmv(OutputVideoBase):
|
205
|
+
"""
|
206
|
+
Windows Media Video.
|
207
|
+
|
208
|
+
EXAMPLES::
|
209
|
+
|
210
|
+
sage: from sage.repl.rich_output.output_catalog import OutputVideoWmv
|
211
|
+
sage: OutputVideoWmv.example()
|
212
|
+
OutputVideoWmv container
|
213
|
+
"""
|
214
|
+
|
215
|
+
ext = ".wmv"
|
216
|
+
mimetype = "video/x-ms-wmv"
|
217
|
+
|
218
|
+
|
219
|
+
class OutputVideoQuicktime(OutputVideoBase):
|
220
|
+
"""
|
221
|
+
Quicktime video.
|
222
|
+
|
223
|
+
EXAMPLES::
|
224
|
+
|
225
|
+
sage: from sage.repl.rich_output.output_catalog import OutputVideoQuicktime
|
226
|
+
sage: OutputVideoQuicktime.example()
|
227
|
+
OutputVideoQuicktime container
|
228
|
+
"""
|
229
|
+
|
230
|
+
ext = ".mov"
|
231
|
+
mimetype = "video/quicktime"
|
@@ -0,0 +1,432 @@
|
|
1
|
+
# sage_setup: distribution = sagemath-repl
|
2
|
+
r"""
|
3
|
+
Display Preferences
|
4
|
+
|
5
|
+
This class is used to express display preferences that are not simply
|
6
|
+
a choice of a particular output format. For example, whether to prefer
|
7
|
+
vector over raster graphics. By convention, the value ``None`` is
|
8
|
+
always a valid value for a preference and means no particular
|
9
|
+
preference.
|
10
|
+
|
11
|
+
EXAMPLES::
|
12
|
+
|
13
|
+
sage: from sage.repl.rich_output.preferences import DisplayPreferences
|
14
|
+
sage: prefs = DisplayPreferences()
|
15
|
+
sage: prefs.available_options()
|
16
|
+
(align_latex, graphics, supplemental_plot, text)
|
17
|
+
sage: prefs.text is None
|
18
|
+
True
|
19
|
+
sage: prefs.text = 'ascii_art'
|
20
|
+
sage: prefs.text
|
21
|
+
'ascii_art'
|
22
|
+
sage: prefs
|
23
|
+
Display preferences:
|
24
|
+
* align_latex is not specified
|
25
|
+
* graphics is not specified
|
26
|
+
* supplemental_plot is not specified
|
27
|
+
* text = ascii_art
|
28
|
+
|
29
|
+
Properties can be unset by deleting them or by assigning ``None``::
|
30
|
+
|
31
|
+
sage: prefs.text = 'ascii_art'
|
32
|
+
sage: del prefs.text
|
33
|
+
sage: prefs.text is None
|
34
|
+
True
|
35
|
+
|
36
|
+
sage: prefs.text = 'ascii_art'
|
37
|
+
sage: prefs.text = None
|
38
|
+
sage: prefs.text is None
|
39
|
+
True
|
40
|
+
|
41
|
+
Properties have documentation attached::
|
42
|
+
|
43
|
+
sage: import pydoc
|
44
|
+
sage: doc = pydoc.render_doc(prefs)
|
45
|
+
sage: assert ' graphics' in doc
|
46
|
+
sage: assert ' Preferred graphics format' in doc
|
47
|
+
sage: assert ' text' in doc
|
48
|
+
sage: assert ' Which textual representation is preferred' in doc
|
49
|
+
|
50
|
+
Values can also be specified as keyword arguments to the constructor::
|
51
|
+
|
52
|
+
sage: DisplayPreferences(text='latex')
|
53
|
+
Display preferences:
|
54
|
+
* align_latex is not specified
|
55
|
+
* graphics is not specified
|
56
|
+
* supplemental_plot is not specified
|
57
|
+
* text = latex
|
58
|
+
|
59
|
+
.. TODO::
|
60
|
+
|
61
|
+
A value-checking preference system should be used elsewhere in
|
62
|
+
Sage, too. The class here is just a simple implementation, a
|
63
|
+
proper implementation would use a metaclass to construct the
|
64
|
+
preference items.
|
65
|
+
"""
|
66
|
+
|
67
|
+
# ****************************************************************************
|
68
|
+
# Copyright (C) 2015 Volker Braun <vbraun.name@gmail.com>
|
69
|
+
#
|
70
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
71
|
+
# as published by the Free Software Foundation; either version 2 of
|
72
|
+
# the License, or (at your option) any later version.
|
73
|
+
# https://www.gnu.org/licenses/
|
74
|
+
# ****************************************************************************
|
75
|
+
|
76
|
+
|
77
|
+
from textwrap import dedent
|
78
|
+
|
79
|
+
from sage.structure.sage_object import SageObject
|
80
|
+
|
81
|
+
|
82
|
+
class Property(property):
|
83
|
+
|
84
|
+
def __init__(self, name, allowed_values, doc=None):
|
85
|
+
r"""
|
86
|
+
Preference item.
|
87
|
+
|
88
|
+
INPUT:
|
89
|
+
|
90
|
+
- ``name`` -- string; the name of the property
|
91
|
+
|
92
|
+
- ``allowed_values`` -- list/tuple/iterable of allowed values
|
93
|
+
|
94
|
+
- ``doc`` -- string (optional); the docstring of the property
|
95
|
+
|
96
|
+
EXAMPLES::
|
97
|
+
|
98
|
+
sage: from sage.repl.rich_output.preferences import Property
|
99
|
+
sage: prop = Property('foo', [0, 1, 2], 'The Foo Property')
|
100
|
+
sage: prop.__doc__
|
101
|
+
'The Foo Property\n\nAllowed values:\n\n* ``None`` (default): no preference\n\n* 0\n\n* 1\n\n* 2'
|
102
|
+
sage: prop.allowed_values
|
103
|
+
(0, 1, 2)
|
104
|
+
"""
|
105
|
+
self.name = name
|
106
|
+
self.underscore_name = '_{0}'.format(name)
|
107
|
+
self.allowed_values = tuple(allowed_values)
|
108
|
+
self.__doc__ = doc = self._make_doc(doc)
|
109
|
+
super().__init__(fget=self.getter, fset=self.setter,
|
110
|
+
fdel=self.deleter, doc=doc)
|
111
|
+
|
112
|
+
def _make_doc(self, doc):
|
113
|
+
"""
|
114
|
+
Generate the documentation.
|
115
|
+
|
116
|
+
INPUT:
|
117
|
+
|
118
|
+
- ``doc`` -- the title line of the documentation
|
119
|
+
|
120
|
+
OUTPUT:
|
121
|
+
|
122
|
+
string; the docstring with auto-generated documentation about
|
123
|
+
the allowed values added
|
124
|
+
|
125
|
+
EXAMPLES::
|
126
|
+
|
127
|
+
sage: from sage.repl.rich_output.preferences import Property
|
128
|
+
sage: prop = Property('foo', [0, 1, 2], 'The Foo Property')
|
129
|
+
sage: print(prop._make_doc('this is the title'))
|
130
|
+
this is the title
|
131
|
+
<BLANKLINE>
|
132
|
+
Allowed values:
|
133
|
+
<BLANKLINE>
|
134
|
+
* ``None`` (default): no preference
|
135
|
+
<BLANKLINE>
|
136
|
+
* 0
|
137
|
+
<BLANKLINE>
|
138
|
+
* 1
|
139
|
+
<BLANKLINE>
|
140
|
+
* 2
|
141
|
+
"""
|
142
|
+
doc = dedent(doc)
|
143
|
+
doc += '\n\n'
|
144
|
+
doc += 'Allowed values:\n\n'
|
145
|
+
values_doc = ['* ``None`` (default): no preference']
|
146
|
+
values_doc.extend('* {0}'.format(repr(value))
|
147
|
+
for value in self.allowed_values)
|
148
|
+
return doc + '\n\n'.join(values_doc)
|
149
|
+
|
150
|
+
def __repr__(self):
|
151
|
+
"""
|
152
|
+
Return a string representation.
|
153
|
+
|
154
|
+
OUTPUT: string
|
155
|
+
|
156
|
+
EXAMPLES::
|
157
|
+
|
158
|
+
sage: from sage.repl.rich_output.preferences import Property
|
159
|
+
sage: prop = Property('foo', [0, 1, 2], 'The Foo Property')
|
160
|
+
sage: prop.__repr__()
|
161
|
+
'foo'
|
162
|
+
"""
|
163
|
+
return self.name
|
164
|
+
|
165
|
+
def getter(self, prefs):
|
166
|
+
"""
|
167
|
+
Get the current value of the property.
|
168
|
+
|
169
|
+
INPUT:
|
170
|
+
|
171
|
+
- ``prefs`` -- the :class:`PreferencesABC` instance that the
|
172
|
+
property is bound to
|
173
|
+
|
174
|
+
OUTPUT: one of the allowed values or ``None`` if not set
|
175
|
+
|
176
|
+
EXAMPLES::
|
177
|
+
|
178
|
+
sage: from sage.repl.rich_output.preferences import Property, PreferencesABC
|
179
|
+
sage: prop = Property('foo', [0, 1, 2], 'The Foo Property')
|
180
|
+
sage: prefs = PreferencesABC()
|
181
|
+
sage: prop.getter(prefs) is None
|
182
|
+
True
|
183
|
+
sage: prop.setter(prefs, 1)
|
184
|
+
sage: prop.getter(prefs)
|
185
|
+
1
|
186
|
+
"""
|
187
|
+
try:
|
188
|
+
return getattr(prefs, self.underscore_name)
|
189
|
+
except AttributeError:
|
190
|
+
return None
|
191
|
+
|
192
|
+
def setter(self, prefs, value):
|
193
|
+
"""
|
194
|
+
Get the current value of the property.
|
195
|
+
|
196
|
+
INPUT:
|
197
|
+
|
198
|
+
- ``prefs`` -- the :class:`PreferencesABC` instance that the
|
199
|
+
property is bound to
|
200
|
+
|
201
|
+
- ``value`` -- anything. The new value of the
|
202
|
+
property. Setting a property to ``None`` is equivalent to
|
203
|
+
deleting the value.
|
204
|
+
|
205
|
+
OUTPUT:
|
206
|
+
|
207
|
+
This method does not return anything. A :exc:`ValueError` is
|
208
|
+
raised if the given ``value`` is not one of the allowed
|
209
|
+
values.
|
210
|
+
|
211
|
+
EXAMPLES::
|
212
|
+
|
213
|
+
sage: from sage.repl.rich_output.preferences import Property, PreferencesABC
|
214
|
+
sage: prop = Property('foo', [0, 1, 2], 'The Foo Property')
|
215
|
+
sage: prefs = PreferencesABC()
|
216
|
+
sage: prop.getter(prefs) is None
|
217
|
+
True
|
218
|
+
sage: prop.setter(prefs, 1)
|
219
|
+
sage: prop.getter(prefs)
|
220
|
+
1
|
221
|
+
|
222
|
+
sage: prop.setter(prefs, None)
|
223
|
+
sage: prop.getter(prefs) is None
|
224
|
+
True
|
225
|
+
"""
|
226
|
+
if value is None:
|
227
|
+
return self.deleter(prefs)
|
228
|
+
allowed = self.allowed_values
|
229
|
+
if value not in allowed:
|
230
|
+
raise ValueError('value must be unset (None) or one of {0}, got {1}'
|
231
|
+
.format(allowed, value))
|
232
|
+
setattr(prefs, self.underscore_name, value)
|
233
|
+
|
234
|
+
def deleter(self, prefs):
|
235
|
+
"""
|
236
|
+
Delete the current value of the property.
|
237
|
+
|
238
|
+
INPUT:
|
239
|
+
|
240
|
+
- ``prefs`` -- the :class:`PreferencesABC` instance that the
|
241
|
+
property is bound to
|
242
|
+
|
243
|
+
EXAMPLES::
|
244
|
+
|
245
|
+
sage: from sage.repl.rich_output.preferences import Property, PreferencesABC
|
246
|
+
sage: prop = Property('foo', [0, 1, 2], 'The Foo Property')
|
247
|
+
sage: prefs = PreferencesABC()
|
248
|
+
sage: prop.getter(prefs) is None
|
249
|
+
True
|
250
|
+
sage: prop.setter(prefs, 1)
|
251
|
+
sage: prop.deleter(prefs)
|
252
|
+
sage: prop.getter(prefs) is None
|
253
|
+
True
|
254
|
+
"""
|
255
|
+
underscore_name = self.underscore_name
|
256
|
+
try:
|
257
|
+
delattr(prefs, underscore_name)
|
258
|
+
except AttributeError:
|
259
|
+
pass
|
260
|
+
|
261
|
+
|
262
|
+
class PreferencesABC(SageObject):
|
263
|
+
|
264
|
+
def __init__(self, *args, **kwds):
|
265
|
+
"""
|
266
|
+
Preferences for displaying graphics.
|
267
|
+
|
268
|
+
These can be preferences expressed by the user or by the
|
269
|
+
display backend. They are specified as keyword arguments.
|
270
|
+
|
271
|
+
INPUT:
|
272
|
+
|
273
|
+
- ``*args*`` -- positional arguments are preferences
|
274
|
+
instances. The property values will be inherited from left
|
275
|
+
to right, that is, later parents override values from
|
276
|
+
earlier parents.
|
277
|
+
|
278
|
+
- ``**kwds`` -- keyword arguments; will be used to initialize
|
279
|
+
properties, and override inherited values if necessary
|
280
|
+
|
281
|
+
EXAMPLES::
|
282
|
+
|
283
|
+
sage: from sage.repl.rich_output.preferences import DisplayPreferences
|
284
|
+
sage: p1 = DisplayPreferences(graphics='vector')
|
285
|
+
sage: p2 = DisplayPreferences(graphics='raster')
|
286
|
+
sage: DisplayPreferences(p1, p2)
|
287
|
+
Display preferences:
|
288
|
+
* align_latex is not specified
|
289
|
+
* graphics = raster
|
290
|
+
* supplemental_plot is not specified
|
291
|
+
* text is not specified
|
292
|
+
|
293
|
+
If specified in the opposite order, the setting from ``p1`` is
|
294
|
+
inherited::
|
295
|
+
|
296
|
+
sage: DisplayPreferences(p2, p1)
|
297
|
+
Display preferences:
|
298
|
+
* align_latex is not specified
|
299
|
+
* graphics = vector
|
300
|
+
* supplemental_plot is not specified
|
301
|
+
* text is not specified
|
302
|
+
|
303
|
+
Further keywords override::
|
304
|
+
|
305
|
+
sage: DisplayPreferences(p2, p1, graphics='disable')
|
306
|
+
Display preferences:
|
307
|
+
* align_latex is not specified
|
308
|
+
* graphics = disable
|
309
|
+
* supplemental_plot is not specified
|
310
|
+
* text is not specified
|
311
|
+
"""
|
312
|
+
for parent in args:
|
313
|
+
for option in self.available_options():
|
314
|
+
value = option.getter(parent)
|
315
|
+
if value is not None:
|
316
|
+
option.setter(self, value)
|
317
|
+
for key, value in kwds.items():
|
318
|
+
setattr(self, key, value)
|
319
|
+
|
320
|
+
@classmethod
|
321
|
+
def _add_option(cls, name, values, doc):
|
322
|
+
"""
|
323
|
+
Add an option to the preferences system.
|
324
|
+
|
325
|
+
This method should only be called during the import of
|
326
|
+
:mod:`sage.repl.rich_output.preferences`.
|
327
|
+
|
328
|
+
INPUT:
|
329
|
+
|
330
|
+
- ``name`` -- the name of the option
|
331
|
+
|
332
|
+
- ``values`` -- the allowed values
|
333
|
+
|
334
|
+
- ``doc`` -- docstring
|
335
|
+
|
336
|
+
EXAMPLES::
|
337
|
+
|
338
|
+
sage: from sage.repl.rich_output.preferences import PreferencesABC
|
339
|
+
sage: class MyPrefs(PreferencesABC):
|
340
|
+
....: pass
|
341
|
+
sage: MyPrefs._add_option('foo', [0, 1, 2], 'The Foo Option')
|
342
|
+
sage: prefs = MyPrefs()
|
343
|
+
sage: prefs.foo
|
344
|
+
sage: prefs.foo = 0
|
345
|
+
sage: prefs.foo
|
346
|
+
0
|
347
|
+
"""
|
348
|
+
prop = Property(name, values, doc)
|
349
|
+
setattr(cls, name, prop)
|
350
|
+
|
351
|
+
def available_options(self):
|
352
|
+
"""
|
353
|
+
Return the available options.
|
354
|
+
|
355
|
+
OUTPUT:
|
356
|
+
|
357
|
+
tuple of the preference items as instances of :class:`Property`
|
358
|
+
|
359
|
+
EXAMPLES::
|
360
|
+
|
361
|
+
sage: from sage.repl.rich_output.preferences import DisplayPreferences
|
362
|
+
sage: DisplayPreferences().available_options()
|
363
|
+
(align_latex, graphics, supplemental_plot, text)
|
364
|
+
"""
|
365
|
+
options = []
|
366
|
+
for value in self.__class__.__dict__.values():
|
367
|
+
if isinstance(value, Property):
|
368
|
+
options.append(value)
|
369
|
+
return tuple(sorted(options, key=str))
|
370
|
+
|
371
|
+
def _repr_(self):
|
372
|
+
r"""
|
373
|
+
Return a string representation.
|
374
|
+
|
375
|
+
OUTPUT: string
|
376
|
+
|
377
|
+
EXAMPLES::
|
378
|
+
|
379
|
+
sage: from sage.repl.rich_output.preferences import DisplayPreferences
|
380
|
+
sage: DisplayPreferences()._repr_()
|
381
|
+
'Display preferences:\n* align_latex is not specified\n* graphics is not specified\n* supplemental_plot is not specified\n* text is not specified'
|
382
|
+
"""
|
383
|
+
s = ['Display preferences:']
|
384
|
+
for opt in self.available_options():
|
385
|
+
value = opt.getter(self)
|
386
|
+
if value is None:
|
387
|
+
s += ['* {0} is not specified'.format(opt.name)]
|
388
|
+
else:
|
389
|
+
s += ['* {0} = {1}'.format(opt.name, value)]
|
390
|
+
return '\n'.join(s)
|
391
|
+
|
392
|
+
|
393
|
+
class DisplayPreferences(PreferencesABC):
|
394
|
+
pass
|
395
|
+
|
396
|
+
|
397
|
+
DisplayPreferences._add_option(
|
398
|
+
'text',
|
399
|
+
('plain', 'ascii_art', 'unicode_art', 'latex'),
|
400
|
+
"""
|
401
|
+
Which textual representation is preferred
|
402
|
+
"""
|
403
|
+
)
|
404
|
+
|
405
|
+
|
406
|
+
DisplayPreferences._add_option(
|
407
|
+
'align_latex',
|
408
|
+
('center', 'left'),
|
409
|
+
"""
|
410
|
+
Preferred mode of latex displays
|
411
|
+
"""
|
412
|
+
)
|
413
|
+
|
414
|
+
|
415
|
+
DisplayPreferences._add_option(
|
416
|
+
'graphics',
|
417
|
+
('disable', 'vector', 'raster'),
|
418
|
+
"""
|
419
|
+
Preferred graphics format
|
420
|
+
"""
|
421
|
+
)
|
422
|
+
|
423
|
+
|
424
|
+
DisplayPreferences._add_option(
|
425
|
+
'supplemental_plot',
|
426
|
+
('always', 'never'),
|
427
|
+
"""
|
428
|
+
Whether to graphically display graphs and other graph-like objects
|
429
|
+
that implement rich output. When not specified small objects are
|
430
|
+
show graphically and large objects as textual overview.
|
431
|
+
"""
|
432
|
+
)
|