Exscript.servers.httpd module

A threaded HTTP server with support for HTTP/Digest authentication.

class Exscript.servers.httpd.HTTPd(addr, handler_cls, user_data=None)[source]

Bases: SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer

An HTTP server, derived from Python’s HTTPServer but with added support for HTTP/Digest. Usage:

from Exscript.servers import HTTPd, RequestHandler
class MyHandler(RequestHandler):
    def handle_GET(self):
        self.send_response(200)
        self.end_headers()
        self.wfile.write('You opened ' + self.path)

server = HTTPd(('', 8080), MyHandler)
server.add_account('testuser', 'testpassword')
print('started httpserver...')
server.serve_forever()
__init__(addr, handler_cls, user_data=None)[source]

Constructor.

Parameters:
  • address ((str, int)) – The address and port number on which to bind.
  • handler_cls (RequestHandler) – The RequestHandler to use.
  • user_data (object) – Optional data that, stored in self.user_data.
add_account(username, password)[source]

Adds a username/password pair that HTTP clients may use to log in.

Parameters:
  • username (str) – The name of the user.
  • password (str) – The user’s password.
daemon_threads = True
get_password(username)[source]

Returns the password of the user with the given name.

Parameters:username (str) – The name of the user.
class Exscript.servers.httpd.RequestHandler(request, client_address, server)[source]

Bases: BaseHTTPServer.BaseHTTPRequestHandler

A drop-in replacement for Python’s BaseHTTPRequestHandler that handles HTTP/Digest.

do_GET()[source]
do_POST()[source]
handle_GET()[source]

Overwrite this method to handle a GET request. The default action is to respond with “error 404 (not found)”.

handle_POST()[source]

Overwrite this method to handle a POST request. The default action is to respond with “error 404 (not found)”.

send_response(code)[source]

See Python’s BaseHTTPRequestHandler.send_response().

Exscript.servers.httpd.md5hex(x)[source]