The Sage Notebook Twisted Web Server
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 doctests 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
-
class sage.server.notebook.twist.AddWorksheet
-
render(ctx)
-
class sage.server.notebook.twist.AdminToplevel(cookie, username)
-
userchild_conf
- alias of NotebookConf
-
userchild_home
- alias of WorksheetsAdmin
-
class sage.server.notebook.twist.AnonymousToplevel(cookie, username)
-
class PasswordChecker
-
__providedBy__
Special descriptor for class __provides__
The descriptor caches the implementedBy info, so that
we can get declarations for objects without instance-specific
interfaces a bit quicker.
For example:
>>> from zope.interface import Interface
>>> class IFooFactory(Interface):
... pass
>>> class IFoo(Interface):
... pass
>>> class C(object):
... implements(IFoo)
... classProvides(IFooFactory)
>>> [i.getName() for i in C.__provides__]
['IFooFactory']
>>> [i.getName() for i in C().__provides__]
['IFoo']
-
__provides__
Special descriptor for class __provides__
The descriptor caches the implementedBy info, so that
we can get declarations for objects without instance-specific
interfaces a bit quicker.
For example:
>>> from zope.interface import Interface
>>> class IFooFactory(Interface):
... pass
>>> class IFoo(Interface):
... pass
>>> class C(object):
... implements(IFoo)
... classProvides(IFooFactory)
>>> [i.getName() for i in C.__provides__]
['IFooFactory']
>>> [i.getName() for i in C().__provides__]
['IFoo']
-
__weakref__
- list of weak references to the object (if defined)
-
add_user(username, password, email, account_type='user')
-
check_username(username)
-
requestAvatarId(credentials)
-
AnonymousToplevel.render(ctx)
-
AnonymousToplevel.userchildFactory(request, name)
-
AnonymousToplevel.userchild_home
- alias of Worksheets
-
AnonymousToplevel.userchild_pub
- alias of PublicWorksheets
-
AnonymousToplevel.userchild_src
- alias of SourceBrowser
-
class sage.server.notebook.twist.CSS
-
childFactory(request, name)
-
render(ctx)
-
class sage.server.notebook.twist.CellData(worksheet, number)
-
__init__(worksheet, number)
-
childFactory(request, name)
-
render(ctx)
-
class sage.server.notebook.twist.Doc(username)
-
__init__(username)
-
childFactory(request, name)
-
render(ctx)
-
class sage.server.notebook.twist.DocLive(username)
-
__init__(username)
-
childFactory(request, name)
-
render(ctx)
-
class sage.server.notebook.twist.DocPDF
-
childFactory(request, name)
-
render(ctx)
-
class sage.server.notebook.twist.DocStatic
-
childFactory(request, name)
-
render(ctx)
-
class sage.server.notebook.twist.DownloadWorksheets(username)
-
__init__(username)
-
render(ctx)
-
class sage.server.notebook.twist.EmptyTrash(username)
-
__init__(username)
This twisted resource empties the trash of the current user when it
is rendered.
EXAMPLES: We create an instance of this resource.
sage: import sage.server.notebook.twist
sage: E = sage.server.notebook.twist.EmptyTrash('sage'); E
<sage.server.notebook.twist.EmptyTrash object at ...>
-
render(ctx)
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 = sage.server.notebook.notebook.Notebook('notebook-test')
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: sage.server.notebook.twist.notebook = n
sage: E = sage.server.notebook.twist.EmptyTrash('sage'); E
<sage.server.notebook.twist.EmptyTrash object at ...>
sage: E.render(None)
<twisted.web2.http.Response code=200, streamlen=...>
Finally we verify that the trashed worksheet is gone:
sage: n.worksheet_names()
[]
sage: n.delete()
-
class sage.server.notebook.twist.FailedToplevel(info, problem, username=None)
-
__init__(info, problem, username=None)
-
render(ctx)
-
class sage.server.notebook.twist.ForgotPassPage
-
render(request)
-
sage.server.notebook.twist.HTMLResponse(*args, **kwds)
Returns an HTMLResponse object whose ‘Content-Type’ header has been set
to ‘text/html; charset=utf-8
- EXAMPLES:
- sage: from sage.server.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>}>
-
class sage.server.notebook.twist.Help(username)
-
__init__(username)
-
render(ctx)
-
class sage.server.notebook.twist.History(username)
-
__init__(username)
-
render(ctx)
-
class sage.server.notebook.twist.Images
-
childFactory(request, name)
-
render(ctx)
-
class sage.server.notebook.twist.InvalidPage(msg, username)
-
__init__(msg, username)
-
childFactory(request, name)
-
render(ctx)
-
class sage.server.notebook.twist.Java
-
childFactory(request, name)
-
render(ctx)
-
class sage.server.notebook.twist.Javascript
-
childFactory(request, name)
-
render(ctx)
-
class sage.server.notebook.twist.JavascriptLocal
-
childFactory(request, name)
-
render(ctx)
-
class sage.server.notebook.twist.Keyboard_js
-
childFactory(request, browser_os)
-
class sage.server.notebook.twist.Keyboard_js_specific(browser_os)
-
__init__(browser_os)
-
render(ctx)
-
class sage.server.notebook.twist.ListOfUsers(username)
-
__init__(username)
-
render(ctx)
-
class sage.server.notebook.twist.LiveHistory(username)
-
__init__(username)
-
render(ctx)
-
class sage.server.notebook.twist.LoginResourceClass
-
childFactory(request, name)
-
render(ctx)
-
class sage.server.notebook.twist.Logout
-
render(ctx)
-
class sage.server.notebook.twist.Main_css
-
render(ctx)
-
class sage.server.notebook.twist.Main_js
-
render(ctx)
-
class sage.server.notebook.twist.NewWorksheet(username)
-
__init__(username)
-
render(ctx)
-
class sage.server.notebook.twist.NotImplementedWorksheetOp(op, ws)
-
__init__(op, ws)
-
render(ctx)
-
class sage.server.notebook.twist.NotebookConf(username)
-
render(ctx)
-
class sage.server.notebook.twist.NotebookSettings(username)
-
__init__(username)
-
render(ctx)
-
class sage.server.notebook.twist.ProcessNotebookSettings
-
render(ctx)
-
class sage.server.notebook.twist.ProcessUserSettings
-
render(ctx)
-
class sage.server.notebook.twist.PublicWorksheets(username)
-
__init__(username)
-
childFactory(request, name)
-
render(ctx)
-
class sage.server.notebook.twist.PublicWorksheetsHome(username)
-
__init__(username)
-
childFactor(request, name)
-
class sage.server.notebook.twist.PublishWorksheetRevision(worksheet, rev)
-
__init__(worksheet, rev)
-
render(ctx)
-
class sage.server.notebook.twist.RedirectLogin
-
childFactory(request, name)
-
render(ctx)
-
class sage.server.notebook.twist.RegConfirmation
-
render(request)
-
class sage.server.notebook.twist.RegistrationPage(userdb)
-
__init__(userdb)
-
render(request)
-
class sage.server.notebook.twist.Reset_css
-
render(ctx)
-
class sage.server.notebook.twist.RevertToWorksheetRevision(worksheet, rev)
-
__init__(worksheet, rev)
-
render(ctx)
-
class sage.server.notebook.twist.SageTex(username)
-
__init__(username)
-
childFactory(request, name)
-
render(ctx)
-
class sage.server.notebook.twist.SendWorksheetToActive(username)
-
action(W)
-
class sage.server.notebook.twist.SendWorksheetToArchive(username)
-
action(W)
-
class sage.server.notebook.twist.SendWorksheetToFolder(username)
-
__init__(username)
-
action(W)
-
render(ctx)
-
class sage.server.notebook.twist.SendWorksheetToStop(username)
Quits each selected worksheet.
-
action(W)
-
class sage.server.notebook.twist.SendWorksheetToTrash(username)
-
action(W)
-
class sage.server.notebook.twist.SettingsPage(username)
-
__init__(username)
-
render(request)
-
class sage.server.notebook.twist.Source(path, username)
-
__init__(path, username)
-
childFactory(request, name)
-
render(ctx)
-
class sage.server.notebook.twist.SourceBrowser(username)
-
__init__(username)
-
childFactory(request, name)
-
render(ctx)
-
class sage.server.notebook.twist.Toplevel(cookie, username)
-
__init__(cookie, username)
-
childFactory(request, name)
-
render(ctx)
-
userchildFactory(request, name)
-
class sage.server.notebook.twist.TrivialResource
-
render(ctx)
-
class sage.server.notebook.twist.Upload(username)
-
__init__(username)
-
render(ctx)
-
class sage.server.notebook.twist.UploadWorksheet(username)
-
__init__(username)
-
render(ctx)
-
class sage.server.notebook.twist.UserToplevel(cookie, username)
-
render(request)
-
userchildFactory(request, name)
-
userchild_doc
- alias of Doc
-
userchild_download_worksheets
- alias of DownloadWorksheets
-
userchild_emptytrash
- alias of EmptyTrash
-
userchild_help
- alias of Help
-
userchild_history
- alias of History
-
userchild_home
- alias of Worksheets
-
userchild_live_history
- alias of LiveHistory
-
userchild_new_worksheet
- alias of NewWorksheet
-
userchild_notebook_settings
- alias of NotebookSettings
-
userchild_pub
- alias of PublicWorksheets
-
userchild_sagetex
- alias of SageTex
-
userchild_send_to_active
- alias of SendWorksheetToActive
-
userchild_send_to_archive
- alias of SendWorksheetToArchive
-
userchild_send_to_stop
- alias of SendWorksheetToStop
-
userchild_send_to_trash
- alias of SendWorksheetToTrash
-
userchild_settings
- alias of SettingsPage
-
userchild_src
- alias of SourceBrowser
-
userchild_upload
- alias of Upload
-
userchild_upload_worksheet
- alias of UploadWorksheet
-
userchild_users
- alias of ListOfUsers
-
class sage.server.notebook.twist.Worksheet(name, username)
-
childFactory(request, op)
-
render(ctx)
-
class sage.server.notebook.twist.WorksheetFile(path, username)
-
__init__(path, username)
-
childFactory(request, name)
-
render(ctx=None)
-
class sage.server.notebook.twist.WorksheetResource(name, username)
-
__init__(name, username)
-
id(ctx)
-
class sage.server.notebook.twist.Worksheet_alive(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_cell_update(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_cells(name, username)
-
childFactory(request, segment)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_conf(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_copy(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_data(name, username)
-
childFactory(request, name)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_datafile(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_delete_all_output(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_delete_cell(name, username)
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.)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_discard_and_quit(name, username)
Save a snapshot of a worksheet and quit.
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_do_upload_data(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_download(name, username)
-
childFactory(request, name)
-
class sage.server.notebook.twist.Worksheet_edit(name, username)
Return a window that allows the user to edit the text of the
worksheet with the given filename.
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_edit_published_page(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_eval(name, username)
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.
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_hide_all(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_input_settings(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_interrupt(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_introspect(name, username)
Cell introspection. This is called when the user presses the tab
key in the browser in order to introspect.
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_invite_collab(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_link_datafile(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_new_cell_after(name, username)
Adds a new cell after a given cell.
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_new_cell_before(name, username)
Adds a new cell before a given cell.
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_new_text_cell_after(name, username)
Adds a new text cell after a given cell.
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_new_text_cell_before(name, username)
Adds a new cell before a given cell.
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_plain(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_pretty_print(name, username)
-
childFactory(request, enable)
-
class sage.server.notebook.twist.Worksheet_print(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_publish(name, username)
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.
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_quit_sage(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_rate(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_rating_info(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_rename(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_restart_sage(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_revert_to_last_saved_state(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_revisions(name, username)
Show a list of revisions of this worksheet.
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_save(name, username)
Save the contents of a worksheet after editing it in plain-text
edit mode.
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_save_and_close(name, username)
Save a snapshot of a worksheet then quit it.
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_save_and_quit(name, username)
Save a snapshot of a worksheet and quit.
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_save_snapshot(name, username)
Save a snapshot of a worksheet.
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_savedatafile(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_set_cell_output_type(name, username)
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.
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_settings(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_share(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_show_all(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_system(name, username)
-
childFactory(request, system)
-
class sage.server.notebook.twist.Worksheet_text(name, username)
Return a window that allows the user to edit the text of the
worksheet with the given filename.
-
render(ctx)
-
class sage.server.notebook.twist.Worksheet_upload_data(name, username)
-
render(ctx)
-
class sage.server.notebook.twist.Worksheets(username)
-
__init__(username)
-
childFactory(request, name)
-
render(ctx)
-
class sage.server.notebook.twist.WorksheetsAdmin(username)
-
childFactory(request, name)
-
class sage.server.notebook.twist.WorksheetsByUser(user, username)
-
__init__(user, username)
-
childFactory(request, name)
-
render(ctx)
-
render_list(ctx)
-
class sage.server.notebook.twist.WorksheetsByUserAdmin(user, username)
-
render(ctx)
-
sage.server.notebook.twist.do_passwords_match(pass1, pass2)
EXAMPLES:
sage: from sage.server.notebook.twist import do_passwords_match
sage: do_passwords_match('momcat', 'mothercat')
False
sage: do_passwords_match('mothercat', 'mothercat')
True
-
sage.server.notebook.twist.doc_worksheet()
-
sage.server.notebook.twist.encode_list(v)
-
sage.server.notebook.twist.gzip_handler(request)
- Add gzip compression to the request if it makes sense.
-
sage.server.notebook.twist.init_updates()
-
sage.server.notebook.twist.is_valid_email(email)
from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65215
EXAMPLES:
sage: from sage.server.notebook.twist import is_valid_email
sage: is_valid_email('joe@washinton.gov')
True
sage: is_valid_email('joe.washington.gov')
False
-
sage.server.notebook.twist.is_valid_password(password, username)
Return True if and only if password is valid, i.e.,
is between 6 and 32 characters long, doesn’t contain space(s), and
doesn’t contain username.
EXAMPLES:
sage: from sage.server.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
-
sage.server.notebook.twist.is_valid_username(username)
Returns True if and only if username is valid,
i.e., starts with a letter, is between 4 and 32 characters long,
and contains only letters, numbers, underscores, and and one dot
(.).
EXAMPLES:
sage: from sage.server.notebook.twist import is_valid_username
username must start with a letter
sage: is_valid_username('mark10')
True
sage: is_valid_username('10mark')
False
username must be between 4 and 32 characters long
sage: is_valid_username('bob')
False
sage: is_valid_username('I_love_computer_science_and_maths') #33 characters long
False
username must not have more than one dot (.)
sage: is_valid_username('david.andrews')
True
sage: is_valid_username('david.m.andrews')
False
sage: is_valid_username('math125.TA.5')
False
username must not have any spaces
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')
False
-
sage.server.notebook.twist.message(msg, cont=None)
-
sage.server.notebook.twist.notebook_idle_check()
-
sage.server.notebook.twist.notebook_save_check()
-
sage.server.notebook.twist.notebook_updates()
-
sage.server.notebook.twist.redirect(url)
-
sage.server.notebook.twist.render_worksheet_list(args, pub, username)
Returns a rendered worksheet listing.
INPUT:
- args - ctx.args where ctx is the dict passed
into a resource’s render method
- pub - boolean, True if this is a listing of
public worksheets
- username - the user whose worksheets we are
listing
OUTPUT: a string
-
sage.server.notebook.twist.set_cookie(cookie)
-
sage.server.notebook.twist.user_type(username)
-
sage.server.notebook.twist.word_wrap_cols()
-
sage.server.notebook.twist.worksheet_revision_publish(worksheet, rev, username)
-
sage.server.notebook.twist.worksheet_revision_revert(worksheet, rev, username)