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.
Files changed (162) hide show
  1. passagemath_repl-10.4.62.data/scripts/sage-cachegrind +25 -0
  2. passagemath_repl-10.4.62.data/scripts/sage-callgrind +16 -0
  3. passagemath_repl-10.4.62.data/scripts/sage-cleaner +230 -0
  4. passagemath_repl-10.4.62.data/scripts/sage-coverage +327 -0
  5. passagemath_repl-10.4.62.data/scripts/sage-eval +14 -0
  6. passagemath_repl-10.4.62.data/scripts/sage-fixdoctests +708 -0
  7. passagemath_repl-10.4.62.data/scripts/sage-inline-fortran +12 -0
  8. passagemath_repl-10.4.62.data/scripts/sage-ipynb2rst +50 -0
  9. passagemath_repl-10.4.62.data/scripts/sage-ipython +16 -0
  10. passagemath_repl-10.4.62.data/scripts/sage-massif +25 -0
  11. passagemath_repl-10.4.62.data/scripts/sage-notebook +267 -0
  12. passagemath_repl-10.4.62.data/scripts/sage-omega +25 -0
  13. passagemath_repl-10.4.62.data/scripts/sage-preparse +302 -0
  14. passagemath_repl-10.4.62.data/scripts/sage-run +27 -0
  15. passagemath_repl-10.4.62.data/scripts/sage-run-cython +10 -0
  16. passagemath_repl-10.4.62.data/scripts/sage-runtests +9 -0
  17. passagemath_repl-10.4.62.data/scripts/sage-startuptime.py +163 -0
  18. passagemath_repl-10.4.62.data/scripts/sage-valgrind +34 -0
  19. passagemath_repl-10.4.62.dist-info/METADATA +77 -0
  20. passagemath_repl-10.4.62.dist-info/RECORD +162 -0
  21. passagemath_repl-10.4.62.dist-info/WHEEL +5 -0
  22. passagemath_repl-10.4.62.dist-info/top_level.txt +1 -0
  23. sage/all__sagemath_repl.py +119 -0
  24. sage/doctest/__init__.py +4 -0
  25. sage/doctest/__main__.py +236 -0
  26. sage/doctest/all.py +4 -0
  27. sage/doctest/check_tolerance.py +261 -0
  28. sage/doctest/control.py +1727 -0
  29. sage/doctest/external.py +534 -0
  30. sage/doctest/fixtures.py +383 -0
  31. sage/doctest/forker.py +2665 -0
  32. sage/doctest/marked_output.py +102 -0
  33. sage/doctest/parsing.py +1708 -0
  34. sage/doctest/parsing_test.py +79 -0
  35. sage/doctest/reporting.py +733 -0
  36. sage/doctest/rif_tol.py +124 -0
  37. sage/doctest/sources.py +1657 -0
  38. sage/doctest/test.py +584 -0
  39. sage/doctest/tests/1second.rst +4 -0
  40. sage/doctest/tests/99seconds.rst +4 -0
  41. sage/doctest/tests/abort.rst +5 -0
  42. sage/doctest/tests/atexit.rst +7 -0
  43. sage/doctest/tests/fail_and_die.rst +6 -0
  44. sage/doctest/tests/initial.rst +15 -0
  45. sage/doctest/tests/interrupt.rst +7 -0
  46. sage/doctest/tests/interrupt_diehard.rst +14 -0
  47. sage/doctest/tests/keyboardinterrupt.rst +11 -0
  48. sage/doctest/tests/longtime.rst +5 -0
  49. sage/doctest/tests/nodoctest +5 -0
  50. sage/doctest/tests/random_seed.rst +4 -0
  51. sage/doctest/tests/show_skipped.rst +18 -0
  52. sage/doctest/tests/sig_on.rst +9 -0
  53. sage/doctest/tests/simple_failure.rst +8 -0
  54. sage/doctest/tests/sleep_and_raise.rst +106 -0
  55. sage/doctest/tests/tolerance.rst +31 -0
  56. sage/doctest/util.py +750 -0
  57. sage/interfaces/cleaner.py +48 -0
  58. sage/interfaces/quit.py +163 -0
  59. sage/misc/all__sagemath_repl.py +51 -0
  60. sage/misc/banner.py +235 -0
  61. sage/misc/benchmark.py +221 -0
  62. sage/misc/classgraph.py +131 -0
  63. sage/misc/copying.py +22 -0
  64. sage/misc/cython.py +694 -0
  65. sage/misc/dev_tools.py +745 -0
  66. sage/misc/edit_module.py +304 -0
  67. sage/misc/explain_pickle.py +3079 -0
  68. sage/misc/gperftools.py +361 -0
  69. sage/misc/inline_fortran.py +212 -0
  70. sage/misc/messaging.py +86 -0
  71. sage/misc/pager.py +21 -0
  72. sage/misc/profiler.py +179 -0
  73. sage/misc/python.py +70 -0
  74. sage/misc/remote_file.py +53 -0
  75. sage/misc/sage_eval.py +246 -0
  76. sage/misc/sage_input.py +3621 -0
  77. sage/misc/sagedoc.py +1742 -0
  78. sage/misc/sh.py +38 -0
  79. sage/misc/trace.py +90 -0
  80. sage/repl/__init__.py +16 -0
  81. sage/repl/all.py +15 -0
  82. sage/repl/attach.py +625 -0
  83. sage/repl/configuration.py +186 -0
  84. sage/repl/display/__init__.py +1 -0
  85. sage/repl/display/fancy_repr.py +354 -0
  86. sage/repl/display/formatter.py +318 -0
  87. sage/repl/display/jsmol_iframe.py +290 -0
  88. sage/repl/display/pretty_print.py +153 -0
  89. sage/repl/display/util.py +163 -0
  90. sage/repl/image.py +302 -0
  91. sage/repl/inputhook.py +91 -0
  92. sage/repl/interface_magic.py +298 -0
  93. sage/repl/interpreter.py +854 -0
  94. sage/repl/ipython_extension.py +593 -0
  95. sage/repl/ipython_kernel/__init__.py +1 -0
  96. sage/repl/ipython_kernel/__main__.py +4 -0
  97. sage/repl/ipython_kernel/all_jupyter.py +10 -0
  98. sage/repl/ipython_kernel/install.py +301 -0
  99. sage/repl/ipython_kernel/interact.py +278 -0
  100. sage/repl/ipython_kernel/kernel.py +217 -0
  101. sage/repl/ipython_kernel/widgets.py +466 -0
  102. sage/repl/ipython_kernel/widgets_sagenb.py +587 -0
  103. sage/repl/ipython_tests.py +163 -0
  104. sage/repl/load.py +326 -0
  105. sage/repl/preparse.py +2218 -0
  106. sage/repl/prompts.py +90 -0
  107. sage/repl/rich_output/__init__.py +4 -0
  108. sage/repl/rich_output/backend_base.py +648 -0
  109. sage/repl/rich_output/backend_doctest.py +316 -0
  110. sage/repl/rich_output/backend_emacs.py +151 -0
  111. sage/repl/rich_output/backend_ipython.py +596 -0
  112. sage/repl/rich_output/buffer.py +311 -0
  113. sage/repl/rich_output/display_manager.py +829 -0
  114. sage/repl/rich_output/example.avi +0 -0
  115. sage/repl/rich_output/example.canvas3d +1 -0
  116. sage/repl/rich_output/example.dvi +0 -0
  117. sage/repl/rich_output/example.flv +0 -0
  118. sage/repl/rich_output/example.gif +0 -0
  119. sage/repl/rich_output/example.jpg +0 -0
  120. sage/repl/rich_output/example.mkv +0 -0
  121. sage/repl/rich_output/example.mov +0 -0
  122. sage/repl/rich_output/example.mp4 +0 -0
  123. sage/repl/rich_output/example.ogv +0 -0
  124. sage/repl/rich_output/example.pdf +0 -0
  125. sage/repl/rich_output/example.png +0 -0
  126. sage/repl/rich_output/example.svg +54 -0
  127. sage/repl/rich_output/example.webm +0 -0
  128. sage/repl/rich_output/example.wmv +0 -0
  129. sage/repl/rich_output/example_jmol.spt.zip +0 -0
  130. sage/repl/rich_output/example_wavefront_scene.mtl +7 -0
  131. sage/repl/rich_output/example_wavefront_scene.obj +17 -0
  132. sage/repl/rich_output/output_basic.py +391 -0
  133. sage/repl/rich_output/output_browser.py +103 -0
  134. sage/repl/rich_output/output_catalog.py +54 -0
  135. sage/repl/rich_output/output_graphics.py +320 -0
  136. sage/repl/rich_output/output_graphics3d.py +345 -0
  137. sage/repl/rich_output/output_video.py +231 -0
  138. sage/repl/rich_output/preferences.py +432 -0
  139. sage/repl/rich_output/pretty_print.py +339 -0
  140. sage/repl/rich_output/test_backend.py +201 -0
  141. sage/repl/user_globals.py +214 -0
  142. sage/tests/__init__.py +1 -0
  143. sage/tests/all.py +3 -0
  144. sage/tests/article_heuberger_krenn_kropf_fsm-in-sage.py +630 -0
  145. sage/tests/arxiv_0812_2725.py +351 -0
  146. sage/tests/benchmark.py +1923 -0
  147. sage/tests/book_schilling_zabrocki_kschur_primer.py +795 -0
  148. sage/tests/book_stein_ent.py +651 -0
  149. sage/tests/book_stein_modform.py +558 -0
  150. sage/tests/cmdline.py +790 -0
  151. sage/tests/combinatorial_hopf_algebras.py +52 -0
  152. sage/tests/finite_poset.py +623 -0
  153. sage/tests/functools_partial_src.py +27 -0
  154. sage/tests/gosper-sum.py +218 -0
  155. sage/tests/lazy_imports.py +28 -0
  156. sage/tests/modular_group_cohomology.py +80 -0
  157. sage/tests/numpy.py +21 -0
  158. sage/tests/parigp.py +76 -0
  159. sage/tests/startup.py +27 -0
  160. sage/tests/symbolic-series.py +76 -0
  161. sage/tests/sympy.py +16 -0
  162. sage/tests/test_deprecation.py +31 -0
