code
stringlengths
17
6.64M
def modified_file_iterator(): "\n Iterate over the changed files\n\n As a side effect the stored time stamps are updated with the\n actual time stamps. So if you iterate over the attached files in\n order to reload them and you hit an error then the subsequent\n files are not marked as read.\n\n ...
def reload_attached_files_if_modified(): "\n Reload attached files that have been modified\n\n This is the internal implementation of the attach mechanism.\n\n EXAMPLES::\n\n sage: sage.repl.attach.reset()\n sage: from sage.repl.interpreter import get_test_shell\n sage: shell = get_t...
class SageIpythonConfiguration(): def _doctest_mode(self): '\n Whether we are in doctest mode\n\n This returns ``True`` during doctests.\n\n EXAMPLES::\n\n sage: from sage.repl.configuration import sage_ipython_config\n sage: sage_ipython_config._doctest_mode()\...
class ObjectReprABC(): '\n The abstract base class of an object representer.\n\n .. automethod:: __call__\n ' def __repr__(self): '\n Return string representation.\n\n OUTPUT:\n\n String.\n\n EXAMPLES::\n\n sage: from sage.repl.display.fancy_repr import...
class SomeIPythonRepr(ObjectReprABC): def __init__(self): '\n Some selected representers from IPython\n\n EXAMPLES::\n\n sage: from sage.repl.display.fancy_repr import SomeIPythonRepr\n sage: SomeIPythonRepr()\n SomeIPythonRepr pretty printer\n\n .. a...
class LargeMatrixHelpRepr(ObjectReprABC): '\n Representation including help for large Sage matrices\n\n .. automethod:: __call__\n ' def __call__(self, obj, p, cycle): '\n Format matrix.\n\n INPUT:\n\n - ``obj`` -- anything. Object to format.\n\n - ``p`` -- Pretty...
class PlainPythonRepr(ObjectReprABC): '\n The ordinary Python representation\n\n .. automethod:: __call__\n ' def __call__(self, obj, p, cycle): '\n Format matrix.\n\n INPUT:\n\n - ``obj`` -- anything. Object to format.\n\n - ``p`` -- PrettyPrinter instance.\n\n ...
class TallListRepr(ObjectReprABC): '\n Special representation for lists with tall entries (e.g. matrices)\n\n .. automethod:: __call__\n ' def __call__(self, obj, p, cycle): "\n Format list/tuple.\n\n INPUT:\n\n - ``obj`` -- anything. Object to format.\n\n - ``p``...
class SageDisplayFormatter(DisplayFormatter): def __init__(self, *args, **kwds): '\n This is where the Sage rich objects are translated to IPython\n\n INPUT/OUTPUT:\n\n See the IPython documentation.\n\n EXAMPLES:\n\n This is part of how Sage works with the IPython outp...
class SagePlainTextFormatter(PlainTextFormatter): def __init__(self, *args, **kwds): "\n Improved plain text IPython formatter.\n\n In particular, it correctly print lists of matrices or other\n objects (see\n :meth:`sage.structure.parent.Parent._repr_option`).\n\n .. w...
class JSMolHtml(SageObject): def __init__(self, jmol, path_to_jsmol=None, width='100%', height='100%'): "\n INPUT:\n\n - ``jmol`` -- 3-d graphics or\n :class:`sage.repl.rich_output.output_graphics3d.OutputSceneJmol`\n instance. The 3-d scene to show.\n\n - ``path_to...
class SagePrettyPrinter(PrettyPrinter): DEBUG = False pretty_repr = (TallListRepr(), LargeMatrixHelpRepr(), SomeIPythonRepr(), PlainPythonRepr()) def toplevel(self): "\n Return whether we are currently at the top level.\n\n OUTPUT:\n\n Boolean. Whether we are currently pretty...
class TallListFormatter(): '\n Special representation for lists with tall entries (e.g. matrices)\n\n .. automethod:: __call__\n ' MAX_COLUMN = 70 def _tall_list_row(self, running_lines, last_row=False): "\n Helper for :meth:`_check_tall_list_and_format`\n\n This helper fun...
class Image(SageObject): def __init__(self, mode, size, color='white'): "\n Creates a new image with the given mode and size.\n\n INPUT:\n\n - ``mode`` -- string. The mode to use for the new image. Valid\n options are:\n\n * ``'1'`` (1-bit pixels, black and whit...
def sage_inputhook(context): f = context.fileno() while True: sage.repl.attach.reload_attached_files_if_modified() try: (r, _, _) = select.select([f], [], [], TIMEOUT) if (f in r): return except select.error as e: if (e[0] != errno.EI...
def install(): '\n Install the Sage input hook\n\n EXAMPLES:\n\n Make sure ipython is running so we really test this function::\n\n sage: from sage.repl.interpreter import get_test_shell\n sage: get_test_shell()\n <sage.repl.interpreter.SageTestShell object at ...>\n\n Run the fun...
def uninstall(): '\n Uninstall the Sage input hook\n\n EXAMPLES::\n\n sage: from sage.repl.inputhook import uninstall\n sage: uninstall()\n ' ip = get_ipython() if (not ip): return if (ip._inputhook == sage_inputhook): with contextlib.redirect_stdout(io.StringIO(...
class InterfaceMagic(): @classmethod def all_iter(cls): '\n Iterate over the available interfaces\n\n EXAMPLES::\n\n sage: from sage.repl.interface_magic import InterfaceMagic\n sage: next(InterfaceMagic.all_iter())\n <sage.repl.interface_magic.Interface...
def preparser(on=True): '\n Turn on or off the Sage preparser.\n\n :keyword on: if True turn on preparsing; if False, turn it off.\n :type on: bool\n\n EXAMPLES::\n\n sage: 2/3\n 2/3\n sage: preparser(False)\n sage: 2/3 # not tested since doctests are always preparsed\n ...
class SageShellOverride(): "\n Mixin to override methods in IPython's [Terminal]InteractiveShell\n classes.\n " def show_usage(self): "\n Print the basic Sage usage.\n\n This method ends up being called when you enter ``?`` and\n nothing else on the command line.\n\n ...
class SageNotebookInteractiveShell(SageShellOverride, InteractiveShell): '\n IPython Shell for the Sage IPython Notebook\n\n The doctests are not tested since they would change the current\n rich output backend away from the doctest rich output backend.\n\n EXAMPLES::\n\n sage: from sage.repl.i...
class SageTerminalInteractiveShell(SageShellOverride, TerminalInteractiveShell): '\n IPython Shell for the Sage IPython Commandline Interface\n\n The doctests are not tested since they would change the current\n rich output backend away from the doctest rich output backend.\n\n EXAMPLES::\n\n s...
class SageTestShell(SageShellOverride, TerminalInteractiveShell): '\n Test Shell\n\n Care must be taken in these doctests to quit the test shell in\n order to switch back the rich output display backend to the\n doctest backend.\n\n EXAMPLES::\n\n sage: from sage.repl.interpreter import get_...
def SagePreparseTransformer(lines): '\n EXAMPLES::\n\n sage: from sage.repl.interpreter import SagePreparseTransformer\n sage: spt = SagePreparseTransformer\n sage: spt([\'1+1r+2.3^2.3r\\n\'])\n ["Integer(1)+1+RealNumber(\'2.3\')**2.3\\n"]\n sage: preparser(False)\n sa...
class logstr(str): '\n For use by :meth`~InterfaceShellTransformer.transform`.\n This provides a ``_latex_`` method which is just the string\n wrapped in a ``\\verb`` environment.\n ' def __repr__(self): '\n EXAMPLES::\n sage: from sage.repl.interpreter import logstr\n ...
class InterfaceShellTransformer(PrefilterTransformer): priority = 50 def __init__(self, *args, **kwds): "\n Initialize this class. All of the arguments get passed to\n :meth:`PrefilterTransformer.__init__`.\n\n .. attribute:: temporary_objects\n\n a list of hold onto i...
def interface_shell_embed(interface): "\n Returns an IPython shell which uses a Sage interface on the\n backend to perform the evaluations. It uses\n :class:`InterfaceShellTransformer` to transform the input into the\n appropriate ``interface.eval(...)`` input.\n\n INPUT:\n\n - ``interface`` --...
def get_test_shell(): '\n Return a IPython shell that can be used in testing the functions\n in this module.\n\n OUTPUT:\n\n An IPython shell\n\n EXAMPLES::\n\n sage: from sage.repl.interpreter import get_test_shell\n sage: shell = get_test_shell(); shell\n <sage.repl.interpret...
class SageCrashHandler(IPAppCrashHandler): def __init__(self, app): "\n A custom :class:`CrashHandler` which gives the user\n instructions on how to post the problem to sage-support.\n\n EXAMPLES::\n\n sage: from sage.repl.interpreter import SageTerminalApp, SageCrashHandl...
class SageTerminalApp(TerminalIPythonApp): name = 'Sage' crash_handler_class = SageCrashHandler test_shell = Bool(False, help='Whether the shell is a test shell') test_shell.tag(config=True) shell_class = Type(InteractiveShell, help='Type of the shell') shell_class.tag(config=True) def lo...
@magics_class class SageMagics(Magics): @line_magic def crun(self, s): "\n Profile C function calls\n\n INPUT:\n\n - ``s`` -- string. Sage command to profile.\n\n EXAMPLES::\n\n sage: from sage.repl.interpreter import get_test_shell\n sage: shell = ge...
class SageCustomizations(): def __init__(self, shell=None): '\n Initialize the Sage plugin.\n ' self.shell = shell self.auto_magics = SageMagics(shell) self.shell.register_magics(self.auto_magics) self.shell.set_hook('editor', LazyImport('sage.misc.edit_modul...
class SageJupyterCustomizations(SageCustomizations): @staticmethod def all_globals(): "\n Return a Python module containing all globals which should be\n made available to the user when running the Jupyter notebook.\n\n EXAMPLES::\n\n sage: from sage.repl.ipython_exten...
@run_once def load_ipython_extension(ip): '\n Load the extension in IPython.\n ' SageCustomizations(shell=ip)
class SageKernelSpec(): def __init__(self, prefix=None): "\n Utility to manage SageMath kernels and extensions\n\n INPUT:\n\n - ``prefix`` -- (optional, default: ``sys.prefix``)\n directory for the installation prefix\n\n EXAMPLES::\n\n sage: from sage.repl...
def have_prerequisites(debug=True): '\n Check that we have all prerequisites to run the Jupyter notebook.\n\n In particular, the Jupyter notebook requires OpenSSL whether or\n not you are using https. See :trac:`17318`.\n\n INPUT:\n\n ``debug`` -- boolean (default: ``True``). Whether to print debug...
class sage_interactive(interactive): '\n Wrapper around the ipywidgets interactive which handles some SageNB\n specifics.\n\n EXAMPLES::\n\n sage: from sage.repl.ipython_kernel.interact import sage_interactive\n sage: def myfunc(x=10, y="hello", z=None): pass\n sage: sage_interactive...
class SageZMQInteractiveShell(SageNotebookInteractiveShell, ZMQInteractiveShell): pass
class SageKernel(IPythonKernel): implementation = 'sage' implementation_version = SAGE_VERSION shell_class = Type(SageZMQInteractiveShell) def __init__(self, **kwds): '\n The Sage Jupyter Kernel\n\n INPUT:\n\n See the Jupyter documentation\n\n EXAMPLES::\n\n ...
class HTMLText(HTMLMath): '\n An HTML widget whose ``description`` is always empty.\n\n This is used to display arbitrary HTML text in interacts without\n a label. The :func:`text_control` function from SageNB is an alias\n of :class:`HTMLText`.\n\n EXAMPLES::\n\n sage: from sage.repl.ipytho...
class TransformWidget(): '\n A mixin class for a widget to transform the bare widget value for\n use in interactive functions.\n\n INPUT:\n\n - ``transform`` -- a one-argument function which transforms the\n value of the widget for use by an interactive function.\n\n - other arguments are pass...
class EvalWidget(TransformWidget): '\n A mixin class for a widget to evaluate (using :func:`sage_eval`) the\n widget value and possibly transform it like :class:`TransformWidget`.\n\n EXAMPLES::\n\n sage: from ipywidgets import ToggleButtons\n sage: from sage.repl.ipython_kernel.widgets imp...
class TransformIntSlider(TransformWidget, IntSlider): '\n An :class:`ipywidgets.IntSlider` widget with an optional\n transformation.\n\n EXAMPLES::\n\n sage: from sage.repl.ipython_kernel.widgets import TransformIntSlider\n sage: w = TransformIntSlider(min=0, max=100, value=7, transform=lam...
class TransformFloatSlider(TransformWidget, FloatSlider): '\n A :class:`ipywidgets.FloatSlider` widget with an optional\n transformation.\n\n EXAMPLES::\n\n sage: from sage.repl.ipython_kernel.widgets import TransformFloatSlider\n sage: w = TransformFloatSlider(min=0, max=100, value=7, tran...
class TransformIntRangeSlider(TransformWidget, IntRangeSlider): '\n An :class:`ipywidgets.IntRangeSlider` widget with an optional\n transformation.\n\n EXAMPLES::\n\n sage: from sage.repl.ipython_kernel.widgets import TransformIntRangeSlider\n sage: w = TransformIntRangeSlider(min=0, max=10...
class TransformFloatRangeSlider(TransformWidget, FloatRangeSlider): '\n An :class:`ipywidgets.FloatRangeSlider` widget with an optional\n transformation.\n\n EXAMPLES::\n\n sage: from sage.repl.ipython_kernel.widgets import TransformFloatRangeSlider\n sage: w = TransformFloatRangeSlider(min...
class TransformText(TransformWidget, Text): '\n A :class:`ipywidgets.Text` widget with an optional\n transformation.\n\n EXAMPLES::\n\n sage: from sage.repl.ipython_kernel.widgets import TransformText\n sage: w = TransformText(value="hello", transform=lambda x: x+x)\n sage: w\n ...
class TransformTextarea(TransformWidget, Textarea): '\n A :class:`ipywidgets.Textarea` widget with an optional\n transformation.\n\n EXAMPLES::\n\n sage: from sage.repl.ipython_kernel.widgets import TransformTextarea\n sage: w = TransformTextarea(value="hello", transform=lambda x: x+x)\n ...
class EvalText(EvalWidget, Text): '\n A :class:`ipywidgets.Text` widget which evaluates (using\n :func:`sage_eval`) its contents and applies an optional transformation.\n\n EXAMPLES::\n\n sage: from sage.repl.ipython_kernel.widgets import EvalText\n sage: w = EvalText(value="pi", transform=...
class EvalTextarea(EvalWidget, Textarea): '\n A :class:`ipywidgets.Textarea` widget which evaluates (using\n :func:`sage_eval`) its contents and applies an optional transformation.\n\n EXAMPLES::\n\n sage: from sage.repl.ipython_kernel.widgets import EvalTextarea\n sage: w = EvalTextarea(va...
class SageColorPicker(ColorPicker): "\n A color picker widget returning a Sage :class:`Color`.\n\n EXAMPLES::\n\n sage: from sage.repl.ipython_kernel.widgets import SageColorPicker\n sage: SageColorPicker()\n SageColorPicker(value='black')\n " def get_interact_value(self): ...
class Grid(TransformWidget, HBox, ValueWidget): '\n A square grid of widgets whose value is a list of lists of the\n values of the individual widgets.\n\n This is usually created using the :func:`input_grid` function.\n\n EXAMPLES::\n\n sage: from ipywidgets import Text\n sage: from sage...
def input_box(default=None, label=None, type=None, width=80, height=1): '\n A textbox widget.\n\n INPUT:\n\n - ``default`` -- initial value\n\n - ``label`` -- optional label\n\n - ``type`` -- function of one variable or ``None``. if ``type`` is\n ``str``, the value of this widget for interacti...
def slider(vmin, vmax=None, step_size=None, default=None, label=None, display_value=True, _range=False): '\n A slider widget.\n\n INPUT:\n\n For a numeric slider (select a value from a range):\n\n - ``vmin``, ``vmax`` -- minimum and maximum value\n\n - ``step_size`` -- the step size\n\n For a se...
def range_slider(*args, **kwds): '\n A slider widget to select a range of values.\n\n INPUT:\n\n - ``vmin``, ``vmax`` -- minimum and maximum value\n\n - ``step_size`` -- the step size\n\n - ``default`` -- initial value, given as a 2-tuple\n\n - ``label`` -- optional label\n\n - ``display_valu...
def checkbox(default=True, label=None): '\n A checkbox widget.\n\n INPUT:\n\n - ``default`` -- (boolean) initial value\n\n - ``label`` -- optional label\n\n EXAMPLES::\n\n sage: from sage.repl.ipython_kernel.all_jupyter import checkbox\n sage: checkbox(label="toggle me")\n Chec...
def selector(values, label=None, default=None, nrows=None, ncols=None, width=None, buttons=False): '\n A widget to select a value from a given list of values.\n\n This is rendered as a dropdown box (if ``buttons`` is False) or\n as a list of buttons (if ``buttons`` is True).\n\n INPUT:\n\n - ``valu...
def input_grid(nrows, ncols, default=None, label=None, to_value=None, width=4): '\n A widget consisting of a grid (matrix) of textboxes.\n\n The values entered in the textboxes are evaluated (using\n :func:`sage_eval`). These are stored as a list of lists on the\n ``value`` attribute. The value of thi...
def color_selector(default=(0, 0, 1), label=None, widget=None, hide_box=False): '\n A widget for choosing a color.\n\n INPUT:\n\n - ``default`` -- initial value\n\n - ``label`` -- optional label\n\n - ``hide_box`` -- (boolean) if True, do not show the textbox\n\n EXAMPLES::\n\n sage: from...
def dummy(argument, optional=None): "\n Dummy Docstring Title\n\n Dummy docstring explanation.\n\n INPUT:\n\n - ``argument`` -- anything. Dummy argument.\n\n - ``optional`` -- anything (optional). Dummy optional.\n\n EXAMPLES::\n\n sage: from sage.repl.ipython_tests import dummy\n ...
def is_loadable_filename(filename): "\n Return whether a file can be loaded into Sage.\n\n This checks only whether its name ends in one of the supported\n extensions ``.py``, ``.pyx``, ``.sage``, ``.spyx``, ``.f``,\n ``.f90`` and ``.m``.\n\n .. NOTE:: :func:`load` assumes that `.m` signifies a Mag...
def load_cython(name): '\n Helper function to load a Cython file.\n\n INPUT:\n\n - ``name`` -- filename of the Cython file\n\n OUTPUT:\n\n - A string with Python code to import the names from the compiled\n module.\n ' from sage.misc.cython import cython (mod, dir) = cython(name, co...
def load(filename, globals, attach=False): '\n Execute a file in the scope given by ``globals``. If the name starts with\n ``http://`` or ``https://``, it is treated as a URL and downloaded.\n\n .. NOTE::\n\n For Cython files, the situation is more complicated --\n the module is first compi...
def load_wrap(filename, attach=False): '\n Encode a load or attach command as valid Python code.\n\n INPUT:\n\n - ``filename`` - a string; the argument to the load or attach\n command\n\n - ``attach`` - a boolean (default: False); whether to attach\n ``filename``, instead of loading it\n\n ...
def implicit_multiplication(level=None): "\n Turn implicit multiplication on or off, optionally setting a\n specific ``level``.\n\n INPUT:\n\n - ``level`` -- a boolean or integer (default: 5); how aggressive to be in\n placing \\*'s\n\n - 0 - Do nothing\n - 1 - Numeric followed by alp...
def isalphadigit_(s) -> bool: "\n Return ``True`` if ``s`` is a non-empty string of alphabetic characters\n or a non-empty string of digits or just a single ``_``\n\n EXAMPLES::\n\n sage: from sage.repl.preparse import isalphadigit_\n sage: isalphadigit_('abc')\n True\n sage: ...
def in_quote() -> bool: return (in_single_quote or in_double_quote or in_triple_quote)
class QuoteStack(): 'The preserved state of parsing in :func:`strip_string_literals`.' def __init__(self): '\n Create a new, empty QuoteStack.\n\n EXAMPLES::\n\n sage: qs = sage.repl.preparse.QuoteStack()\n sage: len(qs)\n 0\n ' self._stac...
class QuoteStackFrame(SimpleNamespace): '\n The state of a single level of a string literal being parsed.\n\n Only F-strings have more than one level.\n ' def __init__(self, delim, raw=False, f_string=False, braces=0, parens=0, brackets=0, fmt_spec=False, nested_fmt_spec=False): '\n C...
def strip_string_literals(code, state=None): '\n Return a string with all literal quotes replaced with labels and\n a dictionary of labels for re-substitution.\n\n This makes parsing easier.\n\n INPUT:\n\n - ``code`` - a string; the input\n\n - ``state`` - a :class:`QuoteStack` (default: ``None`...
def containing_block(code, idx, delimiters=['()', '[]', '{}'], require_delim=True): '\n Find the code block given by balanced delimiters that contains the position ``idx``.\n\n INPUT:\n\n - ``code`` - a string\n\n - ``idx`` - an integer; a starting position\n\n - ``delimiters`` - a list of strings ...
def parse_ellipsis(code, preparse_step=True): '\n Preparses [0,2,..,n] notation.\n\n INPUT:\n\n - ``code`` - a string\n\n - ``preparse_step`` - a boolean (default: ``True``)\n\n OUTPUT:\n\n - a string\n\n EXAMPLES::\n\n sage: from sage.repl.preparse import parse_ellipsis\n sage:...
def extract_numeric_literals(code): '\n Pulls out numeric literals and assigns them to global variables.\n This eliminates the need to re-parse and create the literals,\n e.g., during every iteration of a loop.\n\n INPUT:\n\n - ``code`` - a string; a block of code\n\n OUTPUT:\n\n - a (string,...
def preparse_numeric_literals(code, extract=False, quotes="'"): '\n Preparse numerical literals into their Sage counterparts,\n e.g. Integer, RealNumber, and ComplexNumber.\n\n INPUT:\n\n - ``code`` - string; a code block to preparse\n\n - ``extract`` - boolean (default: ``False``); whether to crea...
def strip_prompts(line): '\n Remove leading sage: and >>> prompts so that pasting of examples\n from the documentation works.\n\n INPUT:\n\n - ``line`` - a string to process\n\n OUTPUT:\n\n - a string stripped of leading prompts\n\n EXAMPLES::\n\n sage: from sage.repl.preparse import s...
def preparse_calculus(code): '\n Supports calculus-like function assignment, e.g., transforms::\n\n f(x,y,z) = sin(x^3 - 4*y) + y^x\n\n into::\n\n __tmp__=var("x,y,z")\n f = symbolic_expression(sin(x**3 - 4*y) + y**x).function(x,y,z)\n\n AUTHORS:\n\n - Bobby Moretti\n\n - Initia...
def preparse_generators(code): '\n Parse generator syntax, converting::\n\n obj.<gen0,gen1,...,genN> = objConstructor(...)\n\n into::\n\n obj = objConstructor(..., names=("gen0", "gen1", ..., "genN"))\n (gen0, gen1, ..., genN,) = obj.gens()\n\n and::\n\n obj.<gen0,gen1,...,gen...
def preparse(line, reset=True, do_time=False, ignore_prompts=False, numeric_literals=True): '\n Preparse a line of input.\n\n INPUT:\n\n - ``line`` - a string\n\n - ``reset`` - a boolean (default: ``True``)\n\n - ``do_time`` - a boolean (default: ``False``)\n\n - ``ignore_prompts`` - a boolean (...
def preparse_file(contents, globals=None, numeric_literals=True): '\n Preparse ``contents`` which is input from a file such as ``.sage`` files.\n\n Special attentions are given to numeric literals and load/attach\n file directives.\n\n .. note:: Temporarily, if @parallel is in the input, then\n ...
def implicit_mul(code, level=5): "\n Insert \\*'s to make implicit multiplication explicit.\n\n INPUT:\n\n - ``code`` -- a string; the code with missing \\*'s\n\n - ``level`` -- an integer (default: 5); see :func:`implicit_multiplication`\n for a list\n\n OUTPUT:\n\n - a string\n\n EXAM...
def _strip_quotes(s): '\n Strip one set of outer quotes.\n\n INPUT:\n\n - ``s`` - a string\n\n OUTPUT:\n\n - a string with any single and double quotes on either side of\n ``s`` removed\n\n EXAMPLES:\n\n Both types of quotes work::\n\n sage: import sage.repl.preparse\n sage...
def handle_encoding_declaration(contents, out): "\n Find a PEP 263-style Python encoding declaration in the first or\n second line of ``contents``. If found, output it to ``out`` and return\n ``contents`` without the encoding line; otherwise output a default\n UTF-8 declaration and return ``contents``...
def preparse_file_named_to_stream(name, out): '\n Preparse file named \\code{name} (presumably a .sage file), outputting to\n stream \\code{out}.\n ' name = os.path.abspath(name) with open(name) as f: contents = f.read() contents = handle_encoding_declaration(contents, out) parsed...
def preparse_file_named(name): '\n Preparse file named \\code{name} (presumably a .sage file), outputting to a\n temporary file. Returns name of temporary file.\n ' from sage.misc.temporary_file import tmp_filename tmpfilename = (tmp_filename(os.path.basename(name)) + '.py') with open(tmpfil...
class SagePrompts(Prompts): def in_prompt_tokens(self, cli=None): return [(Token.Prompt, 'sage: ')] def continuation_prompt_tokens(self, cli=None, width=None): return [(Token.Prompt, '....: ')] def rewrite_prompt_tokens(self): return [(Token.Prompt, '----> ')] def out_promp...
class InterfacePrompts(Prompts): def __init__(self, interface_name): self.__name = interface_name self.__width = len(interface_name) def in_prompt_tokens(self, cli=None): return [(Token.Prompt, (self.__name + ': '))] def continuation_prompt_tokens(self, cli=None, width=None): ...
class DebugPrompts(Prompts): def in_prompt_tokens(self, cli=None): return [(Token.Prompt, 'debug: ')] def continuation_prompt_tokens(self, cli=None, width=None): return [(Token.Prompt, '.....: ')] def rewrite_prompt_tokens(self): return [(Token.Prompt, '-----> ')] def out_p...
class BackendBase(SageObject): def _repr_(self): '\n Return string representation of the backend\n\n Every backend must implement this method.\n\n OUTPUT:\n\n String.\n\n EXAMPLES::\n\n sage: from sage.repl.rich_output.backend_base import BackendBase\n ...
class BackendSimple(BackendBase): '\n Simple Backend\n\n This backend only supports plain text.\n\n EXAMPLES::\n\n sage: from sage.repl.rich_output.backend_base import BackendSimple\n sage: BackendSimple()\n simple\n ' def _repr_(self): "\n Return string repres...
class BackendDoctest(BackendBase): def _repr_(self): "\n Return a string representation.\n\n OUTPUT:\n\n String.\n\n EXAMPLES::\n\n sage: from sage.repl.rich_output.backend_doctest import BackendDoctest\n sage: backend = BackendDoctest()\n sage...
class BackendEmacs(BackendIPythonCommandline): "\n Emacs Backend\n\n This backend is used by Emacs' sage-mode to have typeset output\n and inline images.\n\n EXAMPLES::\n\n sage: from sage.repl.rich_output.backend_emacs import BackendEmacs\n sage: BackendEmacs()\n Emacs sage-mode\...
class BackendIPython(BackendBase): '\n Common base for the IPython UIs\n\n EXAMPLES::\n\n sage: from sage.repl.rich_output.backend_ipython import BackendIPython\n sage: BackendIPython()._repr_()\n Traceback (most recent call last):\n ...\n NotImplementedError: derived clas...
class BackendIPythonCommandline(BackendIPython): '\n Backend for the IPython Command Line\n\n EXAMPLES::\n\n sage: from sage.repl.rich_output.backend_ipython import BackendIPythonCommandline\n sage: BackendIPythonCommandline()\n IPython command line\n ' def default_preferences(s...
class BackendIPythonNotebook(BackendIPython): '\n Backend for the IPython Notebook\n\n EXAMPLES::\n\n sage: from sage.repl.rich_output.backend_ipython import BackendIPythonNotebook\n sage: BackendIPythonNotebook()\n IPython notebook\n ' def _repr_(self): "\n Retur...
class OutputBuffer(SageObject): def __init__(self, data): '\n Data stored either in memory or as a file\n\n This class is an abstraction for "files", in that they can\n either be defined by a bytes array (Python 3) or string\n (Python 2) or by a file (see :meth:`from_file`).\n...
def _required_threejs_version(): "\n Return the version of threejs that Sage requires.\n\n EXAMPLES::\n\n sage: from sage.repl.rich_output.display_manager import _required_threejs_version\n sage: _required_threejs_version() # needs sage.plot\n ...
class DisplayException(Exception): "\n Base exception for all rich output-related exceptions.\n\n EXAMPLES::\n\n sage: from sage.repl.rich_output.display_manager import DisplayException\n sage: raise DisplayException('foo')\n Traceback (most recent call last):\n ...\n Disp...
class OutputTypeException(DisplayException): "\n Wrong Output container.\n\n The output containers are the subclasses of\n :class:`~sage.repl.rich_output.output_basic.OutputBase` that\n contain the entire output. The display backends must create output\n containers of a suitable type depending on t...
class RichReprWarning(UserWarning): "\n Warning that is throws if a call to ``_rich_repr_`` fails.\n\n If an object implements ``_rich_repr_`` then it must return a\n value, possibly ``None`` to indicate that no rich output can be\n generated. But it may not raise an exception as it is very\n confu...
class restricted_output(): def __init__(self, display_manager, output_classes): '\n Context manager to temporarily restrict the accepted output types\n\n In the context, the output is restricted to the output\n container types listed in ``output_classes``. Additionally,\n disp...