AdmitHTTP — Data browser services module.¶
This module defines the classes needed to serve ADMIT data to the data browser on a localhost port. These classes are subclasses of those provided in the Python library BaseHTTPServer module.
-
class
admit.util.AdmitHTTP.
AdmitHTTPServer
(server_address, docroot, postcallback)[source]¶ - This class is identical to BaseHTTPServer.HTTPServer except
- It defines a fixed document root instead of using the current working directory.
- The handler class is fixed to be AdmitHTTPRequestHandler.
This is accomplished by overriding the constructor and BaseServer.finish_request().
Parameters: server_address : tuple
The address on which the server is listening. This is a tuple containing a string giving the address, and an integer port number: (‘127.0.0.1’, 80), for example.
docroot : string
The document root directory for the local data web server. Requests will be served out of this directory. ** todo: possibly make this always localhost**
postcallback : function
The external function to call when handling a POST.
Attributes
_documentRoot (string) The document root directory for the web server. Requests will be served out of this directory. Methods
close_request
(request)Called to clean up an individual request. fileno
()Return socket file number. finish_request
(request, client_address)Finish one http request by instantiating RequestHandlerClass. get_request
()Get the request and client address from the socket. handle_error
(request, client_address)Handle an error gracefully. handle_request
()Handle one request, possibly blocking. handle_timeout
()Called if no new request arrives within self.timeout. process_request
(request, client_address)Call finish_request. serve_forever
([poll_interval])Handle one request at a time until shutdown. server_activate
()Called by constructor to activate the server. server_bind
()Override server_bind to store the server name. server_close
()Called to clean-up the server. shutdown
()Stops the serve_forever loop. shutdown_request
(request)Called to shutdown and close an individual request. verify_request
(request, client_address)Verify the request. -
finish_request
(request, client_address)[source]¶ Finish one http request by instantiating RequestHandlerClass. Construction of the handler class calls the methods to process the request. overrides: BaseServer.finish_request
-
class
admit.util.AdmitHTTP.
AdmitHTTPRequestHandler
(request, client_address, docroot, postcallback)[source]¶ And HTTP request handler that allows a fixed document root. Python’s SimpleHTTPRequestHandler always uses the current working directory which is stored globally. Therefore, SimpleHTTPRequestHandler cannot be used to spawn off http servers in separate threads because they will overwrite each other’s working directories.
Attributes
timeout Methods
MessageClass
alias of Message
address_string
()Return the client address formatted for logging. copyfile
(source, outputfile)Copy all data between two file objects. date_time_string
([timestamp])Return the current date and time formatted for a message header. do_GET
()Serve a GET request. do_HEAD
()Serve a HEAD request. do_OPTIONS
()do_POST
()end_headers
()Send the blank line ending the MIME headers. finish
()guess_type
(path)Guess the type of a file. handle
()Handle multiple requests if necessary. handle_error
(request, client_address)handle_one_request
()Handle a single HTTP request. isFirefox
()Attempt to detect the Firefox browser. is_broken_pipe_error
()list_directory
(path)Helper to produce a directory listing (absent index.html). log_date_time_string
()Return the current time formatted for logging. log_error
(format, \*args)Log an error. log_message
(format, \*args)log_request
([code, size])Log an accepted request. parse_request
()Parse a request (internal). send_error
(code[, message])Send and log an error reply. send_head
()Common code for GET and HEAD commands. send_header
(keyword, value)Send a MIME header. send_response
(code[, message])Send the response header and log the response code. setup
()translate_path
(path)Translate a /-separated PATH to the local filename syntax. version_string
()Return the server software version string. -
isFirefox
()[source]¶ Attempt to detect the Firefox browser. This is because Firefox does funny things and we have to workaround it. Return True if the user-agent header contains the string ‘firefox’ (case insensitive)
-
translate_path
(path)[source]¶ Translate a /-separated PATH to the local filename syntax. Components that mean special things to the local file system (e.g. drive or directory names) are ignored. This method is identical to SimpleHTTPRequestHandler.translate_path() except it uses the locally stored document root instead of the current working directory.
-