Package sage :: Package server :: Package notebook :: Module worksheet
[hide private]
[frames] | no frames]

Module worksheet

source code


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.

The worksheet module is responsible for running calculations in a
worksheet, spawning Sage processes that do all of the actual work and
are controlled via pexpect, and reporting on results of calculations.
The state of the cells in a worksheet is stored on the filesystem (not
in the notebook pickle sobj).

AUTHOR:
    -- William Stein



Classes [hide private]
  Worksheet
Functions [hide private]
 
initialized_sage(server, ulimit)
Return one copy of a Sage compute process that has initialization code run.
source code
 
init_sage_prestart(server, ulimit)
Set the module-scope variable _a_sage to an initialized sage server.
source code
 
one_prestarted_sage(server, ulimit)
Return a Sage interface that has been initialized.
source code
 
worksheet_filename(name, owner)
Return the relative directory name of this worksheet with given name and owner.
source code
 
ignore_prompts_and_output(aString)
Given a string s that defines an input block of code, if the first line begins in \samp{sage:} (or \samp{>>>}), strip out all lines that don't begin in either \samp{sage:} (or \samp{>>>}) or \samp{...}, and remove all \samp{sage:} (or \samp{>>>}) and \samp{...} from the beginning of the remaining lines.
source code
 
extract_text_before_first_compute_cell(text)
OUTPUT: Everything in text up to the first \{\{\{.
source code
 
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 \samp{\}\}\}} in text.
source code
 
after_first_word(s)
Return everything after the first whitespace in the string s.
source code
 
first_word(s) source code
 
format_completions_as_html(cell_id, completions) source code
 
extract_name(text) source code
 
extract_system(text) source code
 
dictify(s)
INPUT:...
source code
 
next_available_id(v)
Return smallest nonnegative integer not in v.
source code
 
convert_seconds_to_meaningful_time_span(t) source code
 
convert_time_to_string(t) source code
 
split_search_string_into_keywords(s)
The point of this function is to allow for searches like this: \begin{verbatim} "ws 7" foo bar Modular '"the" end' \end{verbatim} i.e., where search terms can be in quotes and the different quote types can be mixed.
source code
 
_get_next(s, quote='"') source code
Variables [hide private]
  whitespace = re.compile(r'\s')
  non_whitespace = re.compile(r'\S')
  INTERRUPT_TRIES = 3
  INITIAL_NUM_CELLS = 1
  WARN_THRESHOLD = 100
  SC = '\x01'
  SAGE_BEGIN = '\x01b'
  SAGE_END = '\x01e'
  SAGE_ERROR = '\x01r'
  ARCHIVED = 0
  ACTIVE = 1
  TRASH = 2
  multisession = True
  _a_sage = ['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-...
  __internal_test1 = 'def foo(x):\n "\n EXAMPLES:\n ...
  __internal_test2 = 'sage: 2 + 2\n4\n'
Function Details [hide private]

initialized_sage(server, ulimit)

source code 

Return one copy of a Sage compute process that has initialization
code run.

INPUT:
   server -- if sessions will be run via ssh on a remote account then
             this string specifies that account (passed on to the Sage
             pexpect interface).
   ulimit -- string; passed to the ulimit command before running
             the subprocess

OUTPUT:
    a pexpect interface to a local or remote copy of Sage

EXAMPLES:
    sage: S = sage.server.notebook.worksheet.initialized_sage(None,None)
    sage: S
    Sage

init_sage_prestart(server, ulimit)

source code 

Set the module-scope variable _a_sage to
an initialized sage server. 

INPUT:
    server, ulimit -- strings that are passed
    to the Sage pexpect interface constructor

EXAMPLES:
The _a_sage variable is initially set to None:
    sage: sage.server.notebook.worksheet._a_sage

We call init_sage_prestart and now _a_sage is a Sage instance:
    sage: sage.server.notebook.worksheet.init_sage_prestart(None,None)
    sage: sage.server.notebook.worksheet._a_sage
    Sage

one_prestarted_sage(server, ulimit)

source code 

Return a Sage interface that has been initialized.

INPUT:
    server, ulimit -- strings that are passed
    to the Sage pexpect interface constructor
OUTPUT:
    -- an interface to a running copy of Sage

If the global variable multisession is true, each call to
one_prestarted_sage returns a new Sage compute instance.
Otherwise it always returns the same instance.

EXAMPLES:
    sage: sage.server.notebook.worksheet.one_prestarted_sage(None,None)
    Sage
    sage: sage.server.notebook.worksheet.multisession=False
    sage: sage.server.notebook.worksheet.one_prestarted_sage(None,None) is sage.server.notebook.worksheet._a_sage
    True
    sage: sage.server.notebook.worksheet.multisession=True

worksheet_filename(name, owner)

source code 

Return the relative directory name of this worksheet
with given name and owner.

INPUT:
    name -- string, which may have spaces and funny characters, which
            are replaced by underscores. 
    owner -- string, with no spaces or funny characters
    
OUTPUT:
    string
    
EXAMPLES:
    sage: sage.server.notebook.worksheet.worksheet_filename('Example worksheet 3', 'sage10')
    'sage10/Example_worksheet_3'
    sage: sage.server.notebook.worksheet.worksheet_filename('Example#%&! work\sheet 3', 'sage10')
    'sage10/Example_____work_sheet_3'

ignore_prompts_and_output(aString)

source code 

Given a string s that defines an input block of code,
if the first line begins in \samp{sage:} (or \samp{>>>}),
strip out all lines
that don't begin in either \samp{sage:} (or \samp{>>>}) or \samp{...}, and
remove all \samp{sage:} (or \samp{>>>}) and \samp{...} 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'

after_first_word(s)

source code 

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

dictify(s)

source code 

INPUT:
    s -- a string like 'in=5, out=7'
OUTPUT:
    dict -- such as {'in':5, 'out':7}

split_search_string_into_keywords(s)

source code 

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

\begin{verbatim}
      "ws 7" foo bar  Modular  '"the" end'
\end{verbatim}

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


Variables Details [hide private]

_a_sage

Value:
['4ti2-20061025',
 'R-2.6.0',
 'atlas-3.7.37',
 'atlas-3.8.1',
 'atlas-3.8.1.p1',
 'atlas-3.8.1.p3',
 'atlas-3.8.p11',
 'atlas-3.8.p6',
...

__internal_test1

Value:
'''def foo(x):
    "
    EXAMPLES:
        sage: 2+2
        4
    "
    return x
'''