The page module

The page module contains the definition of the BasePage class which provides the base functionality for implementing a page that can be served by an HTTP server.

This module also contains other classes for defining various types of pages.

The JsonPage class

Inheritance diagram of pyamp.web.http.page.JsonPage

class pyamp.web.http.page.JsonPage[source]

The HtmlPage class provides a base class that returns a page containing JSON content.

Check that all the required properties are defined.

contentType

Define the content type for the JsonPage.

classmethod get(requestHandler, path, arguments)[source]

Override the get method to return JSON data.

  • requestHandler – The request handler object
  • path – The requested path
  • arguments – The request arguments dictionary

The Argument class

Inheritance diagram of pyamp.web.http.page.Argument

class pyamp.web.http.page.Argument(argumentType, required=False, default=None)

The Argument class encapsulates the concept of an HTTP argument passed through a URL request.

Arguments can have a specific type, can be required or optional, and can have a default value if they are optional and not passed in the request.

  • argumentType – The type of the argument
  • required – True if the argument is required, False otherwise
  • default – The default value for optional Arguments
convertValue(value)

Convert the given value to the expected type of the Argument.

  • value – The value of the argument passed in the request
getDefaultValue()

Return the default value for this Argument.

isRequired()

Determine if this is a required Argument or an optional Argument.

The Header class

Inheritance diagram of pyamp.web.http.page.Header

class pyamp.web.http.page.Header(identifier, value)

The Header class provides the ability to create a specific HTTP header.

  • identifier – The header identifier
  • value – The value for the header
classmethod contentType(contentType)

Create a content type header.

  • contentType – The type of content
getId()

Get the ID for this header.

classmethod getOperatingSystem(headers)

Get the operating system from the given headers.

  • headers – The headers
getValue()

Get the value for this header.

classmethod jsonContent()

Create a JSON content type header.

classmethod location(location)

Create a location header.

  • location – The location
classmethod textHtmlContent()

Create an text/html content type header.

The FilePage class

Inheritance diagram of pyamp.web.http.page.FilePage

class pyamp.web.http.page.FilePage

The FilePage class implements a BasePage object which provides the ability for pages to return the content of a file.

Check that all the required properties are defined.

The DirectoryFilesPage class

Inheritance diagram of pyamp.web.http.page.DirectoryFilesPage

class pyamp.web.http.page.DirectoryFilesPage

The DirectoryFilesPage class provides an implementation of a FilePage which provides the ability to return any file contained within a specific directory.

This class allows the path to the locally stored files to be defined, as well as the HTML directory where the files are located. This class also provides the ability to define a set of extensions used to filter the files returned. Any file that has an extension that is contained within the list of supported extensions will be requested using this Page.

Check that all the required properties are defined.

directoryPath

The path to the locally stored files that this Page will return.

extensions

The list of extensions used to filter files that are returned.

classmethod getUrls()

Get a list of URLs which this Page supports. These URLs are used in conjunction with the urls class property.

htmlDirectory

The HTML directory name where the files are stored. This is also the path that will be prefixed to all requests for these pages.

The BasePage class

Inheritance diagram of pyamp.web.http.page.BasePage

class pyamp.web.http.page.BasePage[source]

The BasePage class contains the basic functionality that is shared among all pages.

Check that all the required properties are defined.

arguments

The arguments class defines a dictionary mapping names of arguments to actual Argument objects that this Page accepts. These can be required, or optional arguments. This provides the ability to perform error checking on the request to the page to determine if the correct number of arguments was passed in the request.

contentType

The contentType property contains the type of content contained in this Page.

errorCodes

The errorCodes property defines the list of error codes that will respond with this Page in the event that any of the error codes are encountered.

classmethod get(requestHandler, path, arguments)[source]

Get the page.

  • requestHandler – The request handler object
  • path – The requested path
  • arguments – The request arguments dictionary
classmethod getUrls()

Get a list of URLs which this Page supports. These URLs are used in conjunction with the urls class property.

Note

This function should be overridden by concrete Pages to provide a set of dynamically configured URLs.

urls

The urls property defines the list of URLs that can be used to request this Page.

Note

These URLs should all start with a forward slash.

Example:

urls = ['/index.html', /test/directory/main.html']
classmethod validatePage()

Validate all of the properties for this page.

Return True to indicate success, False to indicate failure

The HtmlPage class

Inheritance diagram of pyamp.web.http.page.HtmlPage

class pyamp.web.http.page.HtmlPage[source]

The HtmlPage class provides a base class that returns a page containing text/html content.

Check that all the required properties are defined.

contentType

Define the content type for the HtmlPage.