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,311 @@
|
|
1
|
+
# sage_setup: distribution = sagemath-repl
|
2
|
+
r"""
|
3
|
+
Output Buffer
|
4
|
+
|
5
|
+
This is the fundamental unit of rich output, a single immutable buffer
|
6
|
+
(either in-memory or as a file). Rich output always consists of one or
|
7
|
+
more buffers. Ideally, the Sage library always uses the buffer object
|
8
|
+
as an in-memory buffer. But you can also ask it for a filename, and it
|
9
|
+
will save the data to a file if necessary. Either way, the buffer
|
10
|
+
object presents the same interface for getting the content of an
|
11
|
+
in-memory buffer or a temporary file. So any rich output backends do
|
12
|
+
not need to know where the buffer content is actually stored.
|
13
|
+
|
14
|
+
EXAMPLES::
|
15
|
+
|
16
|
+
sage: from sage.repl.rich_output.buffer import OutputBuffer
|
17
|
+
sage: buf = OutputBuffer('this is the buffer content'); buf
|
18
|
+
buffer containing 26 bytes
|
19
|
+
sage: buf.get().decode('ascii')
|
20
|
+
'this is the buffer content'
|
21
|
+
sage: type(buf.get()) is bytes
|
22
|
+
True
|
23
|
+
"""
|
24
|
+
# ****************************************************************************
|
25
|
+
# Copyright (C) 2015 Volker Braun <vbraun.name@gmail.com>
|
26
|
+
#
|
27
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
28
|
+
# as published by the Free Software Foundation; either version 2 of
|
29
|
+
# the License, or (at your option) any later version.
|
30
|
+
# https://www.gnu.org/licenses/
|
31
|
+
# ****************************************************************************
|
32
|
+
|
33
|
+
|
34
|
+
import os
|
35
|
+
from sage.structure.sage_object import SageObject
|
36
|
+
|
37
|
+
|
38
|
+
class OutputBuffer(SageObject):
|
39
|
+
|
40
|
+
def __init__(self, data):
|
41
|
+
"""
|
42
|
+
Data stored either in memory or as a file.
|
43
|
+
|
44
|
+
This class is an abstraction for "files", in that they can
|
45
|
+
either be defined by a bytes array (Python 3) or string
|
46
|
+
(Python 2) or by a file (see :meth:`from_file`).
|
47
|
+
|
48
|
+
INPUT:
|
49
|
+
|
50
|
+
- ``data`` -- bytes; the data that is stored in the buffer
|
51
|
+
|
52
|
+
EXAMPLES::
|
53
|
+
|
54
|
+
sage: from sage.repl.rich_output.buffer import OutputBuffer
|
55
|
+
sage: buf = OutputBuffer('this is the buffer content'); buf
|
56
|
+
buffer containing 26 bytes
|
57
|
+
|
58
|
+
sage: buf2 = OutputBuffer(buf); buf2
|
59
|
+
buffer containing 26 bytes
|
60
|
+
|
61
|
+
sage: buf.get_str()
|
62
|
+
'this is the buffer content'
|
63
|
+
sage: buf.filename(ext='.txt')
|
64
|
+
'/....txt'
|
65
|
+
"""
|
66
|
+
if isinstance(data, OutputBuffer):
|
67
|
+
self._filename = data._filename
|
68
|
+
self._data = data._data
|
69
|
+
else:
|
70
|
+
self._filename = None
|
71
|
+
if not isinstance(data, bytes):
|
72
|
+
self._data = data.encode('utf-8')
|
73
|
+
else:
|
74
|
+
self._data = data
|
75
|
+
|
76
|
+
@classmethod
|
77
|
+
def from_file(cls, filename):
|
78
|
+
"""
|
79
|
+
Construct buffer from data in file.
|
80
|
+
|
81
|
+
.. WARNING::
|
82
|
+
|
83
|
+
The buffer assumes that the file content remains the same
|
84
|
+
during the lifetime of the Sage session. To communicate
|
85
|
+
this to the user, the file permissions will be changed to
|
86
|
+
read only.
|
87
|
+
|
88
|
+
INPUT:
|
89
|
+
|
90
|
+
- ``filename`` -- string; the filename under which the data is
|
91
|
+
stored
|
92
|
+
|
93
|
+
OUTPUT: string containing the buffer data
|
94
|
+
|
95
|
+
EXAMPLES::
|
96
|
+
|
97
|
+
sage: from sage.repl.rich_output.buffer import OutputBuffer
|
98
|
+
sage: name = sage.misc.temporary_file.tmp_filename()
|
99
|
+
sage: with open(name, 'wb') as f:
|
100
|
+
....: _ = f.write(b'file content')
|
101
|
+
sage: buf = OutputBuffer.from_file(name); buf
|
102
|
+
buffer containing 12 bytes
|
103
|
+
|
104
|
+
sage: buf.filename() == name
|
105
|
+
True
|
106
|
+
sage: buf.get_str()
|
107
|
+
'file content'
|
108
|
+
"""
|
109
|
+
buf = cls.__new__(cls)
|
110
|
+
buf._filename = filename
|
111
|
+
buf._data = None
|
112
|
+
buf._chmod_readonly(buf._filename)
|
113
|
+
return buf
|
114
|
+
|
115
|
+
@classmethod
|
116
|
+
def _chmod_readonly(cls, filename):
|
117
|
+
"""
|
118
|
+
Make file readonly.
|
119
|
+
|
120
|
+
INPUT:
|
121
|
+
|
122
|
+
- ``filename`` -- string; name of an already-existing file
|
123
|
+
|
124
|
+
EXAMPLES::
|
125
|
+
|
126
|
+
sage: from sage.repl.rich_output.buffer import OutputBuffer
|
127
|
+
sage: tmp = sage.misc.temporary_file.tmp_filename()
|
128
|
+
sage: with open(tmp, 'wb') as f:
|
129
|
+
....: _ = f.write(b'file content')
|
130
|
+
sage: OutputBuffer._chmod_readonly(tmp)
|
131
|
+
sage: import os, stat
|
132
|
+
sage: stat.S_IMODE(os.stat(tmp).st_mode) & (stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH)
|
133
|
+
0
|
134
|
+
"""
|
135
|
+
from sage.env import SAGE_SRC
|
136
|
+
filename = os.path.abspath(filename)
|
137
|
+
if filename.startswith(os.path.abspath(SAGE_SRC)):
|
138
|
+
# Do not change permissions on the sample rich output
|
139
|
+
# files, as it will cause trouble when upgrading Sage
|
140
|
+
return
|
141
|
+
import stat
|
142
|
+
mode = os.stat(filename).st_mode
|
143
|
+
mode = stat.S_IMODE(mode) & ~(stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH)
|
144
|
+
# The file may already be read only for that user
|
145
|
+
try:
|
146
|
+
os.chmod(filename, mode)
|
147
|
+
except PermissionError:
|
148
|
+
pass
|
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.buffer import OutputBuffer
|
159
|
+
sage: OutputBuffer('test1234')
|
160
|
+
buffer containing 8 bytes
|
161
|
+
"""
|
162
|
+
return 'buffer containing {0} bytes'.format(len(self.get()))
|
163
|
+
|
164
|
+
def get(self):
|
165
|
+
"""
|
166
|
+
Return the buffer content.
|
167
|
+
|
168
|
+
OUTPUT: bytes; string in Python 2.x
|
169
|
+
|
170
|
+
EXAMPLES::
|
171
|
+
|
172
|
+
sage: from sage.repl.rich_output.buffer import OutputBuffer
|
173
|
+
sage: c = OutputBuffer('test1234').get(); c.decode('ascii')
|
174
|
+
'test1234'
|
175
|
+
sage: type(c) is bytes
|
176
|
+
True
|
177
|
+
sage: c = OutputBuffer('été').get()
|
178
|
+
sage: type(c) is bytes
|
179
|
+
True
|
180
|
+
"""
|
181
|
+
if self._data is None:
|
182
|
+
with open(self._filename, 'rb') as f:
|
183
|
+
self._data = f.read()
|
184
|
+
return self._data
|
185
|
+
|
186
|
+
def get_unicode(self):
|
187
|
+
"""
|
188
|
+
Return the buffer content as string.
|
189
|
+
|
190
|
+
OUTPUT:
|
191
|
+
|
192
|
+
String. Unicode in Python 2.x. Raises a :exc:`UnicodeEncodeError`
|
193
|
+
if the data is not valid utf-8.
|
194
|
+
|
195
|
+
EXAMPLES::
|
196
|
+
|
197
|
+
sage: from sage.repl.rich_output.buffer import OutputBuffer
|
198
|
+
sage: OutputBuffer('test1234').get().decode('ascii')
|
199
|
+
'test1234'
|
200
|
+
sage: OutputBuffer('test1234').get_unicode()
|
201
|
+
'test1234'
|
202
|
+
"""
|
203
|
+
return self.get().decode('utf-8')
|
204
|
+
|
205
|
+
def get_str(self):
|
206
|
+
"""
|
207
|
+
Return the buffer content as a ``str`` object for the current Python
|
208
|
+
version.
|
209
|
+
|
210
|
+
That is, returns a Python 2-style encoding-agnostic ``str`` on Python
|
211
|
+
2, and returns a unicode ``str`` on Python 3 with the buffer content
|
212
|
+
decoded from UTF-8. In other words, this is equivalent to
|
213
|
+
``OutputBuffer.get`` on Python 2 and ``OutputBuffer.get_unicode`` on
|
214
|
+
Python 3. This is useful in some cases for cross-compatible code.
|
215
|
+
|
216
|
+
OUTPUT: a ``str`` object
|
217
|
+
|
218
|
+
EXAMPLES::
|
219
|
+
|
220
|
+
sage: from sage.repl.rich_output.buffer import OutputBuffer
|
221
|
+
sage: c = OutputBuffer('test1234').get_str(); c
|
222
|
+
'test1234'
|
223
|
+
sage: type(c) is str
|
224
|
+
True
|
225
|
+
sage: c = OutputBuffer('été').get_str()
|
226
|
+
sage: type(c) is str
|
227
|
+
True
|
228
|
+
"""
|
229
|
+
return self.get_unicode()
|
230
|
+
|
231
|
+
def filename(self, ext=None):
|
232
|
+
"""
|
233
|
+
Return the filename.
|
234
|
+
|
235
|
+
INPUT:
|
236
|
+
|
237
|
+
- ``ext`` -- string; the file extension
|
238
|
+
|
239
|
+
OUTPUT:
|
240
|
+
|
241
|
+
Name of a file, most likely a temporary file. If ``ext`` is
|
242
|
+
specified, the filename will have that extension.
|
243
|
+
|
244
|
+
You must not modify the returned file. Its permissions are set
|
245
|
+
to readonly to help with that.
|
246
|
+
|
247
|
+
EXAMPLES::
|
248
|
+
|
249
|
+
sage: from sage.repl.rich_output.buffer import OutputBuffer
|
250
|
+
sage: buf = OutputBuffer('test')
|
251
|
+
sage: buf.filename() # random output
|
252
|
+
'/home/user/.sage/temp/hostname/26085/tmp_RNSfAc'
|
253
|
+
|
254
|
+
sage: os.path.isfile(buf.filename())
|
255
|
+
True
|
256
|
+
sage: buf.filename(ext='txt') # random output
|
257
|
+
'/home/user/.sage/temp/hostname/26085/tmp_Rjjp4V.txt'
|
258
|
+
sage: buf.filename(ext='txt').endswith('.txt')
|
259
|
+
True
|
260
|
+
"""
|
261
|
+
if ext is None:
|
262
|
+
ext = ''
|
263
|
+
elif not ext.startswith('.'):
|
264
|
+
ext = '.' + ext
|
265
|
+
|
266
|
+
if self._filename is None or not self._filename.endswith(ext):
|
267
|
+
from sage.misc.temporary_file import tmp_filename
|
268
|
+
output = tmp_filename(ext=ext)
|
269
|
+
else:
|
270
|
+
output = self._filename
|
271
|
+
|
272
|
+
if self._filename is None:
|
273
|
+
assert self._data is not None
|
274
|
+
with open(output, 'wb') as f:
|
275
|
+
f.write(self._data)
|
276
|
+
self._filename = output
|
277
|
+
elif self._filename != output:
|
278
|
+
try:
|
279
|
+
os.link(self._filename, output)
|
280
|
+
except (OSError, AttributeError):
|
281
|
+
import shutil
|
282
|
+
shutil.copy2(self._filename, output)
|
283
|
+
|
284
|
+
self._chmod_readonly(output)
|
285
|
+
return output
|
286
|
+
|
287
|
+
def save_as(self, filename):
|
288
|
+
"""
|
289
|
+
Save a copy of the buffer content.
|
290
|
+
|
291
|
+
You may edit the returned file, unlike the file returned by
|
292
|
+
:meth:`filename`.
|
293
|
+
|
294
|
+
INPUT:
|
295
|
+
|
296
|
+
- ``filename`` -- string; the file name to save under
|
297
|
+
|
298
|
+
EXAMPLES::
|
299
|
+
|
300
|
+
sage: from sage.repl.rich_output.buffer import OutputBuffer
|
301
|
+
sage: buf = OutputBuffer('test')
|
302
|
+
sage: buf.filename(ext='txt') # random output
|
303
|
+
sage: tmp = tmp_dir()
|
304
|
+
sage: filename = os.path.join(tmp, 'foo.txt')
|
305
|
+
sage: buf.save_as(filename)
|
306
|
+
sage: with open(filename, 'r') as f:
|
307
|
+
....: f.read()
|
308
|
+
'test'
|
309
|
+
"""
|
310
|
+
with open(filename, 'wb') as f:
|
311
|
+
f.write(self.get())
|