CAT-SOOP API: catsoop.dispatch

Methods for handling requests, or for routing them to the proper handlers

View Source

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 request
    • path is 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 by catsoop.wsgi.application

 

 

  • 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 request
    • url: 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 request
    • path: an "intermediate" URL (list of strings) representing a given resource

    Returns: True if the path represents a dynamic page with a content file, and False otherwise.

 

  • catsoop.dispatch.is_static (function, lines 276-287)

    Parameters:

    • context: the context associated with this request
    • path: an "intermediate" URL (list of strings) representing a given resource

    **Returns: True if the path represents a static file, and False otherwise

 

  • 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.py files
    • 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 tests
    • form_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 by catsoop.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 by catsoop.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 request
    • fname: the location on disk of the file to be sent

    Optional Parameters:

    • environment (default {}): the environment variables associated with the request
    • stream (default False): whether this file should be streamed (instead of sent as one bytestring). Regardless of the value of stream, files above 1MB are always streamed.
    • streamchunk (default 4096): 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:

    • _base to look in the CAT-SOOP source directory
    • _qtype to look in a question type's directory
    • _handler to look in a handler's directory
    • _plugin to 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 request
    • path: a list of directory names, starting with the course

    Returns: a string containing the location of the requested file on disk.