toyz.web package

Submodules

toyz.web.app module

Runs the webapp for Toyz

class toyz.web.app.AuthHandler

Subclass for all secure handlers.

get_current_user()

Load the name of the current user

class toyz.web.app.AuthLoginHandler(application, request, **kwargs)

Bases: toyz.web.app.AuthHandler, tornado.web.RequestHandler

get()

Send the login.html page to the client

initialize()

When the handler is initialized, set the path to the template that needs to be rendered

post()

Load the user_id and password passed to the server from the client and check authentication

set_current_user(user_id)

Send a secure cookie to the client to keep the user logged into the system

Parameters
user_id (string ): User id of the current user
class toyz.web.app.AuthLogoutHandler(application, request, **kwargs)

Bases: tornado.web.RequestHandler

get()

Clear the users cookie and log them out

class toyz.web.app.AuthMainHandler(application, request, **kwargs)

Bases: toyz.web.app.MainHandler

toyz.web.app.MainHandler extensions when using secure cookies.

get(*args, **kwargs)
class toyz.web.app.AuthStaticFileHandler(application, request, **kwargs)

Bases: toyz.web.app.AuthHandler, tornado.web.StaticFileHandler

Handles static files and checks for a secure user cookie and that the user has permission to view the file.

get(*args, **kwargs)
validate_absolute_path(root, full_path)

Check that the user has permission to view the file

class toyz.web.app.AuthToyz3rdPartyHandler(application, request, **kwargs)

Bases: toyz.web.app.AuthHandler, toyz.web.app.Toyz3rdPartyHandler

get(*args, **kwargs)
class toyz.web.app.AuthToyzStaticFileHandler(application, request, **kwargs)

Bases: toyz.web.app.AuthHandler, toyz.web.app.ToyzStaticFileHandler

Secure handler for all toyz added to the application. This handles security, such as making sure the user has a registered cookie and that the user has acces to the requested files.

get(*args, **kwargs)
class toyz.web.app.AuthToyzTemplateHandler(application, request, **kwargs)

Bases: toyz.web.app.AuthHandler, toyz.web.app.ToyzTemplateHandler

get(*args, **kwargs)
class toyz.web.app.AuthToyzWorkspaceHandler(application, request, **kwargs)

Bases: toyz.web.app.AuthHandler, toyz.web.app.ToyzWorkspaceHandler

get(*args, **kwargs)
class toyz.web.app.MainHandler(application, request, **kwargs)

Bases: toyz.web.app.ToyzHandler, tornado.web.RequestHandler

Main Handler when user connects to localhost:8888/ (or whatever port is used by the application).

get(*args, **kwargs)

Render the main web page

get_template_path()

Get the path for the main webpage

initialize(template_name, template_path)

Initialize handler

class toyz.web.app.Toyz3rdPartyHandler(application, request, **kwargs)

Bases: toyz.web.app.ToyzHandler, tornado.web.StaticFileHandler

get(path)
class toyz.web.app.ToyzHandler

Handler for Toyz extensions.

get_current_user()

Load the name of the current user

get_toyz_path(path, path_type)

Given a toyz path, return the root path for the toy.

get_user_id()
get_user_theme()
class toyz.web.app.ToyzStaticFileHandler(application, request, **kwargs)

Bases: toyz.web.app.ToyzHandler, tornado.web.StaticFileHandler

Static file handler for all toyz added to the application.

parse_url_path(url_path)
class toyz.web.app.ToyzTemplateHandler(application, request, **kwargs)

Bases: toyz.web.app.ToyzHandler, tornado.web.RequestHandler

  • Not yet implemented*
get(*args, **kwargs)
get_template_path()
initialize(**options)

Initialize handler

class toyz.web.app.ToyzWebApp

Bases: tornado.web.Application

Web application that runs on the server. Along with setting up the Tornado web application, it also processes jobs sent to the server from clients.

close_session(session)

Close a websocket session and delete any temporary files or directories created during the session. To help ensure all temp files are deleted (in case of a server or client error), if the user doesn’t have any open session his/her temp directory is also deleted.

find_open_port(port)

Begin at port and search for an open port on the server

new_session(user_id, websocket, session_id=None)

Open a new websocket session for a given user

