actions

Actions allow you to write code that looks like:

class RandomController(Controller):
  def GET(self):
    return Redirect("/")

This module provides a few common Action classes to use, along with a base Action class which can be inherited to create your own Actions by overriding the __init__ function.

class seshat.actions.Action[source]

Provides a base for creating a new object which represents an HTTP Status code.

All returned data is checked if it is of type Action and if so, the data/actions head is returned rather than the controllers head. This allows for a syntax like:

return NotFound()

which will cause the controller to return a 404 status code.

To create a new action, inherit this class then make a new __init__(self, *kargs) which sets self.response to a Reponse object (or just call super), and adds any headers or status changes to that Response object.

class seshat.actions.Redirect(loc)[source]

Returns a 303 See Other status code along with a location header back to the client.

Parameters:loc (str) – The location to which the client should be redirect to
class seshat.actions.BadRequest[source]

Returns a 400 BAD REQUEST

class seshat.actions.Unauthorized[source]

Returns a 401 UNAUTHORIZED back to the client

This should probably also include a WWW-Authenticate header, but I’ll leave that for later right now.

class seshat.actions.Forbidden[source]

Returns a 403 FORBIDDEN

class seshat.actions.NotFound[source]

Returns a 404 Not Found

class seshat.actions.MethodNotAllowed(allow)[source]

Returns a 405 METHOD NOT ALLOWED

Parameters:allow (list) – A list of allowable methods
class seshat.actions.InternalServerError(e=None, tb=None)[source]

Returns a 500 INTERNAL SERVER ERROR

Parameters:
  • e (Exception) – The Exception
  • tb (str) – The traceback of the exception