Module: sage.interfaces.expect
Common Interface Functionality
See the examples in the other sections for how to use specific interfaces. The interface classes all derive from the generic interface that is described in this section.
Author Log:
Module-level Functions
cmd) |
x) |
parent, x) |
Class: AsciiArtString
self, x) |
Special Functions: __init__,
__repr__
Class: Expect
self, name, prompt, [command=None], [server=None], [server_tmpdir=None], [ulimit=None], [maxread=100000], [script_subdirectory=], [restart_on_ctrlc=False], [verbose_start=False], [init_code=[]], [max_startup_time=30], [logfile=None], [eval_using_file_cutoff=0], [do_cleaner=True], [remote_cleaner=False], [path=None]) |
Functions: call,
clear,
clear_prompts,
console,
cputime,
eval,
execute,
expect,
function_call,
get,
get_using_file,
help,
interact,
interrupt,
is_local,
is_remote,
is_running,
name,
new,
path,
pid,
quit,
set,
user_dir
self, var) |
Clear the variable named var.
self) |
CPU time since this process started running.
self, code, [strip=True], [synchronize=False]) |
Input:
self, var) |
Get the value of the variable var.
self) |
This allows you to interactively interact with the child interpreter. Press Ctrl-D or type 'quit' or 'exit' to exit and return to SAGE.
Note: This is completely different than the console() member function. The console function opens a new copy of the child interepreter, whereas the interact function gives you interactive access to the interpreter that is being used by SAGE. Use sage(xxx) or interpretername(xxx) to pull objects in from sage to the interpreter.
self) |
Return True if self is currently running.
self, [verbose=False], [timeout=0.25]) |
sage: a = maxima('y') sage: maxima.quit() sage: a._check_valid() Traceback (most recent call last): ... ValueError: The maxima session in which this object was defined is no longer running.
self, var, value) |
Set the variable var to the given value.
Special Functions: __call__,
__cmp__,
__init__,
_assign_symbol,
_before,
_change_prompt,
_coerce_from_special_method,
_coerce_impl,
_contains,
_continuation_prompt,
_crash_msg,
_create,
_do_cleaner,
_equality_symbol,
_eval_line,
_eval_line_using_file,
_expect_expr,
_false_symbol,
_get,
_get_tmpfile_from_server,
_greaterthan_symbol,
_install_hints,
_install_hints_ssh,
_install_hints_ssh_through_gate,
_interrupt,
_is_true_string,
_keyboard_interrupt,
_left_list_delim,
_lessthan_symbol,
_local_tmpfile,
_next_var_name,
_object_class,
_post_interact,
_post_process_from_file,
_pre_interact,
_quit_string,
_read_in_file_command,
_remote_tmpdir,
_remote_tmpfile,
_remove_tmpfile_from_server,
_repr_,
_right_list_delim,
_send,
_send_tmpfile_to_server,
_sendstr,
_so_far,
_start,
_synchronize,
_true_symbol
self, x) |
Create a new object in self from x.
The object X returned can be used like any SAGE object, and wraps an object in self. The standard arithmetic operators work. Morever if foo is a function then X.foo(y,z,...) calls foo(X, y, z, ...) and returns the corresponding object.
self, other) |
Compare to pseudo-tty interfaces. To interfaces compare equal if and only if they are identical objects (this is a critical constrait so that caching of representations of objects in interfaces works correctly). Otherwise they are never equal.
sage: sage.calculus.calculus.maxima == maxima False sage: maxima == maxima True
self) |
Return the previous string that was send through the interface.
sage: singular(2+3) 5 sage: singular._before() 'print(sage...); 5 '
self, x) |
Tries to coerce to self by calling a special underscore method.
If no such method is defined, raises an AttributeError instead of a TypeError.
self) |
Show a message if the interface crashed.
sage: singular._crash_msg() Singular crashed -- automatically restarting.
sage: singular('2+3') 5 sage: import os sage: singular._sendstr('quit; ') # make it so that singular appears to die. sage: singular('2+3') Singular crashed -- automatically restarting. 5
self, [expr=None], [timeout=None]) |
Wait for a given expression expr (which could be a regular expression or list of regular expressions) to appear in the output for at most timeout seconds.
Use r._expect.before
to see what was put in the output
stream before the expression.
Input:
We test all of this using the R interface. First we put 10 + 15 in the input stream:
sage: r._sendstr('abc <- 10 +15;\n')
Here an exception is raised because 25 hasn't appeared yet in the output stream. The key thing is that this doesn't lock, but instead quickly raises an exception.
sage: t = walltime() sage: try: r._expect_expr('25', timeout=0.5) ... except: print 'Did not get expression' Did not get expression
A quick consistency check on the time that the above took:
sage: w = walltime(t); w > 0.4 and w < 10 True
We tell R to print abc, which equals 25.
sage: r._sendstr('abc;\n')
Now 25 is in the output stream, so we can wait for it.
sage: r._expect_expr('25')
This gives us everything before the 25.
sage: r._expect.before 'abc;\r\n[1] '
self) |
Hints for installing needed slave program on your computer.
There are no hints by default.
self) |
Hints for installing passwordless authentication on your computer...
self) |
Hints for installing passwordless authentication through a gate
self, str) |
Send a string to the pexpect interface, autorestarting the expect interface if anything goes wrong.
Input:
We illustrate this function using the R interface:
sage: r._sendstr('a <- 10; ') sage: r.eval('a') '[1] 10'
We illustrate using the singular interface:
sage: singular._sendstr('int i = 5;') sage: singular('i') 5
self, [wait=0.1], [alternate_prompt=None]) |
Return whether done and output so far and new output since last time called.
self) |
Synchronize pexpect interface.
This put a random integer (plus one!) into the output stream, then waits for it, thus resynchronizing the stream. If the random integer doesn't appear within 1 second, the interface is sent interrupt signals.
This way, even if you somehow left the interface in a busy state computing, calling _synchronize gets everything fixed.
We observe nothing, just as it should be:
sage: r._synchronize()
TESTS: This illustrates a synchronization bug being fixed (thanks to Simon King and David Joyner for tracking this down):
sage: R.<x> = QQ[]; f = x^3 + x + 1; g = x^3 - x - 1; r = f.resultant(g); gap(ZZ); singular(R) Integers // characteristic : 0 // number of vars : 1 // block 1 : ordering lp // : names x // block 2 : ordering C
Class: ExpectElement
self, parent, value, [is_name=False]) |
Functions: attribute,
bool,
gen,
hasattr,
name,
sage
self, attrname) |
If this wraps the object x in the system, this returns the object x.attrname. This is useful for some systems that have object oriented attribute access notation.
sage: g = gap('SO(1,4,7)') sage: k = g.InvariantQuadraticForm() sage: k.attribute('matrix') [ [ 0*Z(7), Z(7)^0, 0*Z(7), 0*Z(7) ], [ 0*Z(7), 0*Z(7), 0*Z(7), 0*Z(7) ], [ 0*Z(7), 0*Z(7), Z(7), 0*Z(7) ], [ 0*Z(7), 0*Z(7), 0*Z(7), Z(7)^0 ] ]
sage: e = gp('ellinit([0,-1,1,-10,-20])') sage: e.attribute('j') -122023936/161051
self, attrname) |
Returns whether the given attribute is already defined by this object, and in particular is not dynamically generated.
self, [new_name=None]) |
Returns the name of self. If new_name is passed in, then this function returns a new object identitical to self whose name is new_name.
Note that this can overwrite existing variables in the system.
sage: x = r([1,2,3]); x [1] 1 2 3 sage: x.name() 'sage3' sage: x = r([1,2,3]).name('x'); x [1] 1 2 3 sage: x.name() 'x'
sage: s5 = gap.SymmetricGroup(5).name('s5') sage: s5 SymmetricGroup( [ 1 .. 5 ] ) sage: s5.name() 's5'
self) |
Attempt to return a SAGE version of this object.
Special Functions: __bool__,
__call__,
__cmp__,
__contains__,
__float____,
__getitem__,
__init__,
__int__,
__iter__,
__len__,
__long__,
__pow__,
__reduce__,
__repr__,
_add_,
_check_valid,
_div_,
_integer_,
_latex_,
_matrix_,
_mul_,
_r_action,
_rational_,
_reduce,
_sage_,
_sage_doc_,
_sub_,
_vector_
self, n) |
sage: a = maxima('2') sage: a^(3/4) 2^(3/4)
self) |
Check that this object is valid, i.e., the session in which this object is defined is still running. This is relevant for interpreters that can't be interrupted via ctrl-C, hence get restarted.
Class: ExpectFunction
self, parent, name) |
Special Functions: __call__,
__init__,
__repr__
Class: FunctionElement
self, obj, name) |
Functions: help
Special Functions: __call__,
__init__,
__repr__,
_sage_doc_
Class: gc_disabled
sage: import gc sage: from sage.interfaces.expect import gc_disabled sage: gc.isenabled() True sage: with gc_disabled(): ... print gc.isenabled() ... with gc_disabled(): ... print gc.isenabled() ... print gc.isenabled() False False False sage: gc.isenabled() True
Special Functions: __enter__,
__exit__
Class: PropTypeError
See About this document... for information on suggesting changes.