Parameters
user_id ( toyz.utils.core.ToyzUser ): User id websocket (toyz.web.app.WebSocketHandler ): new websocket opened
update(attr)

Certain properties of the application may be changed by an external job, for example a user may change his/her password, a new user may be created, a setting may be changed, etc. When this happens the job notifies the application that something has changed and this function is called to reload the property.

Parameters
  • attr (string ): Name of attribute that needs to be updated. So far only toyz_settings is supported
class toyz.web.app.ToyzWorkspaceHandler(application, request, **kwargs)

Bases: toyz.web.app.ToyzHandler, tornado.web.RequestHandler

get(path)

Load the workspace

get_template_path()
initialize()
class toyz.web.app.WebSocketHandler(application, request, **kwargs)

Bases: tornado.websocket.WebSocketHandler

Websocket that handles jobs sent to the server from clients

on_close()

Called when the websocket is closed. This function calls the applications -toyz.web.app.ToyzWebApp.close_session)() function.

on_message(message)

Called when the websocket recieves a message from the client. The user and session information is then extracted and processed before running the job initiated by the client. Only modules and toyz that the user has permission to view are accepted, all others return a toyz.utils.errors.ToyzJobError .

Parameters
open(session_id=None)

Called when a new websocket is opened

Parameters
*args: Currently no arguments are passed to this function
send_response(remote_pipe, events, error=None)
toyz.web.app.init_web_app()

Run the web application on the server

toyz.web.app.job_process(session_id, pipe, websocket_pipe)

Process created for the websocket. When a job is received from the Toyz Application it is run in this process and a response is sent.

toyz.web.tasks module

While each toy may contain a large number of functions, only the functions located in the tasks.py file will be callable from the job queue.

toyz.web.tasks.add_new_user(toyz_settings, tid, params)

Add a new user to the toyz application.

Parameters
  • toyz_settings ( toyz.utils.core.ToyzSettings): Settings for the toyz application
  • tid (string ): Task ID of the client user running the task
  • params (dict ): Any parameters sent by the client (see params below)
Params
  • user_id (string ): Id of user to add
Response
  • id: ‘notification’
  • func: ‘add_new_user’
  • msg: ‘User/Group added correctly’
toyz.web.tasks.change_pwd(toyz_settings, tid, params)

Change a users password.

Parameters
  • toyz_settings ( toyz.utils.core.ToyzSettings): Settings for the toyz application
  • tid (string ): Task ID of the client user running the task
  • params (dict ): Any parameters sent by the client (see params below)
Params
  • current_pwd (string ): Users current password. Must match the password on file or an exception is raised
  • new_pwd (string ): New password
  • confirm_pwd (string ): Confirmation of the the new password. If new_pwd and confirm_pwd do not match, an exception is raised
Response
  • id: ‘notification’
  • func: ‘change_pwd’
  • msg: ‘Password changed successfully’
toyz.web.tasks.create_paths(toyz_settings, tid, params)

Creates a new path on the server (if it does not already exist).

Parameters
  • toyz_settings ( toyz.utils.core.ToyzSettings): Settings for the toyz application
  • tid (string ): Task ID of the client user running the task
  • params (dict ): Any parameters sent by the client (see params below)
Params
  • path (string ): path to create on the server
Response
id: ‘create_folder’, status (string ): ‘success’, path (string ): path created on the server
toyz.web.tasks.get_file_info(toyz_settings, tid, params)

Get information about an image file

toyz.web.tasks.get_img_data(toyz_settings, tid, params)

Get data from an image or FITS file

toyz.web.tasks.get_img_info(toyz_settings, tid, params)

Map a large image into a set of tiles that make up the larger image

toyz.web.tasks.get_img_tile(toyz_settings, tid, params)

Load a tile from a larger image and notify the client it has been created

toyz.web.tasks.get_src_columns(toyz_settings, tid, params)

Get column information from multiple sources and return to a workspace

toyz.web.tasks.get_tile_info(toyz_settings, tid, params)

Get new tiles that need to be loaded

toyz.web.tasks.get_workspace_info(toyz_settings, tid, params)

Get I/O settings for different packages (pure python, numpy, pandas, etc) and other settings for the current users workspaces

toyz.web.tasks.get_workspace_sharing(toyz_settings, tid, params)

Get shared workspace settings for users and groups

Params
  • work_id ( string ): name of the workspace
