3.3 A Worksheet

Module: sage.server.notebook.worksheet

A Worksheet.

A worksheet is embedded in a webpage that is served by the Sage server. It is a linearly-ordered collections of numbered cells, where a cell is a single input/output block.

Module-level Functions

after_first_word( s)

Return everything after the first whitespace in the string s. Returns the empty string if there is nothing after the first whitespace.

Input:

s
- string
Output: a string

convert_seconds_to_meaningful_time_span( t)

convert_time_to_string( t)

dictify( s)

Input:

s
- a string like 'in=5, out=7'
Output:
dict
- such as 'in':5, 'out':7

extract_first_compute_cell( text)

Input: a block of wiki-like marked up text Output:

meta
- meta information about the cell (as a dictionary)
input
- string, the input text
output
- string, the output text
end
- integer, first position after "}}}" in text.

extract_name( text)

extract_system( text)

extract_text_before_first_compute_cell( text)

Output: Everything in text up to the first {{{.

first_word( s)

format_completions_as_html( cell_id, completions)

ignore_prompts_and_output( aString)

Given a string s that defines an input block of code, if the first line begins in "sage:" (or "»>"), strip out all lines that don't begin in either "sage:" (or "»>") or "...", and remove all "sage:" (or "»>") and "..." from the beginning of the remaining lines.

TESTS:

sage: test1 = sage.server.notebook.worksheet.__internal_test1
sage: test1 == sage.server.notebook.worksheet.ignore_prompts_and_output(test1)
True

sage: test2 = sage.server.notebook.worksheet.__internal_test2
sage: sage.server.notebook.worksheet.ignore_prompts_and_output(test2)
'2 + 2\n'

init_sage_prestart( server, ulimit)

initialized_sage( server, ulimit)

next_available_id( v)

Return smallest nonnegative integer not in v.

one_prestarted_sage( server, ulimit)

split_search_string_into_keywords( s)

The point of this function is to allow for searches like this:

          "ws 7" foo bar  Modular  '"the" end'

i.e., where search terms can be in quotes and the different quote types can be mixed.

Input:

s
- a string

Output:
list
- a list of strings

worksheet_filename( name, owner)

Class: Worksheet

class Worksheet
Worksheet( self, name, dirname, notebook, system, owner, [docbrowser=False], [pretty_print=False])

Functions: add_collaborator,$  $ add_viewer,$  $ append,$  $ append_new_cell,$  $ attach,$  $ attached_data_files,$  $ attached_files,$  $ attached_html,$  $ autosave,$  $ best_completion,$  $ cell_id_list,$  $ cell_list,$  $ cells_directory,$  $ check_cell,$  $ check_comp,$  $ check_for_system_switching,$  $ clear,$  $ clear_queue,$  $ collaborators,$  $ completions_html,$  $ compute_cell_id_list,$  $ compute_process_has_been_started,$  $ computing,$  $ conf,$  $ cython_import,$  $ data_directory,$  $ delete_cell_input_files,$  $ delete_cell_with_id,$  $ delete_cells_directory,$  $ delete_notebook_specific_data,$  $ delete_user,$  $ detach,$  $ DIR,$  $ directory,$  $ do_sage_extensions_preparsing,$  $ docbrowser,$  $ edit_save,$  $ edit_text,$  $ enqueue,$  $ eval_asap_no_output,$  $ everyone_has_deleted_this_worksheet,$  $ filename,$  $ filename_without_owner,$  $ get_cell_with_id,$  $ get_snapshot_text_filename,$  $ has_published_version,$  $ hide_all,$  $ html,$  $ html_data_options_list,$  $ html_file_menu,$  $ html_menu,$  $ html_ratings_info,$  $ html_save_discard_buttons,$  $ html_share_publish_buttons,$  $ html_time_last_edited,$  $ html_time_since_last_edited,$  $ html_title,$  $ html_worksheet_body,$  $ hunt_file,$  $ initialize_sage,$  $ input_text,$  $ interrupt,$  $ is_active,$  $ is_archived,$  $ is_doc_worksheet,$  $ is_last_id_and_previous_is_nonempty,$  $ is_owner,$  $ is_published,$  $ is_publisher,$  $ is_rater,$  $ is_trashed,$  $ javascript_confirm_before_leave,$  $ javascript_for_being_active_worksheet,$  $ javascript_for_jsmath_rendering,$  $ last_compute_walltime,$  $ last_edited,$  $ last_to_edit,$  $ load_any_changed_attached_files,$  $ load_path,$  $ move_out_of_trash,$  $ move_to_archive,$  $ move_to_trash,$  $ name,$  $ new_cell_after,$  $ new_cell_before,$  $ next_block_id,$  $ next_hidden_id,$  $ notebook,$  $ owner,$  $ ping,$  $ plain_text,$  $ postprocess_output,$  $ preparse,$  $ preparse_input,$  $ preparse_introspection_input,$  $ preparse_nonswitched_input,$  $ pretty_print,$  $ published_version,$  $ publisher,$  $ queue,$  $ queue_id_list,$  $ quit,$  $ quit_if_idle,$  $ rate,$  $ rating,$  $ ratings,$  $ record_edit,$  $ reset_interact_state,$  $ restart_sage,$  $ revert_to_last_saved_state,$  $ revert_to_snapshot,$  $ sage,$  $ satisfies_search,$  $ save,$  $ save_snapshot,$  $ set_active,$  $ set_cell_counter,$  $ set_collaborators,$  $ set_filename,$  $ set_filename_without_owner,$  $ set_is_doc_worksheet,$  $ set_name,$  $ set_not_computing,$  $ set_owner,$  $ set_pretty_print,$  $ set_published_version,$  $ set_system,$  $ set_user_view,$  $ set_worksheet_that_was_published,$  $ show_all,$  $ snapshot_data,$  $ snapshot_directory,$  $ start_next_comp,$  $ synchro,$  $ synchronize,$  $ system,$  $ time_idle,$  $ time_since_last_edited,$  $ truncated_name,$  $ uncache_snapshot_data,$  $ user_autosave_interval,$  $ user_is_collaborator,$  $ user_is_only_viewer,$  $ user_is_viewer,$  $ user_view,$  $ user_view_is,$  $ viewers,$  $ warn_about_other_person_editing,$  $ worksheet_command,$  $ worksheet_that_was_published

append_new_cell( self)

Create and append a new cell to the list of cells.

check_cell( self, id)

Check the status on computation of the cell with given id.

Input:

id
- an integer

Output:
status
- a string, either 'd' (done) or 'w' (working)
cell
- the cell with given id

check_for_system_switching( self, s, C)

Check for input cells that start with %foo, where foo is an object with an eval method.

compute_process_has_been_started( self)

Return True precisely if the compute process has been started, irregardless of whether or not it is currently churning away on a computation.

computing( self)

Return whether or not a cell is currently being run in the worksheet Sage process.

delete_cell_input_files( self)

Delete all the files code_%s.py and code_%s.spyx that are created when evaluating cells. We do this when we first start the notebook to get rid of clutter.

delete_cell_with_id( self, id)

Remove the cell with given id and return the cell before it.

delete_user( self, user)

Delete a user from having any view or ownership of this worksheet.

Input:

user
- string; the name of a user

We create a notebook with 2 users and 1 worksheet that both view.

sage: n = sage.server.notebook.notebook.Notebook('notebook-test')
sage: n.add_user('wstein','sage','wstein@sagemath.org',force=True)
sage: n.add_user('sage','sage','sage@sagemath.org',force=True)
sage: W = n.new_worksheet_with_title_from_text('Sage', owner='sage')
sage: W.add_viewer('wstein')
sage: W.owner()
'sage'
sage: W.viewers()
['wstein']

We delete the sage user from the worksheet W. This makes wstein the new owner.

sage: W.delete_user('sage')
sage: W.viewers()
['wstein']
sage: W.owner()
'wstein'

Then we delete wstein from W, which makes the owner None:

sage: W.delete_user('wstein')
sage: W.owner() is None
True
sage: W.viewers()
[]

Finally, we clean up.

sage: import shutil; shutil.rmtree('notebook-test')

edit_text( self)

Returns a plain-text version of the worksheet with {{{}}} wiki-formatting, suitable for hand editing.

enqueue( self, C, [username=None], [next=False])

Queue up the cell C for evaluation in this worksheet.

Input:

C
- a Cell
username
- the name of the user that is evaluating this cell (mainly used for loging)

NOTE: If C.is_asap() is True, then we put C as close to the beginning of the queue as possible, but after all asap cells. Otherwise, C goes at the end of the queue.

filename_without_owner( self)

Return the part of the worksheet filename after the last /, i.e., without any information about the owner of this worksheet.

input_text( self)

Return text version of the input to the worksheet.

interrupt( self)

Interrupt all currently queued up calculations.

Output:

bool
- return True if no problems interrupting calculation return False if the Sage interpreter had to be restarted.

load_any_changed_attached_files( self, s)

Modify s by prepending any necessary load commands corresponding to attached files that have changed.

new_cell_after( self, id, [input=])

Insert a new cell into the cell list after the cell with the given integer id.

Input:

id
- integer
input
- string

Output: new cell with the given input text (empty by default).

new_cell_before( self, id, [input=])

Insert a new cell into the cell list before the cell with the given integer id. If the id is not the id of any cell, inserts a new cell at the end of the cell list.

Input:

id
- integer
input
- string

Output: new cell with the given input text (empty by default).

plain_text( self, [prompts=False], [banner=True])

Return a plain-text version of the worksheet.

Input:

prompts
- if True format for inclusion in docstrings.

quit_if_idle( self, timeout)

Quit the worksheet process if it has been ``idle'' for more than timeout seconds, where idle is by definition that the worksheet has not reported back that it is actually computing. I.e., an ignored worksheet process (since the user closed their browser) is also considered idle, even if code is running.

reset_interact_state( self)

Reset the interact state of this worksheet.

restart_sage( self)

Restart Sage kernel.

sage( self)

Return a started up copy of Sage initialized for computations.

If this is a published worksheet, just return None, since published worksheets must not have any compute functionality.

Output: a Sage interface

satisfies_search( self, search)

Input: search is a string that describes a search query, i.e., a space-separated collections of words.

Output: True if the search is satisfied by self, i.e., all the words appear in the text version of self.

warn_about_other_person_editing( self, username, threshold)

Check to see if another user besides username was the last to edit this worksheet during the last threshold seconds. If so, return True and that user name. If not, return False.

Input:

username
- user who would like to edit this file.
threshold
- number of seconds, so if there was no activity on this worksheet for this many seconds, then editing is considered safe.

Special Functions: __cmp__,$  $ __getitem__,$  $ __init__,$  $ __len__,$  $ __repr__,$  $ __setstate__,$  $ _enqueue_auto,$  $ _enqueue_auto_cells,$  $ _eval_cmd,$  $ _get_last_identifier,$  $ _load_file,$  $ _new_cell,$  $ _new_text_cell,$  $ _normalized_filenames,$  $ _process_output,$  $ _record_that_we_are_computing,$  $ _save_objects,$  $ _saved_by_info,$  $ _strip_synchro_from_start_of_output

See About this document... for information on suggesting changes.