CAT-SOOP API: catsoop.dispatch
Members
-
catsoop.dispatch.content_file_location (
function, lines 166-220)Returns the location (filename on disk) of the content file for the dynamic page represented by
path.This function is responsible for looking for content files (regardless of their extension), and also for looking for pages that don't have an associated directory (i.e., pages represented by a single file).
Parameters:
context: the context associated with this requestpathis an "intermediate" URL (i.e., a list of strings starting with a course).
Returns: a string containing the location of the requested file on disk.
-
catsoop.dispatch.display_page (
function, lines 399-483)Generate the HTTP response for a dynamically-generated page.
Parameters:
context: the context associated with this request
Returns: a 3-tuple
(response_code, headers, content)as expected bycatsoop.wsgi.application
- catsoop.dispatch.get_client_ipaddr (
function, lines 637-641)
-
catsoop.dispatch.get_real_url (
function, lines 347-373)Convert a location from our internal representation to something that will actually point the web browser to the right place.
Links in CAT-SOOP can begin with
BASE,COURSE,CURRENT,_qtype,_handler,_auth, or_plugin. This function takes in a URL in that form and returns the corresponding URL.Parameters:
context: the context associated with this requesturl: a location, possibly starting with a "magic" location (e.g.,CURRENT)
Returns: a string containing a URL pointing to the corresponding resource
-
catsoop.dispatch.is_resource (
function, lines 290-301)Parameters:
context: the context associated with this requestpath: an "intermediate" URL (list of strings) representing a given resource
Returns:
Trueif the path represents a dynamic page with a content file, andFalseotherwise.
-
catsoop.dispatch.is_static (
function, lines 276-287)Parameters:
context: the context associated with this requestpath: an "intermediate" URL (list of strings) representing a given resource
**Returns:
Trueif the path represents a static file, andFalseotherwise
-
catsoop.dispatch.main (
function, lines 644-934)Generate the page content associated with this request, properly handling dynamic pages and static files.
This function is the main entrypoint into CAT-SOOP. It is responsible for:
- gathering form data
- organizing execution of
preload.pyfiles - authenticating users
- loading page source and dispatching to the proper handlers
- displaying the result
- handling errors in these steps
Parameters:
environment: a dictionary containing the environment variables associated with this request.return_context: (bool) set to True if the context dict should be returned (instead of the usual tuple) on success -- used for unit testsform_data: (dict) provided by LTI on callback, because form information is removed from environment after initial call
Returns: a 3-tuple
(response_code, headers, content)as expected bycatsoop.wsgi.application
-
catsoop.dispatch.redirect (
function, lines 55-66)Generate HTTP response that redirects the user to the specified location
Parameters:
location: the location the user should be redirected to
Returns: a 3-tuple
(response_code, headers, content)as expected bycatsoop.wsgi.application
-
catsoop.dispatch.serve_static_file (
function, lines 223-273)Generate an HTTP response to serve up a static file, or a 404 error if the file does not exist. Makes use of the browser's cache when possible.
Parameters:
context: the context associated with this requestfname: the location on disk of the file to be sent
Optional Parameters:
environment(default{}): the environment variables associated with the requeststream(defaultFalse): whether this file should be streamed (instead of sent as one bytestring). Regardless of the value ofstream, files above 1MB are always streamed.streamchunk(default4096): the size, in bytes, of the chunks in the resulting stream
-
catsoop.dispatch.static_file_location (
function, lines 69-163)Given an "intermediate" URL, return the path to that file on disk. Used by
serve_static_file.The given path is in CAT-SOOP's internal format, a list of strings. The first string represents the course in question, or one of the following:
_baseto look in the CAT-SOOP source directory_qtypeto look in a question type's directory_handlerto look in a handler's directory_pluginto look in a plugin's directory
Regardless of whether the first element is a course or one of the special values above, the function proceeds by working its way down the given directories (all elements but the last in the given list). Upon arriving in that directory, it looks for a directory called
__STATIC__containing a file with the given name.Parameters:
context: the context associated with this requestpath: a list of directory names, starting with the course
Returns: a string containing the location of the requested file on disk.