TESTS:
It is important that this file never be imported by default on startup by Sage, since it is very expensive, since importing Twisted is expensive. This doctest verifies that twist.py isn’t imported on startup.:
sage: os.system("sage -startuptime | grep twisted\.web2 1>/dev/null") != 0 # !=0 means not found
True
Bases: twisted.web2.resource.PostableResource
Bases: sagenb.notebook.twist.UserToplevel
Bases: sagenb.notebook.twist.Toplevel
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.PostableResource
Rendering this resource (1) empties the trash, and (2) returns a message.
EXAMPLES:
We create a notebook with a worksheet, put it in the trash, then empty the trash by creating and rendering this worksheet.:
sage: n = sagenb.notebook.notebook.load_notebook('notebook-test.sagenb')
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.move_to_trash('sage')
sage: n.worksheet_names()
['sage/0']
sage: sagenb.notebook.twist.notebook = n
sage: E = sagenb.notebook.twist.EmptyTrash('sage'); E
<sagenb.notebook.twist.EmptyTrash object at ...>
sage: from sagenb.notebook.twist import HTMLResponse
sage: ctx = HTMLResponse(stream = 'foo')
sage: ctx.headers.addRawHeader('referer', 'over there')
sage: E.render(ctx)
<sagenb.notebook.twist.RedirectResponse code=303, streamlen=None>
Finally we verify that the trashed worksheet is gone:
sage: n.worksheet_names()
[]
sage: n.delete()
Bases: sagenb.notebook.twist.Toplevel
Returns an HTMLResponse object whose ‘Content-Type’ header has been set to text/html; charset=utf-8
EXAMPLES:
sage: from sagenb.notebook.twist import HTMLResponse
sage: response = HTMLResponse(stream='<html><head><title>Test</title></head><body>Test</body></html>')
sage: response.headers
<Headers: Raw: {'content-type': ['text/html; charset=utf-8']} Parsed: {'content-type': <RecalcNeeded>}>
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.PostableResource
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.PostableResource
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.PostableResource
Bases: twisted.web2.http.Response
A redirect response class that uses the proper status code (303 See Other) instead of 301 Moved Permanently, as twisted.web2 uses. This is not cached, unlike 301.
Bases: twisted.web2.resource.PostableResource
Bases: twisted.web2.http.Response
An adapter for twisted.web2.http.Response that automatically encodes its stream into UTF-8.
INPUT:
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.Resource
Bases: sagenb.notebook.twist.SendWorksheetToFolder
Bases: sagenb.notebook.twist.SendWorksheetToFolder
Bases: twisted.web2.resource.PostableResource
Bases: sagenb.notebook.twist.SendWorksheetToFolder
Quits each selected worksheet.
Bases: sagenb.notebook.twist.SendWorksheetToFolder
Bases: twisted.web2.resource.PostableResource
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.Resource
Bases: twisted.web2.resource.PostableResource
Bases: twisted.web2.resource.PostableResource
Bases: sagenb.notebook.twist.Toplevel
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.Resource
Bases: twisted.web2.resource.Resource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.Resource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.PostableResource
Return the state number and the HTML for the main body of the worksheet, which consists of a list of cells.
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.PostableResource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.Resource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.Resource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.PostableResource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.Resource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.Resource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.Resource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.PostableResource
Deletes a notebook cell.
If there is only one cell left in a given worksheet, the request to delete that cell is ignored because there must be a least one cell at all times in a worksheet. (This requirement exists so other functions that evaluate relative to existing cells will still work, and so one can add new cells.)
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.PostableResource
Deletes a cell’s output.
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.PostableResource
Save a snapshot of a worksheet and quit.
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.PostableResource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.Resource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.Resource
Return a window that allows the user to edit the text of the worksheet with the given filename.
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.Resource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.PostableResource
Evaluate a worksheet cell.
If the request is not authorized (the requester did not enter the correct password for the given worksheet), then the request to evaluate or introspect the cell is ignored.
If the cell contains either 1 or 2 question marks at the end (not on a comment line), then this is interpreted as a request for either introspection to the documentation of the function, or the documentation of the function and the source code of the function respectively.
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.Resource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.Resource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.PostableResource
Cell introspection. This is called when the user presses the tab key in the browser in order to introspect.
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.PostableResource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.Resource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.PostableResource
Adds a new cell after a given cell.
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.PostableResource
Adds a new cell before a given cell.
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.PostableResource
Adds a new text cell after a given cell.
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.PostableResource
Adds a new cell before a given cell.
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.Resource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.Resource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.Resource
This is a child resource of the Worksheet resource. It provides a frontend to the management of worksheet publication. This management functionality includes initializational of publication, re-publication, automated publication when a worksheet saved, and ending of publication.
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.Resource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.Resource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.Resource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.PostableResource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.Resource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.PostableResource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.PostableResource
Show a list of revisions of this worksheet.
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.PostableResource
Save the contents of a worksheet after editing it in plain-text edit mode.
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.PostableResource
Save a snapshot of a worksheet then quit it.
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.PostableResource
Save a snapshot of a worksheet and quit.
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.PostableResource
Save a snapshot of a worksheet.
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.PostableResource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.PostableResource
Set the output type of the cell.
This enables the type of output cell, such as to allowing wrapping for output that is very long.
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.Resource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.Resource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.Resource
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.Resource
Return a window that allows the user to edit the text of the worksheet with the given filename.
Bases: sagenb.notebook.twist.WorksheetResource, twisted.web2.resource.Resource
Bases: twisted.web2.resource.Resource
Bases: sagenb.notebook.twist.Worksheets
Bases: twisted.web2.resource.Resource
Bases: sagenb.notebook.twist.WorksheetsByUser
EXAMPLES:
sage: from sagenb.notebook.twist import do_passwords_match
sage: do_passwords_match('momcat', 'mothercat')
False
sage: do_passwords_match('mothercat', 'mothercat')
True
Validates an email address. The implemention here is short, but it should cover the more common forms. In particular, it allows “plus addresses,” e.g.,
first.last+label@gmail.com
But it rejects several other classes, including those with comments, quoted local-parts, and/or IP address domains. For more information, please see RFC 3696, RFC 5322, and their errata.
INPUT:
OUTPUT:
EXAMPLES:
sage: from sagenb.notebook.twist import is_valid_email
sage: is_valid_email('joe@washinton.gov')
True
sage: is_valid_email('joe.washington.gov') # missing @
False
sage: is_valid_email('foo+plus@gmail.com')
True
sage: is_valid_email('foo++@gmail.com')
True
sage: is_valid_email('foo+bar+baz@gmail.com')
True
sage: is_valid_email('+plus@something.org')
True
sage: is_valid_email('hyphens-are-okay@example.ab.cd')
True
sage: is_valid_email('onlytld@com') # missing subdomain
False
sage: is_valid_email("we..are@the.borg") # consecutive dots not allowed
False
sage: is_valid_email("abcd@[12.34.56.78]") # legal, really
False
sage: is_valid_email("x@y.z") # legal but too short
False
sage: is_valid_email('"i c@nt"@do.it') # legal, really
False
sage: is_valid_email(65 * 'a' + '@lim.sup') # username too long
False
sage: is_valid_email(32 * '@..@.][.' + '!') # too long, ...
False
Return True if and only if password is valid, i.e., is between 4 and 32 characters long, doesn’t contain space(s), and doesn’t contain username.
EXAMPLES:
sage: from sagenb.notebook.twist import is_valid_password
sage: is_valid_password('uip@un7!', None)
True
sage: is_valid_password('markusup89', None)
True
sage: is_valid_password('8u7', None)
False
sage: is_valid_password('fUmDagaz8LmtonAowjSe0Pvu9C5Gvr6eKcC6wsAT', None)
False
sage: is_valid_password('rrcF !u78!', None)
False
sage: is_valid_password('markusup89', 'markus')
False
Returns whether a candidate username is valid. It must contain between 3 and 65 of these characters: letters, numbers, underscores, @, and/or dots (‘.’).
INPUT:
OUTPUT:
EXAMPLES:
sage: from sagenb.notebook.twist import is_valid_username
sage: is_valid_username('mark10')
True
sage: is_valid_username('10mark')
False
sage: is_valid_username('me')
False
sage: is_valid_username('abcde' * 13)
False
sage: is_valid_username('David Andrews')
False
sage: is_valid_username('David M. Andrews')
False
sage: is_valid_username('sarah_andrews')
True
sage: is_valid_username('TA-1')
False
sage: is_valid_username('math125-TA')
False
sage: is_valid_username('dandrews@sagemath.org')
True
Returns a rendered worksheet listing.
INPUT:
OUTPUT:
a string