AbjadBookConsole

class abjadbooktools.AbjadBookConsole(document_handler=None, locals=None, filename='<stdin>')

An interactive console which provides a sandboxed namespace for executing abjad-book code examples.

Lineage

digraph InheritanceGraph { graph [background=transparent, bgcolor=transparent, color=lightslategrey, fontname=Arial, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, root="__builtin__.object", splines=spline, style="dotted, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=12, penwidth=2, style="filled, rounded"]; edge [color=lightsteelblue2, penwidth=2]; subgraph cluster_abjadbooktools { graph [label=abjadbooktools]; "abjad.tools.abjadbooktools.AbjadBookConsole.AbjadBookConsole" [color=black, fontcolor=white, group=0, label=<<B>AbjadBookConsole</B>>, shape=box, style="filled, rounded"]; } subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=2, group=1, label=object, shape=box]; } subgraph cluster_code { graph [label=code]; "code.InteractiveConsole" [color=3, group=2, label=InteractiveConsole, shape=box]; "code.InteractiveInterpreter" [color=3, group=2, label=InteractiveInterpreter, shape=box]; "code.InteractiveInterpreter" -> "code.InteractiveConsole"; } "builtins.object" -> "code.InteractiveInterpreter"; "code.InteractiveConsole" -> "abjad.tools.abjadbooktools.AbjadBookConsole.AbjadBookConsole"; }

Attribute summary

errored Is true if the last line executed by the console errored.
interact([banner]) Closely emulate the interactive Python console.
push(line) Push a line to the interpreter.
raw_input([prompt]) Write a prompt and read a line.
resetbuffer() Reset the input buffer.
restore_topleveltools_dict() Restores the topleveltols module dictionary.
runcode(code) Execute a code object.
runsource(source[, filename, symbol]) Compile and run some source in the interpreter.
save_topleveltools_dict() Caches the dictionary of the topleveltools module.
showsyntaxerror([filename]) Proxies Python’s InteractiveConsole.showsyntaxerror().
showtraceback() Proxies Python’s InteractiveConsole.showtraceback().
unregister_error() Unregisters the last error registered in the current document handler.
write(data) Write a string.

Read-only properties

AbjadBookConsole.errored

Is true if the last line executed by the console errored.

Methods

(InteractiveConsole).interact(banner=None)

Closely emulate the interactive Python console.

The optional banner argument specifies the banner to print before the first interaction; by default it prints a banner similar to the one printed by the real Python interpreter, followed by the current class name in parentheses (so as not to confuse this with the real interpreter – since it’s so close!).

(InteractiveConsole).push(line)

Push a line to the interpreter.

The line should not have a trailing newline; it may have internal newlines. The line is appended to a buffer and the interpreter’s runsource() method is called with the concatenated contents of the buffer as source. If this indicates that the command was executed or invalid, the buffer is reset; otherwise, the command is incomplete, and the buffer is left as it was after the line was appended. The return value is 1 if more input is required, 0 if the line was dealt with in some way (this is the same as runsource()).

(InteractiveConsole).raw_input(prompt='')

Write a prompt and read a line.

The returned line does not include the trailing newline. When the user enters the EOF key sequence, EOFError is raised.

The base implementation uses the built-in function input(); a subclass may replace this with a different implementation.

(InteractiveConsole).resetbuffer()

Reset the input buffer.

AbjadBookConsole.restore_topleveltools_dict()

Restores the topleveltols module dictionary.

(InteractiveInterpreter).runcode(code)

Execute a code object.

When an exception occurs, self.showtraceback() is called to display a traceback. All exceptions are caught except SystemExit, which is reraised.

A note about KeyboardInterrupt: this exception may occur elsewhere in this code, and may not always be caught. The caller should be prepared to deal with it.

(InteractiveInterpreter).runsource(source, filename='<input>', symbol='single')

Compile and run some source in the interpreter.

Arguments are as for compile_command().

One several things can happen:

1) The input is incorrect; compile_command() raised an exception (SyntaxError or OverflowError). A syntax traceback will be printed by calling the showsyntaxerror() method.

2) The input is incomplete, and more input is required; compile_command() returned None. Nothing happens.

3) The input is complete; compile_command() returned a code object. The code is executed by calling self.runcode() (which also handles run-time exceptions, except for SystemExit).

The return value is True in case 2, False in the other cases (unless an exception is raised). The return value can be used to decide whether to use sys.ps1 or sys.ps2 to prompt the next line.

AbjadBookConsole.save_topleveltools_dict()

Caches the dictionary of the topleveltools module.

Because CodeBlock replaces various topleveltools function references with its own proxies, the originals must be cached so they can later be restored. Otherwise Sphinx’s autodoc extension will discover the abjad-book function proxies and not the originals.

AbjadBookConsole.showsyntaxerror(filename=None)

Proxies Python’s InteractiveConsole.showsyntaxerror().

AbjadBookConsole.showtraceback()

Proxies Python’s InteractiveConsole.showtraceback().

AbjadBookConsole.unregister_error()

Unregisters the last error registered in the current document handler.

This occurs when the interpreting code block permits errors to appear.

(InteractiveInterpreter).write(data)

Write a string.

The base implementation writes to sys.stderr; a subclass may replace this with a different implementation.