@@ -0,0 +1,186 @@
1
+ # sage_setup: distribution = sagemath-repl
2
+ r"""
3
+ Sage's IPython Configuration
4
+
5
+ TESTS:
6
+
7
+ We check that Sage stdin can be piped in even if stdout is a tty; In that case
8
+ the IPython simple prompt is being used::
9
+
10
+ sage: cmd = 'print([sys.stdin.isatty(), sys.stdout.isatty()])'
11
+ sage: import pexpect # needs pexpect
12
+ sage: output = pexpect.run( # needs pexpect
13
+ ....: 'bash -c \'echo "{0}" | sage\''.format(cmd),
14
+ ....: ).decode('utf-8', 'surrogateescape')
15
+ sage: 'sage: [False, True]' in output # needs pexpect
16
+ True
17
+ """
18
+
19
+ #*****************************************************************************
20
+ # Copyright (C) 2016 Volker Braun <vbraun.name@gmail.com>
21
+ #
22
+ # Distributed under the terms of the GNU General Public License (GPL)
23
+ # as published by the Free Software Foundation; either version 2 of
24
+ # the License, or (at your option) any later version.
25
+ # http://www.gnu.org/licenses/
26
+ #*****************************************************************************
27
+
28
+
29
+ import sys
30
+ import copy
31
+ from traitlets.config.loader import Config
32
+
33
+ from sage.repl.prompts import SagePrompts
34
+
35
+
36
+ # Name of the Sage IPython extension
37
+ SAGE_EXTENSION = 'sage'
38
+
39
+
40
+ class SageIpythonConfiguration:
41
+
42
+ def _doctest_mode(self):
43
+ """
44
+ Whether we are in doctest mode.
45
+
46
+ This returns ``True`` during doctests.
47
+
48
+ EXAMPLES::
49
+
50
+ sage: from sage.repl.configuration import sage_ipython_config
51
+ sage: sage_ipython_config._doctest_mode()
52
+ True
53
+ """
54
+ from sage.doctest import DOCTEST_MODE
55
+ return DOCTEST_MODE
56
+
57
+ def _allow_ansi(self):
58
+ """
59
+ Whether to allow ANSI escape sequences.
60
+
61
+ This returns ``False`` during doctests to avoid ANSI escape
62
+ sequences.
63
+
64
+ EXAMPLES::
65
+
66
+ sage: from sage.repl.configuration import sage_ipython_config
67
+ sage: sage_ipython_config._allow_ansi()
68
+ False
69
+ """
70
+ return (not self._doctest_mode()) and sys.stdin.isatty() and sys.stdout.isatty()
71
+
72
+ def colors(self):
73
+ """
74
+ Return the IPython color palette.
75
+
76
+ This returns ``'NoColor'`` during doctests to avoid ANSI escape
77
+ sequences.
78
+
79
+ EXAMPLES::
80
+
81
+ sage: from sage.repl.configuration import sage_ipython_config
82
+ sage: sage_ipython_config.simple_prompt()
83
+ True
84
+ """
85
+ if not self._allow_ansi():
86
+ return 'NoColor'
87
+ from sage.repl.interpreter import SageTerminalInteractiveShell
88
+ return SageTerminalInteractiveShell.colors.default()
89
+
90
+ def simple_prompt(self):
91
+ """
92
+ Return whether to use the simple prompt.
93
+
94
+ This returns ``True`` during doctests to avoid ANSI escape sequences.
95
+
96
+ EXAMPLES::
97
+
98
+ sage: from sage.repl.configuration import sage_ipython_config
99
+ sage: sage_ipython_config.simple_prompt()
100
+ True
101
+ """
102
+ return not self._allow_ansi()
103
+
104
+ def term_title(self):
105
+ """
106
+ Return whether to set the terminal title.
107
+
108
+ This returns false during doctests to avoid ANSI escape sequences.
109
+
110
+ EXAMPLES::
111
+
112
+ sage: from sage.repl.configuration import sage_ipython_config
113
+ sage: sage_ipython_config.term_title()
114
+ False
115
+ """
116
+ return self._allow_ansi()
117
+
118
+ def default(self):
119
+ """
120
+ Return a new default configuration object.
121
+
122
+ EXAMPLES::
123
+
124
+ sage: from sage.repl.configuration import sage_ipython_config
125
+ sage: conf = sage_ipython_config.default()
126
+ sage: type(conf)
127
+ <class 'traitlets.config.loader.Config'>
128
+ sage: 'InteractiveShell' in conf
129
+ True
130
+ """
131
+ from sage.repl.interpreter import SageTerminalInteractiveShell
132
+
133
+ # Use the same config for both InteractiveShell, and its subclass
134
+ # TerminalInteractiveShell (note: in fact some configs like term_title
135
+ # only apply to the latter, but we can still use the same config for
136
+ # both for simplicity's sake; see Issue #28289)
137
+ InteractiveShell = Config(
138
+ prompts_class=SagePrompts,
139
+ ast_node_interactivity='all',
140
+ colors=self.colors(),
141
+ simple_prompt=self.simple_prompt(),
142
+ term_title=self.term_title(),
143
+ confirm_exit=False,
144
+ separate_in=''
145
+ )
146
+
147
+ cfg = Config(
148
+ TerminalIPythonApp=Config(
149
+ display_banner=False,
150
+ verbose_crash=True,
151
+ test_shell=False,
152
+ shell_class=SageTerminalInteractiveShell,
153
+ ),
154
+ InteractiveShell=InteractiveShell,
155
+ TerminalInteractiveShell=InteractiveShell,
156
+ InteractiveShellApp=Config(extensions=[SAGE_EXTENSION]),
157
+ # TODO: jedi is disabled by default because it causes too many troubles
158
+ # disabling issue: https://github.com/sagemath/sage/issues/31648
159
+ # reenabling issue: https://github.com/sagemath/sage/issues/31649
160
+ IPCompleter=Config(use_jedi=False),
161
+ )
162
+ if self._doctest_mode():
163
+ # Using the file-backed history causes problems in parallel tests
164
+ cfg.HistoryManager = Config(hist_file=':memory:')
165
+ return cfg
166
+
167
+ def copy(self):
168
+ """
169
+ Return a copy of the current configuration.
170
+
171
+ EXAMPLES::
172
+
173
+ sage: from sage.repl.configuration import sage_ipython_config
174
+ sage: conf = sage_ipython_config.copy()
175
+ sage: type(conf)
176
+ <class 'traitlets.config.loader.Config'>
177
+ sage: 'InteractiveShell' in conf
178
+ True
179
+ """
180
+ try:
181
+ return copy.deepcopy(get_ipython().config)
182
+ except NameError:
183
+ return self.default()
184
+
185
+
186
+ sage_ipython_config = SageIpythonConfiguration()
@@ -0,0 +1 @@
1
+ # sage_setup: distribution = sagemath-repl
@@ -0,0 +1,354 @@
1
+ # sage_setup: distribution = sagemath-repl
2
+ """
3
+ Representations of objects
4
+ """
5
+ # ****************************************************************************
6
+ # Copyright (C) 2014 Volker Braun <vbraun.name@gmail.com>
7
+ #
8
+ # Distributed under the terms of the GNU General Public License (GPL)
9
+ # as published by the Free Software Foundation; either version 2 of
10
+ # the License, or (at your option) any later version.
11
+ # https://www.gnu.org/licenses/
12
+ # ****************************************************************************
13
+
14
+ import types
15
+ from io import StringIO
16
+
17
+ from IPython.lib.pretty import (
18
+ _safe_getattr,
19
+ _type_pprinters,
20
+ )
21
+
22
+ from sage.repl.display.util import format_list
23
+
24
+ _baseclass_reprs = (object.__repr__,)
25
+
26
+
27
+ class ObjectReprABC:
28
+ """
29
+ The abstract base class of an object representer.
30
+
31
+ .. automethod:: __call__
32
+ """
33
+
34
+ def __repr__(self):
35
+ """
36
+ Return string representation.
37
+
38
+ OUTPUT: string
39
+
40
+ EXAMPLES::
41
+
42
+ sage: from sage.repl.display.fancy_repr import ObjectReprABC
43
+ sage: ObjectReprABC()
44
+ ObjectReprABC pretty printer
45
+ """
46
+ return '{0} pretty printer'.format(self.__class__.__name__)
47
+
48
+ def __call__(self, obj, p, cycle):
49
+ r"""
50
+ Format object.
51
+
52
+ INPUT:
53
+
54
+ - ``obj`` -- anything; object to format
55
+
56
+ - ``p`` -- PrettyPrinter instance
57
+
58
+ - ``cycle`` -- boolean; whether there is a cycle
59
+
60
+ OUTPUT:
61
+
62
+ boolean; whether the representer is applicable to ``obj``. If
63
+ ``True``, the string representation is appended to ``p``.
64
+
65
+ EXAMPLES::
66
+
67
+ sage: from sage.repl.display.fancy_repr import ObjectReprABC
68
+ sage: ObjectReprABC().format_string(123) # indirect doctest
69
+ 'Error: ObjectReprABC.__call__ is abstract'
70
+ """
71
+ p.text('Error: ObjectReprABC.__call__ is abstract')
72
+ return True
73
+
74
+ def format_string(self, obj):
75
+ """
76
+ For doctesting only: Directly return string.
77
+
78
+ INPUT:
79
+
80
+ - ``obj`` -- anything; object to format
81
+
82
+ OUTPUT: string
83
+
84
+ EXAMPLES::
85
+
86
+ sage: from sage.repl.display.fancy_repr import ObjectReprABC
87
+ sage: ObjectReprABC().format_string(123)
88
+ 'Error: ObjectReprABC.__call__ is abstract'
89
+ """
90
+ from sage.repl.display.pretty_print import SagePrettyPrinter
91
+ stream = StringIO()
92
+ p = SagePrettyPrinter(stream, 79, '\n')
93
+ ok = self(obj, p, False)
94
+ if ok:
95
+ p.flush()
96
+ return stream.getvalue()
97
+ else:
98
+ return '--- object not handled by representer ---'
99
+
100
+
101
+ class SomeIPythonRepr(ObjectReprABC):
102
+
103
+ def __init__(self):
104
+ """
105
+ Some selected representers from IPython.
106
+
107
+ EXAMPLES::
108
+
109
+ sage: from sage.repl.display.fancy_repr import SomeIPythonRepr
110
+ sage: SomeIPythonRepr()
111
+ SomeIPythonRepr pretty printer
112
+
113
+ .. automethod:: __call__
114
+ """
115
+ type_repr = _type_pprinters.copy()
116
+ del type_repr[type]
117
+ del type_repr[types.BuiltinFunctionType]
118
+ del type_repr[types.FunctionType]
119
+ del type_repr[str]
120
+ self._type_repr = type_repr
121
+
122
+ def __call__(self, obj, p, cycle):
123
+ """
124
+ Format object.
125
+
126
+ INPUT:
127
+
128
+ - ``obj`` -- anything; object to format
129
+
130
+ - ``p`` -- PrettyPrinter instance
131
+
132
+ - ``cycle`` -- boolean; whether there is a cycle
133
+
134
+ OUTPUT:
135
+
136
+ boolean; whether the representer is applicable to ``obj``. If
137
+ ``True``, the string representation is appended to ``p``.
138
+
139
+ EXAMPLES::
140
+
141
+ sage: from sage.repl.display.fancy_repr import SomeIPythonRepr
142
+ sage: pp = SomeIPythonRepr()
143
+ sage: pp.format_string(set([1, 2, 3]))
144
+ '{1, 2, 3}'
145
+ """
146
+ try:
147
+ pretty_repr = self._type_repr[type(obj)]
148
+ except KeyError:
149
+ return False
150
+ pretty_repr(obj, p, cycle)
151
+ return True
152
+
153
+
154
+ class LargeMatrixHelpRepr(ObjectReprABC):
155
+ """
156
+ Representation including help for large Sage matrices.
157
+
158
+ .. automethod:: __call__
159
+ """
160
+
161
+ def __call__(self, obj, p, cycle):
162
+ r"""
163
+ Format matrix.
164
+
165
+ INPUT:
166
+
167
+ - ``obj`` -- anything; object to format
168
+
169
+ - ``p`` -- PrettyPrinter instance
170
+
171
+ - ``cycle`` -- boolean; whether there is a cycle
172
+
173
+ OUTPUT:
174
+
175
+ boolean; whether the representer is applicable to ``obj``. If
176
+ ``True``, the string representation is appended to ``p``.
177
+
178
+ EXAMPLES::
179
+
180
+ sage: # needs sage.modules
181
+ sage: from sage.repl.display.fancy_repr import LargeMatrixHelpRepr
182
+ sage: M = identity_matrix(40)
183
+ sage: pp = LargeMatrixHelpRepr()
184
+ sage: pp.format_string(M)
185
+ "40 x 40 dense matrix over Integer Ring (use the '.str()' method...)"
186
+ sage: pp.format_string([M, M])
187
+ '--- object not handled by representer ---'
188
+
189
+ Leads to::
190
+
191
+ sage: M # needs sage.modules
192
+ 40 x 40 dense matrix over Integer Ring (use the '.str()' method...)
193
+ sage: [M, M] # needs sage.modules
194
+ [40 x 40 dense matrix over Integer Ring,
195
+ 40 x 40 dense matrix over Integer Ring]
196
+ """
197
+ if not p.toplevel():
198
+ # Do not print the help for matrices inside containers
199
+ return False
200
+ from sage.structure.element import Matrix
201
+ if not isinstance(obj, Matrix):
202
+ return False
203
+ from sage.matrix.constructor import options
204
+ if obj.nrows() <= options.max_rows() and obj.ncols() <= options.max_cols():
205
+ return False
206
+ p.text(
207
+ repr(obj) + " (use the '.str()' method to see the entries)"
208
+ )
209
+ return True
210
+
211
+
212
+ class PlainPythonRepr(ObjectReprABC):
213
+ """
214
+ The ordinary Python representation.
215
+
216
+ .. automethod:: __call__
217
+ """
218
+
219
+ def __call__(self, obj, p, cycle):
220
+ r"""
221
+ Format matrix.
222
+
223
+ INPUT:
224
+
225
+ - ``obj`` -- anything; object to format
226
+
227
+ - ``p`` -- PrettyPrinter instance
228
+
229
+ - ``cycle`` -- boolean; whether there is a cycle
230
+
231
+ OUTPUT:
232
+
233
+ boolean; whether the representer is applicable to ``obj``. If
234
+ ``True``, the string representation is appended to ``p``.
235
+
236
+ EXAMPLES::
237
+
238
+ sage: from sage.repl.display.fancy_repr import PlainPythonRepr
239
+ sage: pp = PlainPythonRepr()
240
+ sage: pp.format_string(type(1))
241
+ "<class 'sage.rings.integer.Integer'>"
242
+
243
+ Do not swallow a trailing newline at the end of the output of
244
+ a custom representer. Note that it is undesirable to have a
245
+ trailing newline, and if we don't display it you can't fix
246
+ it::
247
+
248
+ sage: class Newline():
249
+ ....: def __repr__(self):
250
+ ....: return 'newline\n'
251
+ sage: n = Newline()
252
+ sage: pp.format_string(n)
253
+ 'newline\n'
254
+ sage: pp.format_string([n, n, n])
255
+ '[newline\n, newline\n, newline\n]'
256
+ sage: [n, n, n]
257
+ [newline
258
+ , newline
259
+ , newline
260
+ ]
261
+ """
262
+ klass = _safe_getattr(obj, '__class__', None) or type(obj)
263
+ klass_repr = _safe_getattr(klass, '__repr__', None)
264
+ if klass_repr in _baseclass_reprs:
265
+ p.text(klass_repr(obj))
266
+ else:
267
+ # A user-provided repr. Find newlines and replace them with p.break_()
268
+ try:
269
+ output = repr(obj)
270
+ except Exception:
271
+ import sys
272
+ import traceback
273
+ objrepr = object.__repr__(obj).replace("object at", "at")
274
+ exc = traceback.format_exception_only(sys.exc_info()[0], sys.exc_info()[1])
275
+ exc = (''.join(exc)).strip()
276
+ output = "<repr({}) failed: {}>".format(objrepr, exc)
277
+ for idx, output_line in enumerate(output.split('\n')):
278
+ if idx:
279
+ p.break_()
280
+ p.text(output_line)
281
+ return True
282
+
283
+
284
+ class TallListRepr(ObjectReprABC):
285
+ """
286
+ Special representation for lists with tall entries (e.g. matrices).
287
+
288
+ .. automethod:: __call__
289
+ """
290
+
291
+ def __call__(self, obj, p, cycle):
292
+ r"""
293
+ Format list/tuple.
294
+
295
+ INPUT:
296
+
297
+ - ``obj`` -- anything; object to format
298
+
299
+ - ``p`` -- PrettyPrinter instance
300
+
301
+ - ``cycle`` -- boolean; whether there is a cycle
302
+
303
+ OUTPUT:
304
+
305
+ boolean; whether the representer is applicable to ``obj``. If
306
+ ``True``, the string representation is appended to ``p``.
307
+
308
+ EXAMPLES::
309
+
310
+ sage: from sage.repl.display.fancy_repr import TallListRepr
311
+ sage: format_list = TallListRepr().format_string
312
+ sage: format_list([1, 2, identity_matrix(2)]) # needs sage.modules
313
+ '[\n [1 0]\n1, 2, [0 1]\n]'
314
+
315
+ Check that :issue:`18743` is fixed::
316
+
317
+ sage: class Foo():
318
+ ....: def __repr__(self):
319
+ ....: return '''BBB AA RRR
320
+ ....: B B A A R R
321
+ ....: BBB AAAA RRR
322
+ ....: B B A A R R
323
+ ....: BBB A A R R'''
324
+ ....: def _repr_option(self, key):
325
+ ....: return key == 'ascii_art'
326
+ sage: F = Foo()
327
+ sage: [F, F]
328
+ [
329
+ BBB AA RRR BBB AA RRR
330
+ B B A A R R B B A A R R
331
+ BBB AAAA RRR BBB AAAA RRR
332
+ B B A A R R B B A A R R
333
+ BBB A A R R, BBB A A R R
334
+ ]
335
+ """
336
+ if not (isinstance(obj, (tuple, list)) and len(obj) > 0):
337
+ return False
338
+ ascii_art_repr = False
339
+ for o in obj:
340
+ try:
341
+ ascii_art_repr = ascii_art_repr or o._repr_option('ascii_art')
342
+ except (AttributeError, TypeError):
343
+ pass
344
+ try:
345
+ ascii_art_repr = ascii_art_repr or o.parent()._repr_option('element_ascii_art')
346
+ except (AttributeError, TypeError):
347
+ pass
348
+ if not ascii_art_repr:
349
+ return False
350
+ output = format_list.try_format(obj)
351
+ if output is None:
352
+ return False
353
+ p.text(output)
354
+ return True