The server module

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

The Argument class

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

class pyamp.web.http.server.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 HttpServerThread class

Inheritance diagram of pyamp.web.http.server.HttpServerThread

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.

The HttpServer class

Inheritance diagram of pyamp.web.http.server.HttpServer

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

Table Of Contents

Previous topic

The http module

Next topic

The requests module

This Page