The web module

The web module contains classes and methods to perform tasks pertaining to the world wide web, such as accessing the content of a web page.

The hacking module

Contains the Hacking class which provides functions pertaining to hacking web sites.

class pyamp.web.hacking.Hacking[source]

Contains methods pertaining to Hacking.

classmethod findAdminPage(baseUrl, adminFile=None)[source]

Attempt to find an admin page for a website using the configured list of possible admin names.

  • baseUrl - The base URL to look for an admin page
  • adminFile - The list of possible admin names

The web module

The web module provides classes, and functions which provide various functionality respective to websites.

class pyamp.web.web.UrlRequest[source]

The UrlRequest provides methods for requesting webpages.

classmethod authenticate(username, password, url)[source]

Request a page that requires authentication.

classmethod get(url)[source]

Get the content of a page.

classmethod request(url)[source]

Request a page.

The http module

The http module contains modules pertaining to creating an HTTP server to serve pages upon request.

The constants module

The constants module contains classes which define constants relating to HTTP data.

class pyamp.web.http.constants.ContentTypes[source]

The ContentTypes class contains constants pertaining to different types of content.

Bmp

A BMP image content.

Css

CSS content.

Gif

A GIF image content.

Ico

An ICO image content.

JavaScript

JavaScript content.

Json

JSON content.

Png

An PNG image content.

TextHtml

Standard text HTML content.

class pyamp.web.http.constants.HeaderIds[source]

The HeaderIds class contains constants pertaining to header identifiers.

ContentType

The content type header id.

Location

The location header id.

UserAgent

The user agent header id.

class pyamp.web.http.constants.Keys

The Keys class defines constants that are used as keys to access certain dictionary values.

ErrorMessage

The key for the entry containing the error message.

class pyamp.web.http.constants.OperatingSystems[source]

The OperatingSystems class contains constants pertaining to the strings used to identify various operating systems.

BeOS

The BeOS OS.

Linux

The Linux OS.

MacOS

The Mac OS.

OS2

The OS/2 OS.

OpenBSD

The OpenBSD OS.

QNX

The QNX OS.

SearchBot

The SearchBot OS.

SunOS

The Sun OS OS.

Windows2000

The Windows 2000 OS.

Windows3_11

The Windows 3.11 OS.

Windows7

The Windows 7 OS.

Windows95

The Windows 95 OS.

Windows98

The Windows 98 OS.

WindowsME

The Windows ME OS.

WindowsNT4

The Windows NT 4.0 OS.

WindowsServer2003

The Windows Server 2003 OS.

WindowsVista

The Windows Vista OS.

WindowsXP

The Windows XP OS.

class pyamp.web.http.constants.StatusCodes[source]

The StatusCodes class contains constants pertaining to HTTP status codes.

FileNotFound

The file not found status code.

Found

The found status code.

InternalServerError

The internal server error status code.

MovedPermanently

The moved permanently status code.

OK

The OK status code.

The headers module

The headers module contains a class which provides the ability to create a specific HTTP header.

class pyamp.web.http.headers.Header(identifier, value)[source]

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)[source]

Create a content type header.

  • contentType – The type of content
getId()[source]

Get the ID for this header.

classmethod getOperatingSystem(headers)[source]

Get the operating system from the given headers.

  • headers – The headers
getValue()[source]

Get the value for this header.

classmethod jsonContent()[source]

Create a JSON content type header.

classmethod location(location)[source]

Create a location header.

  • location – The location
classmethod textHtmlContent()[source]

Create an text/html content type header.

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.

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

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.

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.

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.

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 requests module

The requests module contains classes pertaining to creating various types of objects to handle HTTP requests.

class pyamp.web.http.requests.BaseRequestHandler(request, client_address, server)[source]

The BaseRequestHandler class provides the basic functionality that is shared among all HTTP request handlers.

do_GET()[source]

Process a GET request.

do_POST()[source]

Process a POST request.

classmethod initialize(*args, **kwargs)

Initialize the request handler.

  • args – Additional arguments
  • kwargs – Additional keyword arguments
logError(message)

Log an error message.

  • message – The message to log
pageClasses

The pageClasses property contains the list of Page classes which this request handler is able to provide. The request handler will be able to return requests based on the configured list of URLs for each page, as well as any supported error codes each Page defines.

class pyamp.web.http.requests.StoppableRequestHandler(request, client_address, server)[source]

The StoppableRequestHandler class provides an implementation of an HTTP request handler that handles the quit message send by a server when it is trying to stop itself.

do_QUIT()[source]

Handle a QUIT message.

The server module

The server module contains various classes pertaining to creating HTTP servers.

class pyamp.web.http.server.HttpServer(port, requestHandlerClass, host='')[source]

Create a basic HTTP server.

Example:

from BaseHTTPServer import BaseHTTPRequestHandler


class RequestHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        
        print "GET:", self.path

server = HttpServer(12345, RequestHandler)
server.serve_forever()
  • port – The port for the server
  • requestHandlerClass – The class used to handle requests
  • host – The host name for the server
class pyamp.web.http.server.HttpServerThread(port, requestHandlerClass, host='')[source]

The HttpServerThread class provides an implementation of an HttpServer that runs in its own thread.

Example:

from time import sleep

from pyamp.web.http.requests import StoppableRequestHandler


server = HttpServerThread(12345, StoppableRequestHandler)
server.start()

while True:
    try:
        sleep(0.1)
    except (KeyboardInterrupt, SystemExit):
        print "Stopping server!"
        server.shutdown()
        break

print "Done."
  • port – The port for the server
  • requestHandlerClass – The class used to handle requests
  • host – The host name for the server
onCycle(_i)

Called once during every cycle of the thread.

  • _i – The current cycle number
onShutdown()[source]

Called in the event that the Thread is shut down.

onStop()[source]

Called in the event that the Thread is stopped.