toyz.web.tasks.load_data_file(toyz_settings, tid, params)

Load a data file given a set of parameters from the browser, initialized by get_io_info.

toyz.web.tasks.load_directory(toyz_settings, tid, params)

Used by the file browser to load the folders and files in a given path.

Parameters
  • toyz_settings ( toyz.utils.core.ToyzSettings): Settings for the toyz application
  • tid (string ): Task ID of the client user running the task
  • params (dict ): Any parameters sent by the client (see params below)
Params
  • path (string ): Path to search
Response
  • id: ‘directory’
  • path (string ): path passed to the function
  • shortcuts (dict ): Dictionary of shortcut_name: shortcut_path ‘s for the user
  • folders (list of strings): folders contained in the path
  • files (list of strings): files contained in the path
  • parent (string ): parent directory of current path
toyz.web.tasks.load_user_info(toyz_settings, tid, params)

Load info for a given user from the database

Parameters
  • toyz_settings ( toyz.utils.core.ToyzSettings): Settings for the toyz application
  • tid (string ): Task ID of the client user running the task
  • params (dict ): Any parameters sent by the client (see params below)
Params
  • user_id or group_id (string ): User or group to load parameters for
  • user_attr (list ): List of user attributes to load
Response
  • id: ‘user_info’
  • Each attribute requested by the client is also returned as a key in the response
toyz.web.tasks.load_user_settings(toyz_settings, tid, params)

Load settings for a given user

Parameters
  • toyz_settings ( toyz.utils.core.ToyzSettings): Settings for the toyz application
  • tid (string ): Task ID of the client user running the task
  • params (dict ): Any parameters sent by the client (None for this function)
Response for all users
  • id: ‘user_settings’
  • shortcuts (dict ): Dictionary of shortcut_name: shortcut_path ‘s for the user
  • workspaces (dict ): Dictionary of workspace_name: workspace_settings for the user
Additional response keys for users in the modify_toyz group
  • modules (list ): List of toyz modules the user can run
  • toyz (dict ): Dictionary of toy_name: path_to_toy ‘s that the user can run
Additional reponse keys for admins
  • config (dict ): Configuration settings for the application
  • db (dict ): Database settings
  • web (dict): Web settings
  • security (dict ): Security settings
  • users (list ): list of all users in the database
  • groups (list ): list of all groups in the database
  • user_settings (dict ): Settings for a specified user (initially the admin)
  • group_settings (dict ): Settings for a specified group (initially the admin group)
toyz.web.tasks.load_workspace(toyz_settings, tid, params)

Load a workspace

toyz.web.tasks.old_load_data_file(toyz_settings, tid, params)

Load a data file given a set of parameters from the browser, initialized by get_io_info.

toyz.web.tasks.remove_datapoints(toyz_settings, tid, params)

Remove a point from a data source

toyz.web.tasks.reset_pwd(toyz_settings, tid, params)

Reset a users password

toyz.web.tasks.save_data_file(toyz_settings, tid, params)

Save a data source.

toyz.web.tasks.save_user_info(toyz_settings, tid, params)

Save a users info. If any admin settings are being changed, ensures that the user is in the admin group.

Parameters
  • toyz_settings ( toyz.utils.core.ToyzSettings): Settings for the toyz application
  • tid (string ): Task ID of the client user running the task
  • params (dict ): Any parameters sent by the client (see params below)

Params can be any settings the user has permission to set on the server.

Response
  • id: ‘notification’
  • func: ‘save_user_info’
  • msg: ‘Settings saved for <user_id>’
toyz.web.tasks.save_workspace(toyz_settings, tid, params)

Save a workspace for later use

toyz.web.tasks.update_toyz_settings(toyz_settings, tid, params)

Update the toyz settings for the application

toyz.web.tasks.update_workspace(toyz_settings, tid, params)

Update user permissions or delete a workspace

Params
  • work_id ( string ): name of the workspace

  • type ( string ): type of update
    • Can be update to update user permissions or delete to remove the workspace
  • users ( dict, optional ):
    • Dict of permissions for other users
    • Required if the update type is update
  • groups ( dict, optional ):
    • Dict of permissions for other groups
    • Required if the update type is update
Response
  • id: ‘notification’
  • status: ‘success’ (if the update is successfully saved in the database)

Module contents