ThreadedServers
NAME
ThreadedServers
PACKAGE CONTENTS
Avahi
Base
HTTPS
Multicast
Pacserve
PageGenerators (package)
PeeredQuickserve
Quickserve
__version__
common
ThreadedServers.Avahi
NAME
ThreadedServers.Avahi
CLASSES
builtins.object
AvahiAnnouncer
AvahiListener
AvahiPeerManager
class AvahiAnnouncer(builtins.object)
| AvahiAnnouncer(server, domain='', host='', text='')
|
| Context manager for announcing service via Avahi.
|
| Methods defined here:
|
| __enter__(self)
|
| __exit__(self, typ, value, traceback)
|
| __init__(self, server, domain='', host='', text='')
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
class AvahiListener(builtins.object)
| AvahiListener(server)
|
| Connect to the Avahi system bus and listen for services.
|
| Methods defined here:
|
| __init__(self, server)
| Initialize self. See help(type(self)) for accurate signature.
|
| handle_avahi(self, interface, protocol, name, service_type, domain, flags)
|
| listen(self)
| Loop wrapper with exception handling.
|
| log_error(self, err)
|
| loop(self)
| Connect to Avahi via the system bus and listen for service announcements.
|
| resolve_service(self, interface, protocol, name, service_type, domain, host, aprotocol, address, port, txt, flags)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
class AvahiPeerManager(builtins.object)
| Manage the avahi announcer and listener threads. This should be subclassed by
| servers that wish to acquire peers through avahi. Subclasses must have the
| following attributes from one of the server classes:
|
| * options (with all options added by add_avahi_argparse_groups())
| * get_server_uris
| * handler
|
| Methods defined here:
|
| get_avahi_info(self)
|
| get_avahi_service_name(self, prefix_only=False)
| Get the version-specific service name.
|
| get_avahi_service_type(self)
| Get the appropriate avahi service type.
|
| shutdown(self)
|
| start_avahi_threads(self)
| Start the listener and announcer threads.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
FUNCTIONS
DBusGMainLoop(...)
DBusGMainLoop([set_as_default=False]) -> NativeMainLoop
Return a NativeMainLoop object which can be used to
represent the default GLib main context in dbus-python.
If the keyword argument set_as_default is given and is true, set the new
main loop as the default for all new Connection or Bus instances.
Non-default main contexts are not currently supported.
add_avahi_argparse_groups(parser, avahi_interval=300)
avahi_announcer(server)
Announcer thread.
DATA
AVAHI_INTERVAL = 300
AVAHI_MODULES_FOUND = True
HTTPS_SERVICE_TYPE = '_https._tcp'
HTTP_SERVICE_TYPE = '_http._tcp'
ThreadedServers.Base
NAME
ThreadedServers.Base
CLASSES
builtins.object
BaseServer(socketserver.ThreadingMixIn, builtins.object)
socketserver.ThreadingMixIn(builtins.object)
BaseServer(socketserver.ThreadingMixIn, builtins.object)
class BaseServer(socketserver.ThreadingMixIn, builtins.object)
| BaseServer(options)
|
| Base server class from which all others in this package should inherit.
|
| Method resolution order:
| BaseServer
| socketserver.ThreadingMixIn
| builtins.object
|
| Methods defined here:
|
| __init__(self, options)
| Initialize self. See help(type(self)) for accurate signature.
|
| get_address_and_port(self)
|
| get_address_header_and_string(self)
|
| get_scheme(self)
| This should return a scheme for constructing URIs.
|
| is_local_address(self, address)
| Check if an address is local. Returns True if the address is listed by
| the local_ips() method.
|
| local_ifnames_and_ips(self)
| Return an iterator over the detected interfaces and local IP addresses.
|
| local_ips(self)
| Return an iterator over the detected local IP addresses.
|
| log_debug(self, msg)
|
| log_error(self, msg)
|
| log_message(self, msg)
|
| log_warning(self, msg)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| daemon_threads = True
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.ThreadingMixIn:
|
| process_request(self, request, client_address)
| Start a new thread to process the request.
|
| process_request_thread(self, request, client_address)
| Same as in BaseServer but as a thread.
|
| In addition, exception handling is done here.
|
| server_close(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketserver.ThreadingMixIn:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketserver.ThreadingMixIn:
|
| block_on_close = True
DATA
DAEMON_THREADS = True
ThreadedServers.HTTPS
NAME
ThreadedServers.HTTPS
CLASSES
ThreadedServers.Base.BaseServer(socketserver.ThreadingMixIn, builtins.object)
HTTPSServer(ThreadedServers.Base.BaseServer, http.server.HTTPServer)
builtins.object
BaseHTTPSRequestHandler(http.server.BaseHTTPRequestHandler, builtins.object)
CGIHTTPSRequestHandler(BaseHTTPSRequestHandler, http.server.CGIHTTPRequestHandler)
SimpleHTTPSRequestHandler(BaseHTTPSRequestHandler, http.server.SimpleHTTPRequestHandler)
ChunkWriter
http.server.BaseHTTPRequestHandler(socketserver.StreamRequestHandler)
BaseHTTPSRequestHandler(http.server.BaseHTTPRequestHandler, builtins.object)
CGIHTTPSRequestHandler(BaseHTTPSRequestHandler, http.server.CGIHTTPRequestHandler)
SimpleHTTPSRequestHandler(BaseHTTPSRequestHandler, http.server.SimpleHTTPRequestHandler)
http.server.HTTPServer(socketserver.TCPServer)
HTTPSServer(ThreadedServers.Base.BaseServer, http.server.HTTPServer)
class BaseHTTPSRequestHandler(http.server.BaseHTTPRequestHandler, builtins.object)
| BaseHTTPSRequestHandler(*args, **kwargs)
|
| HTTP(S) request handler with support for HTTP authorization.
|
| Method resolution order:
| BaseHTTPSRequestHandler
| http.server.BaseHTTPRequestHandler
| socketserver.StreamRequestHandler
| socketserver.BaseRequestHandler
| builtins.object
|
| Methods defined here:
|
| __init__(self, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| authenticate(self, method)
| Attempt to authenticate HTTP requests and reject those that fail.
|
| The specification only supports GET and POST methods. GET should be used for
| HEAD requests.
|
| The return value indicates if the authentication succeeded.
|
| create_nonce(self)
| Create a nonce value.
|
| do_GET(self)
|
| do_HEAD(self)
|
| do_POST(self)
|
| get_nonce(self, opaque, nc)
| Get a nonce value from a given opaque if the nonce count (nc) matches.
|
| get_realm(self)
| Return the realm. Can be overridden in subclasses.
|
| log_date_time_string(self)
| Return the current time formatted for logging.
|
| log_error(self, fmt, *args)
| Log an error.
|
| This is called when a request cannot be fulfilled. By
| default it passes the message on to log_message().
|
| Arguments are the same as for log_message().
|
| XXX This should go to the separate error log.
|
| log_message(self, fmt, *args)
| Log an arbitrary message.
|
| This is used by all other logging functions. Override
| it if you have specific logging wishes.
|
| The first argument, FORMAT, is a format string for the
| message to be logged. If the format string contains
| any % escapes requiring parameters, they should be
| specified as subsequent arguments (it's just like
| printf!).
|
| The client ip and current date/time are prefixed to
| every message.
|
| redirect(self, location='/', status_code=303, message=None, close=True)
| Redirect to a local server path.
|
| reject_unauthenticated_request(self)
| Reject an unauthenticated request.
|
| transfer_directory(self, dpaths, name, *args, include_body=True, compression=None, hide_path=None, **kwargs)
| Transfer a directory by recursivingly adding its contents to a tar file.
|
| dpaths:
| The directories to transfer.
|
| include_body:
| If True, transfer the content, else only transfer the header.
|
| compression:
| A compression type supported by Python's tarfile module.
|
| All other positional and keyword arguments are passed to tarfile.open.
|
| transfer_file(self, fpath, include_body=True, chunk_size=None)
| Transfer the contents of a file, with support for the Range header.
|
| transfer_html(self, html, include_body=True, status_code=200, close=True)
| Transfer a UTF-8-encoded HTML page.
|
| transfer_json(self, obj, include_body=True, status_code=200, close=True, *args, **kwargs)
| Transfer UTF-8-encoded JSON data.
|
| transfer_plaintext(self, text, include_body=True, status_code=200, close=True)
| Transfer a UTF-8-encoded plaintext page.
|
| transfer_utf8_content(self, content, content_type='application/octet-stream', include_body=True, status_code=200, encode=True, location=None, close=False)
| Convenience method for transferring UTF-8 encoded content.
|
| version_string(self)
| Return the server software version string.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| NONCE_LENGTH = 32
|
| protocol_version = 'HTTP/1.1'
|
| ----------------------------------------------------------------------
| Methods inherited from http.server.BaseHTTPRequestHandler:
|
| address_string(self)
| Return the client address.
|
| date_time_string(self, timestamp=None)
| Return the current date and time formatted for a message header.
|
| end_headers(self)
| Send the blank line ending the MIME headers.
|
| flush_headers(self)
|
| handle(self)
| Handle multiple requests if necessary.
|
| handle_expect_100(self)
| Decide what to do with an "Expect: 100-continue" header.
|
| If the client is expecting a 100 Continue response, we must
| respond with either a 100 Continue or a final response before
| waiting for the request body. The default is to always respond
| with a 100 Continue. You can behave differently (for example,
| reject unauthorized requests) by overriding this method.
|
| This method should either return True (possibly after sending
| a 100 Continue response) or send an error response and return
| False.
|
| handle_one_request(self)
| Handle a single HTTP request.
|
| You normally don't need to override this method; see the class
| __doc__ string for information on how to handle specific HTTP
| commands such as GET and POST.
|
| log_request(self, code='-', size='-')
| Log an accepted request.
|
| This is called by send_response().
|
| parse_request(self)
| Parse a request (internal).
|
| The request should be stored in self.raw_requestline; the results
| are in self.command, self.path, self.request_version and
| self.headers.
|
| Return True for success, False for failure; on failure, any relevant
| error response has already been sent back.
|
| send_error(self, code, message=None, explain=None)
| Send and log an error reply.
|
| Arguments are
| * code: an HTTP error code
| 3 digits
| * message: a simple optional 1 line reason phrase.
| *( HTAB / SP / VCHAR / %x80-FF )
| defaults to short entry matching the response code
| * explain: a detailed message defaults to the long entry
| matching the response code.
|
| This sends an error response (so it must be called before any
| output has been generated), logs the error, and finally sends
| a piece of HTML explaining the error to the user.
|
| send_header(self, keyword, value)
| Send a MIME header to the headers buffer.
|
| send_response(self, code, message=None)
| Add the response header to the headers buffer and log the
| response code.
|
| Also send two standard headers with the server software
| version and the current date.
|
| send_response_only(self, code, message=None)
| Send the response header only.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from http.server.BaseHTTPRequestHandler:
|
| MessageClass = <class 'http.client.HTTPMessage'>
|
| default_request_version = 'HTTP/0.9'
|
| error_content_type = 'text/html;charset=utf-8'
|
| error_message_format = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//...
|
| monthname = [None, 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'A...
|
| responses = {<HTTPStatus.CONTINUE: 100>: ('Continue', 'Request receive...
|
| server_version = 'BaseHTTP/0.6'
|
| sys_version = 'Python/3.10.5'
|
| weekdayname = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.StreamRequestHandler:
|
| finish(self)
|
| setup(self)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketserver.StreamRequestHandler:
|
| disable_nagle_algorithm = False
|
| rbufsize = -1
|
| timeout = None
|
| wbufsize = 0
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketserver.BaseRequestHandler:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
class CGIHTTPSRequestHandler(BaseHTTPSRequestHandler, http.server.CGIHTTPRequestHandler)
| CGIHTTPSRequestHandler(*args, **kwargs)
|
| Subclass of http.server.SimpleHTTPRequestHandler.
|
| Method resolution order:
| CGIHTTPSRequestHandler
| BaseHTTPSRequestHandler
| http.server.CGIHTTPRequestHandler
| http.server.SimpleHTTPRequestHandler
| http.server.BaseHTTPRequestHandler
| socketserver.StreamRequestHandler
| socketserver.BaseRequestHandler
| builtins.object
|
| Methods defined here:
|
| __init__(self, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| do_authenticated_GET(self)
|
| do_authenticated_HEAD(self)
|
| do_authenticated_POST(self)
|
| ----------------------------------------------------------------------
| Methods inherited from BaseHTTPSRequestHandler:
|
| authenticate(self, method)
| Attempt to authenticate HTTP requests and reject those that fail.
|
| The specification only supports GET and POST methods. GET should be used for
| HEAD requests.
|
| The return value indicates if the authentication succeeded.
|
| create_nonce(self)
| Create a nonce value.
|
| do_GET(self)
|
| do_HEAD(self)
|
| do_POST(self)
|
| get_nonce(self, opaque, nc)
| Get a nonce value from a given opaque if the nonce count (nc) matches.
|
| get_realm(self)
| Return the realm. Can be overridden in subclasses.
|
| log_date_time_string(self)
| Return the current time formatted for logging.
|
| log_error(self, fmt, *args)
| Log an error.
|
| This is called when a request cannot be fulfilled. By
| default it passes the message on to log_message().
|
| Arguments are the same as for log_message().
|
| XXX This should go to the separate error log.
|
| log_message(self, fmt, *args)
| Log an arbitrary message.
|
| This is used by all other logging functions. Override
| it if you have specific logging wishes.
|
| The first argument, FORMAT, is a format string for the
| message to be logged. If the format string contains
| any % escapes requiring parameters, they should be
| specified as subsequent arguments (it's just like
| printf!).
|
| The client ip and current date/time are prefixed to
| every message.
|
| redirect(self, location='/', status_code=303, message=None, close=True)
| Redirect to a local server path.
|
| reject_unauthenticated_request(self)
| Reject an unauthenticated request.
|
| transfer_directory(self, dpaths, name, *args, include_body=True, compression=None, hide_path=None, **kwargs)
| Transfer a directory by recursivingly adding its contents to a tar file.
|
| dpaths:
| The directories to transfer.
|
| include_body:
| If True, transfer the content, else only transfer the header.
|
| compression:
| A compression type supported by Python's tarfile module.
|
| All other positional and keyword arguments are passed to tarfile.open.
|
| transfer_file(self, fpath, include_body=True, chunk_size=None)
| Transfer the contents of a file, with support for the Range header.
|
| transfer_html(self, html, include_body=True, status_code=200, close=True)
| Transfer a UTF-8-encoded HTML page.
|
| transfer_json(self, obj, include_body=True, status_code=200, close=True, *args, **kwargs)
| Transfer UTF-8-encoded JSON data.
|
| transfer_plaintext(self, text, include_body=True, status_code=200, close=True)
| Transfer a UTF-8-encoded plaintext page.
|
| transfer_utf8_content(self, content, content_type='application/octet-stream', include_body=True, status_code=200, encode=True, location=None, close=False)
| Convenience method for transferring UTF-8 encoded content.
|
| version_string(self)
| Return the server software version string.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from BaseHTTPSRequestHandler:
|
| NONCE_LENGTH = 32
|
| protocol_version = 'HTTP/1.1'
|
| ----------------------------------------------------------------------
| Methods inherited from http.server.CGIHTTPRequestHandler:
|
| is_cgi(self)
| Test whether self.path corresponds to a CGI script.
|
| Returns True and updates the cgi_info attribute to the tuple
| (dir, rest) if self.path requires running a CGI script.
| Returns False otherwise.
|
| If any exception is raised, the caller should assume that
| self.path was rejected as invalid and act accordingly.
|
| The default implementation tests whether the normalized url
| path begins with one of the strings in self.cgi_directories
| (and the next character is a '/' or the end of the string).
|
| is_executable(self, path)
| Test whether argument path is an executable file.
|
| is_python(self, path)
| Test whether argument path is a Python script.
|
| run_cgi(self)
| Execute a CGI script.
|
| send_head(self)
| Version of send_head that support CGI scripts
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from http.server.CGIHTTPRequestHandler:
|
| cgi_directories = ['/cgi-bin', '/htbin']
|
| have_fork = True
|
| rbufsize = 0
|
| ----------------------------------------------------------------------
| Methods inherited from http.server.SimpleHTTPRequestHandler:
|
| copyfile(self, source, outputfile)
| Copy all data between two file objects.
|
| The SOURCE argument is a file object open for reading
| (or anything with a read() method) and the DESTINATION
| argument is a file object open for writing (or
| anything with a write() method).
|
| The only reason for overriding this would be to change
| the block size or perhaps to replace newlines by CRLF
| -- note however that this the default server uses this
| to copy binary data as well.
|
| guess_type(self, path)
| Guess the type of a file.
|
| Argument is a PATH (a filename).
|
| Return value is a string of the form type/subtype,
| usable for a MIME Content-type header.
|
| The default implementation looks the file's extension
| up in the table self.extensions_map, using application/octet-stream
| as a default; however it would be permissible (if
| slow) to look inside the data to make a better guess.
|
| list_directory(self, path)
| Helper to produce a directory listing (absent index.html).
|
| Return value is either a file object, or None (indicating an
| error). In either case, the headers are sent, making the
| interface the same as for send_head().
|
| translate_path(self, path)
| 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. (XXX They should
| probably be diagnosed.)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from http.server.SimpleHTTPRequestHandler:
|
| extensions_map = {'.Z': 'application/octet-stream', '.bz2': 'applicati...
|
| server_version = 'SimpleHTTP/0.6'
|
| ----------------------------------------------------------------------
| Methods inherited from http.server.BaseHTTPRequestHandler:
|
| address_string(self)
| Return the client address.
|
| date_time_string(self, timestamp=None)
| Return the current date and time formatted for a message header.
|
| end_headers(self)
| Send the blank line ending the MIME headers.
|
| flush_headers(self)
|
| handle(self)
| Handle multiple requests if necessary.
|
| handle_expect_100(self)
| Decide what to do with an "Expect: 100-continue" header.
|
| If the client is expecting a 100 Continue response, we must
| respond with either a 100 Continue or a final response before
| waiting for the request body. The default is to always respond
| with a 100 Continue. You can behave differently (for example,
| reject unauthorized requests) by overriding this method.
|
| This method should either return True (possibly after sending
| a 100 Continue response) or send an error response and return
| False.
|
| handle_one_request(self)
| Handle a single HTTP request.
|
| You normally don't need to override this method; see the class
| __doc__ string for information on how to handle specific HTTP
| commands such as GET and POST.
|
| log_request(self, code='-', size='-')
| Log an accepted request.
|
| This is called by send_response().
|
| parse_request(self)
| Parse a request (internal).
|
| The request should be stored in self.raw_requestline; the results
| are in self.command, self.path, self.request_version and
| self.headers.
|
| Return True for success, False for failure; on failure, any relevant
| error response has already been sent back.
|
| send_error(self, code, message=None, explain=None)
| Send and log an error reply.
|
| Arguments are
| * code: an HTTP error code
| 3 digits
| * message: a simple optional 1 line reason phrase.
| *( HTAB / SP / VCHAR / %x80-FF )
| defaults to short entry matching the response code
| * explain: a detailed message defaults to the long entry
| matching the response code.
|
| This sends an error response (so it must be called before any
| output has been generated), logs the error, and finally sends
| a piece of HTML explaining the error to the user.
|
| send_header(self, keyword, value)
| Send a MIME header to the headers buffer.
|
| send_response(self, code, message=None)
| Add the response header to the headers buffer and log the
| response code.
|
| Also send two standard headers with the server software
| version and the current date.
|
| send_response_only(self, code, message=None)
| Send the response header only.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from http.server.BaseHTTPRequestHandler:
|
| MessageClass = <class 'http.client.HTTPMessage'>
|
| default_request_version = 'HTTP/0.9'
|
| error_content_type = 'text/html;charset=utf-8'
|
| error_message_format = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//...
|
| monthname = [None, 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'A...
|
| responses = {<HTTPStatus.CONTINUE: 100>: ('Continue', 'Request receive...
|
| sys_version = 'Python/3.10.5'
|
| weekdayname = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.StreamRequestHandler:
|
| finish(self)
|
| setup(self)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketserver.StreamRequestHandler:
|
| disable_nagle_algorithm = False
|
| timeout = None
|
| wbufsize = 0
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketserver.BaseRequestHandler:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
class ChunkWriter(builtins.object)
| ChunkWriter(fileobj)
|
| File object wrapper to transfer HTTP chunks. Only the write method is modified.
|
| Methods defined here:
|
| __enter__(self)
|
| __exit__(self, exc_type, exc_value, traceback)
|
| __init__(self, fileobj)
| Initialize self. See help(type(self)) for accurate signature.
|
| write(self, data, *args, **kwargs)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
class HTTPSServer(ThreadedServers.Base.BaseServer, http.server.HTTPServer)
| HTTPSServer(server_address, handler, options, nc_limit=None, opaque_timeout=None, *args, **kwargs)
|
| Threaded HTTP(S) Server.
|
| Method resolution order:
| HTTPSServer
| ThreadedServers.Base.BaseServer
| socketserver.ThreadingMixIn
| http.server.HTTPServer
| socketserver.TCPServer
| socketserver.BaseServer
| builtins.object
|
| Methods defined here:
|
| __init__(self, server_address, handler, options, nc_limit=None, opaque_timeout=None, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| clean_house(self)
|
| delete_opaque(self, opaque)
|
| finish_request(self, request, client_address)
| Finish one request by instantiating RequestHandlerClass.
|
| get_request(self)
| Overridden method for SSL support.
|
| get_scheme(self)
| This should return a scheme for constructing URIs.
|
| get_server_uris(self, path='/')
| Generator over all local URIs via which the server is accessible.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| NC_LIMIT = 4294967295
|
| OPAQUE_TIMEOUT = 3600
|
| ----------------------------------------------------------------------
| Methods inherited from ThreadedServers.Base.BaseServer:
|
| get_address_and_port(self)
|
| get_address_header_and_string(self)
|
| is_local_address(self, address)
| Check if an address is local. Returns True if the address is listed by
| the local_ips() method.
|
| local_ifnames_and_ips(self)
| Return an iterator over the detected interfaces and local IP addresses.
|
| local_ips(self)
| Return an iterator over the detected local IP addresses.
|
| log_debug(self, msg)
|
| log_error(self, msg)
|
| log_message(self, msg)
|
| log_warning(self, msg)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from ThreadedServers.Base.BaseServer:
|
| daemon_threads = True
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.ThreadingMixIn:
|
| process_request(self, request, client_address)
| Start a new thread to process the request.
|
| process_request_thread(self, request, client_address)
| Same as in BaseServer but as a thread.
|
| In addition, exception handling is done here.
|
| server_close(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketserver.ThreadingMixIn:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketserver.ThreadingMixIn:
|
| block_on_close = True
|
| ----------------------------------------------------------------------
| Methods inherited from http.server.HTTPServer:
|
| server_bind(self)
| Override server_bind to store the server name.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from http.server.HTTPServer:
|
| allow_reuse_address = 1
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.TCPServer:
|
| close_request(self, request)
| Called to clean up an individual request.
|
| fileno(self)
| Return socket file number.
|
| Interface required by selector.
|
| server_activate(self)
| Called by constructor to activate the server.
|
| May be overridden.
|
| shutdown_request(self, request)
| Called to shutdown and close an individual request.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketserver.TCPServer:
|
| address_family = <AddressFamily.AF_INET: 2>
|
| request_queue_size = 5
|
| socket_type = <SocketKind.SOCK_STREAM: 1>
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.BaseServer:
|
| __enter__(self)
|
| __exit__(self, *args)
|
| handle_error(self, request, client_address)
| Handle an error gracefully. May be overridden.
|
| The default is to print a traceback and continue.
|
| handle_request(self)
| Handle one request, possibly blocking.
|
| Respects self.timeout.
|
| handle_timeout(self)
| Called if no new request arrives within self.timeout.
|
| Overridden by ForkingMixIn.
|
| serve_forever(self, poll_interval=0.5)
| Handle one request at a time until shutdown.
|
| Polls for shutdown every poll_interval seconds. Ignores
| self.timeout. If you need to do periodic tasks, do them in
| another thread.
|
| service_actions(self)
| Called by the serve_forever() loop.
|
| May be overridden by a subclass / Mixin to implement any code that
| needs to be run during the loop.
|
| shutdown(self)
| Stops the serve_forever loop.
|
| Blocks until the loop has finished. This must be called while
| serve_forever() is running in another thread, or it will
| deadlock.
|
| verify_request(self, request, client_address)
| Verify the request. May be overridden.
|
| Return True if we should proceed with this request.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketserver.BaseServer:
|
| timeout = None
class SimpleHTTPSRequestHandler(BaseHTTPSRequestHandler, http.server.SimpleHTTPRequestHandler)
| SimpleHTTPSRequestHandler(*args, **kwargs)
|
| Subclass of http.server.SimpleHTTPRequestHandler.
|
| Method resolution order:
| SimpleHTTPSRequestHandler
| BaseHTTPSRequestHandler
| http.server.SimpleHTTPRequestHandler
| http.server.BaseHTTPRequestHandler
| socketserver.StreamRequestHandler
| socketserver.BaseRequestHandler
| builtins.object
|
| Methods defined here:
|
| __init__(self, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| do_authenticated_GET(self)
|
| do_authenticated_HEAD(self)
|
| do_authenticated_POST(self)
|
| ----------------------------------------------------------------------
| Methods inherited from BaseHTTPSRequestHandler:
|
| authenticate(self, method)
| Attempt to authenticate HTTP requests and reject those that fail.
|
| The specification only supports GET and POST methods. GET should be used for
| HEAD requests.
|
| The return value indicates if the authentication succeeded.
|
| create_nonce(self)
| Create a nonce value.
|
| do_GET(self)
|
| do_HEAD(self)
|
| do_POST(self)
|
| get_nonce(self, opaque, nc)
| Get a nonce value from a given opaque if the nonce count (nc) matches.
|
| get_realm(self)
| Return the realm. Can be overridden in subclasses.
|
| log_date_time_string(self)
| Return the current time formatted for logging.
|
| log_error(self, fmt, *args)
| Log an error.
|
| This is called when a request cannot be fulfilled. By
| default it passes the message on to log_message().
|
| Arguments are the same as for log_message().
|
| XXX This should go to the separate error log.
|
| log_message(self, fmt, *args)
| Log an arbitrary message.
|
| This is used by all other logging functions. Override
| it if you have specific logging wishes.
|
| The first argument, FORMAT, is a format string for the
| message to be logged. If the format string contains
| any % escapes requiring parameters, they should be
| specified as subsequent arguments (it's just like
| printf!).
|
| The client ip and current date/time are prefixed to
| every message.
|
| redirect(self, location='/', status_code=303, message=None, close=True)
| Redirect to a local server path.
|
| reject_unauthenticated_request(self)
| Reject an unauthenticated request.
|
| transfer_directory(self, dpaths, name, *args, include_body=True, compression=None, hide_path=None, **kwargs)
| Transfer a directory by recursivingly adding its contents to a tar file.
|
| dpaths:
| The directories to transfer.
|
| include_body:
| If True, transfer the content, else only transfer the header.
|
| compression:
| A compression type supported by Python's tarfile module.
|
| All other positional and keyword arguments are passed to tarfile.open.
|
| transfer_file(self, fpath, include_body=True, chunk_size=None)
| Transfer the contents of a file, with support for the Range header.
|
| transfer_html(self, html, include_body=True, status_code=200, close=True)
| Transfer a UTF-8-encoded HTML page.
|
| transfer_json(self, obj, include_body=True, status_code=200, close=True, *args, **kwargs)
| Transfer UTF-8-encoded JSON data.
|
| transfer_plaintext(self, text, include_body=True, status_code=200, close=True)
| Transfer a UTF-8-encoded plaintext page.
|
| transfer_utf8_content(self, content, content_type='application/octet-stream', include_body=True, status_code=200, encode=True, location=None, close=False)
| Convenience method for transferring UTF-8 encoded content.
|
| version_string(self)
| Return the server software version string.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from BaseHTTPSRequestHandler:
|
| NONCE_LENGTH = 32
|
| protocol_version = 'HTTP/1.1'
|
| ----------------------------------------------------------------------
| Methods inherited from http.server.SimpleHTTPRequestHandler:
|
| copyfile(self, source, outputfile)
| Copy all data between two file objects.
|
| The SOURCE argument is a file object open for reading
| (or anything with a read() method) and the DESTINATION
| argument is a file object open for writing (or
| anything with a write() method).
|
| The only reason for overriding this would be to change
| the block size or perhaps to replace newlines by CRLF
| -- note however that this the default server uses this
| to copy binary data as well.
|
| guess_type(self, path)
| Guess the type of a file.
|
| Argument is a PATH (a filename).
|
| Return value is a string of the form type/subtype,
| usable for a MIME Content-type header.
|
| The default implementation looks the file's extension
| up in the table self.extensions_map, using application/octet-stream
| as a default; however it would be permissible (if
| slow) to look inside the data to make a better guess.
|
| list_directory(self, path)
| Helper to produce a directory listing (absent index.html).
|
| Return value is either a file object, or None (indicating an
| error). In either case, the headers are sent, making the
| interface the same as for send_head().
|
| send_head(self)
| Common code for GET and HEAD commands.
|
| This sends the response code and MIME headers.
|
| Return value is either a file object (which has to be copied
| to the outputfile by the caller unless the command was HEAD,
| and must be closed by the caller under all circumstances), or
| None, in which case the caller has nothing further to do.
|
| translate_path(self, path)
| 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. (XXX They should
| probably be diagnosed.)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from http.server.SimpleHTTPRequestHandler:
|
| extensions_map = {'.Z': 'application/octet-stream', '.bz2': 'applicati...
|
| server_version = 'SimpleHTTP/0.6'
|
| ----------------------------------------------------------------------
| Methods inherited from http.server.BaseHTTPRequestHandler:
|
| address_string(self)
| Return the client address.
|
| date_time_string(self, timestamp=None)
| Return the current date and time formatted for a message header.
|
| end_headers(self)
| Send the blank line ending the MIME headers.
|
| flush_headers(self)
|
| handle(self)
| Handle multiple requests if necessary.
|
| handle_expect_100(self)
| Decide what to do with an "Expect: 100-continue" header.
|
| If the client is expecting a 100 Continue response, we must
| respond with either a 100 Continue or a final response before
| waiting for the request body. The default is to always respond
| with a 100 Continue. You can behave differently (for example,
| reject unauthorized requests) by overriding this method.
|
| This method should either return True (possibly after sending
| a 100 Continue response) or send an error response and return
| False.
|
| handle_one_request(self)
| Handle a single HTTP request.
|
| You normally don't need to override this method; see the class
| __doc__ string for information on how to handle specific HTTP
| commands such as GET and POST.
|
| log_request(self, code='-', size='-')
| Log an accepted request.
|
| This is called by send_response().
|
| parse_request(self)
| Parse a request (internal).
|
| The request should be stored in self.raw_requestline; the results
| are in self.command, self.path, self.request_version and
| self.headers.
|
| Return True for success, False for failure; on failure, any relevant
| error response has already been sent back.
|
| send_error(self, code, message=None, explain=None)
| Send and log an error reply.
|
| Arguments are
| * code: an HTTP error code
| 3 digits
| * message: a simple optional 1 line reason phrase.
| *( HTAB / SP / VCHAR / %x80-FF )
| defaults to short entry matching the response code
| * explain: a detailed message defaults to the long entry
| matching the response code.
|
| This sends an error response (so it must be called before any
| output has been generated), logs the error, and finally sends
| a piece of HTML explaining the error to the user.
|
| send_header(self, keyword, value)
| Send a MIME header to the headers buffer.
|
| send_response(self, code, message=None)
| Add the response header to the headers buffer and log the
| response code.
|
| Also send two standard headers with the server software
| version and the current date.
|
| send_response_only(self, code, message=None)
| Send the response header only.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from http.server.BaseHTTPRequestHandler:
|
| MessageClass = <class 'http.client.HTTPMessage'>
|
| default_request_version = 'HTTP/0.9'
|
| error_content_type = 'text/html;charset=utf-8'
|
| error_message_format = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//...
|
| monthname = [None, 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'A...
|
| responses = {<HTTPStatus.CONTINUE: 100>: ('Continue', 'Request receive...
|
| sys_version = 'Python/3.10.5'
|
| weekdayname = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.StreamRequestHandler:
|
| finish(self)
|
| setup(self)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketserver.StreamRequestHandler:
|
| disable_nagle_algorithm = False
|
| rbufsize = -1
|
| timeout = None
|
| wbufsize = 0
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketserver.BaseRequestHandler:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
FUNCTIONS
add_HTTPS_argparse_groups(parser)
# ----------------------------- Argument Parsing ----------------------------- #
add_tar_extension(path, compression=None)
Add an appropriate tar extension to the given path.
format_content_range(ranges, size)
Format "Content-Range" headers.
get_authorized(args)
Collect the list of username-password pairs for HTTP digest authentication.
get_digest_hash(xs)
get_length_from_ranges(ranges)
Calculate the total content length from a list of ranges.
get_ssl_parameters(args)
Return a dictionary of SSL parameters.
get_tar_mimetype(compression=None)
get_tar_mtime(dpath)
Get the last modification time of a the last modified path in a directory.
get_valid_ranges(ranges, size)
main(args=None)
parse_range_header(header, size=None)
Parse HTTP "Range" headers. Range headers may take the form "a-b,c-d,e-f".
This function assumed that the range headers are well-formed, i.e. that there
are no extra spaces, invalid offsets, or extra characters.
DATA
DEFAULT_CHUNK_FACTOR = 16
DEFAULT_CHUNK_SIZE = 4096
NAME = 'ThreadedServers.HTTPS'
RFC_2822_TIME_FORMAT = '%a, %d %b %Y %H:%M:%S %Z'
TAR_COMPRESSIONS = ('none', 'gz', 'bz2', 'xz')
UTF8 = 'UTF-8'
VERSION = '2022'
VERSION_STRING = 'ThreadedServers.HTTPS/2022'
ThreadedServers.Multicast
NAME
ThreadedServers.Multicast - Multicast functionality.
CLASSES
builtins.object
MulticastPeerManager
socketserver.BaseRequestHandler(builtins.object)
MulticastSubserverRequestHandler
TestHandler
socketserver.UDPServer(socketserver.TCPServer)
MulticastServer
MulticastSubserver
class MulticastPeerManager(builtins.object)
| MulticastPeerManager(options, handler)
|
| Manage the multicast subserver and announcer threads. This should be
| subclassed by servers that wish to acquire peers through multicasts.
| Subclasses must have the following attributes from one of the server classes:
|
| * options (with all options added by add_Multicast_argparse_groups())
| * handle_peer
| * get_server_uris
|
| Methods defined here:
|
| __init__(self, options, handler)
| Initialize self. See help(type(self)) for accurate signature.
|
| get_multicast_info(self)
| Get multicast information.
|
| get_multicast_prefix(self)
| The multicast prefix is prepended to the contents of the multicasts. Only
| multicasts with the same prefix will be processed.
|
| shutdown(self)
| Shutdown multicasting.
|
| start_multicast_threads(self)
| Start the multicast subserver to listen for multicast requests and start a
| thread to periodically announce the presence of this server.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| get_server_uris()
| Placeholder for returning the server URIs, overridden in child classes.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
class MulticastServer(socketserver.UDPServer)
| MulticastServer(server_address, handler, multicast_group, *args, **kwargs)
|
| Server for listening for multicast announcements.
|
| Method resolution order:
| MulticastServer
| socketserver.UDPServer
| socketserver.TCPServer
| socketserver.BaseServer
| builtins.object
|
| Methods defined here:
|
| __init__(self, server_address, handler, multicast_group, *args, **kwargs)
| Constructor. May be extended, do not override.
|
| server_bind(self)
| Called by constructor to bind the socket.
|
| May be overridden.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| daemon_threads = True
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.UDPServer:
|
| close_request(self, request)
| Called to clean up an individual request.
|
| get_request(self)
| Get the request and client address from the socket.
|
| May be overridden.
|
| server_activate(self)
| Called by constructor to activate the server.
|
| May be overridden.
|
| shutdown_request(self, request)
| Called to shutdown and close an individual request.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketserver.UDPServer:
|
| allow_reuse_address = False
|
| max_packet_size = 8192
|
| socket_type = <SocketKind.SOCK_DGRAM: 2>
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.TCPServer:
|
| fileno(self)
| Return socket file number.
|
| Interface required by selector.
|
| server_close(self)
| Called to clean-up the server.
|
| May be overridden.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketserver.TCPServer:
|
| address_family = <AddressFamily.AF_INET: 2>
|
| request_queue_size = 5
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.BaseServer:
|
| __enter__(self)
|
| __exit__(self, *args)
|
| finish_request(self, request, client_address)
| Finish one request by instantiating RequestHandlerClass.
|
| handle_error(self, request, client_address)
| Handle an error gracefully. May be overridden.
|
| The default is to print a traceback and continue.
|
| handle_request(self)
| Handle one request, possibly blocking.
|
| Respects self.timeout.
|
| handle_timeout(self)
| Called if no new request arrives within self.timeout.
|
| Overridden by ForkingMixIn.
|
| process_request(self, request, client_address)
| Call finish_request.
|
| Overridden by ForkingMixIn and ThreadingMixIn.
|
| serve_forever(self, poll_interval=0.5)
| Handle one request at a time until shutdown.
|
| Polls for shutdown every poll_interval seconds. Ignores
| self.timeout. If you need to do periodic tasks, do them in
| another thread.
|
| service_actions(self)
| Called by the serve_forever() loop.
|
| May be overridden by a subclass / Mixin to implement any code that
| needs to be run during the loop.
|
| shutdown(self)
| Stops the serve_forever loop.
|
| Blocks until the loop has finished. This must be called while
| serve_forever() is running in another thread, or it will
| deadlock.
|
| verify_request(self, request, client_address)
| Verify the request. May be overridden.
|
| Return True if we should proceed with this request.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketserver.BaseServer:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketserver.BaseServer:
|
| timeout = None
class MulticastSubserver(MulticastServer)
| MulticastSubserver(main_server, *args, **kwargs)
|
| Subserver to handle multicast announcements. This is a subclass of the
| multicast listening server. It is run by a main server to handle multicast
| announcements.
|
| Method resolution order:
| MulticastSubserver
| MulticastServer
| socketserver.UDPServer
| socketserver.TCPServer
| socketserver.BaseServer
| builtins.object
|
| Methods defined here:
|
| __init__(self, main_server, *args, **kwargs)
| Constructor. May be extended, do not override.
|
| ----------------------------------------------------------------------
| Methods inherited from MulticastServer:
|
| server_bind(self)
| Called by constructor to bind the socket.
|
| May be overridden.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from MulticastServer:
|
| daemon_threads = True
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.UDPServer:
|
| close_request(self, request)
| Called to clean up an individual request.
|
| get_request(self)
| Get the request and client address from the socket.
|
| May be overridden.
|
| server_activate(self)
| Called by constructor to activate the server.
|
| May be overridden.
|
| shutdown_request(self, request)
| Called to shutdown and close an individual request.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketserver.UDPServer:
|
| allow_reuse_address = False
|
| max_packet_size = 8192
|
| socket_type = <SocketKind.SOCK_DGRAM: 2>
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.TCPServer:
|
| fileno(self)
| Return socket file number.
|
| Interface required by selector.
|
| server_close(self)
| Called to clean-up the server.
|
| May be overridden.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketserver.TCPServer:
|
| address_family = <AddressFamily.AF_INET: 2>
|
| request_queue_size = 5
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.BaseServer:
|
| __enter__(self)
|
| __exit__(self, *args)
|
| finish_request(self, request, client_address)
| Finish one request by instantiating RequestHandlerClass.
|
| handle_error(self, request, client_address)
| Handle an error gracefully. May be overridden.
|
| The default is to print a traceback and continue.
|
| handle_request(self)
| Handle one request, possibly blocking.
|
| Respects self.timeout.
|
| handle_timeout(self)
| Called if no new request arrives within self.timeout.
|
| Overridden by ForkingMixIn.
|
| process_request(self, request, client_address)
| Call finish_request.
|
| Overridden by ForkingMixIn and ThreadingMixIn.
|
| serve_forever(self, poll_interval=0.5)
| Handle one request at a time until shutdown.
|
| Polls for shutdown every poll_interval seconds. Ignores
| self.timeout. If you need to do periodic tasks, do them in
| another thread.
|
| service_actions(self)
| Called by the serve_forever() loop.
|
| May be overridden by a subclass / Mixin to implement any code that
| needs to be run during the loop.
|
| shutdown(self)
| Stops the serve_forever loop.
|
| Blocks until the loop has finished. This must be called while
| serve_forever() is running in another thread, or it will
| deadlock.
|
| verify_request(self, request, client_address)
| Verify the request. May be overridden.
|
| Return True if we should proceed with this request.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketserver.BaseServer:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketserver.BaseServer:
|
| timeout = None
class MulticastSubserverRequestHandler(socketserver.BaseRequestHandler)
| MulticastSubserverRequestHandler(request, client_address, server)
|
| The request handler passed to the multicast subserver. This invokes a method
| in the parent server to handle the data from the multicast and add the peer
| to the pool of known peers.
|
| Method resolution order:
| MulticastSubserverRequestHandler
| socketserver.BaseRequestHandler
| builtins.object
|
| Methods defined here:
|
| handle(self)
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.BaseRequestHandler:
|
| __init__(self, request, client_address, server)
| Initialize self. See help(type(self)) for accurate signature.
|
| finish(self)
|
| setup(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketserver.BaseRequestHandler:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
class TestHandler(socketserver.BaseRequestHandler)
| TestHandler(request, client_address, server)
|
| Simple request hander for basic testing.
|
| Method resolution order:
| TestHandler
| socketserver.BaseRequestHandler
| builtins.object
|
| Methods defined here:
|
| handle(self)
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.BaseRequestHandler:
|
| __init__(self, request, client_address, server)
| Initialize self. See help(type(self)) for accurate signature.
|
| finish(self)
|
| setup(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketserver.BaseRequestHandler:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
FUNCTIONS
add_multicast_argparse_groups(parser, multicast_address='0.0.0.0', multicast_port=32768, multicast_group='224.4.4.4', multicast_interval=300)
Add Multicast arguments to argument parser.
multicast(message, group, ports, bind_address=None)
Send a multicast message.
multicast_announcer(message_prefix, get_server_uris, group='224.4.4.4', ports=32768, interval=300, delay=1, interfaces=None)
Periodically announce presence via multicast.
DATA
DAEMON_THREADS = True
MULTICAST_GROUP = '224.4.4.4'
MULTICAST_INTERVAL = 300
MULTICAST_PORT = 32768
ThreadedServers.Pacserve
NAME
ThreadedServers.Pacserve
CLASSES
ThreadedServers.PeeredQuickserve.PeeredQuickserveRequestHandler(ThreadedServers.Quickserve.QuickserveRequestHandler)
PacserveRequestHandler
ThreadedServers.PeeredQuickserve.PeeredQuickserveServer(ThreadedServers.Quickserve.QuickserveServer, ThreadedServers.Multicast.MulticastPeerManager, ThreadedServers.Avahi.AvahiPeerManager)
PacserveServer
class PacserveRequestHandler(ThreadedServers.PeeredQuickserve.PeeredQuickserveRequestHandler)
| PacserveRequestHandler(*args, **kwargs)
|
| Pacserve request handler.
|
| Method resolution order:
| PacserveRequestHandler
| ThreadedServers.PeeredQuickserve.PeeredQuickserveRequestHandler
| ThreadedServers.Quickserve.QuickserveRequestHandler
| ThreadedServers.HTTPS.BaseHTTPSRequestHandler
| http.server.BaseHTTPRequestHandler
| socketserver.StreamRequestHandler
| socketserver.BaseRequestHandler
| builtins.object
|
| Methods defined here:
|
| handle_unresolved(self)
|
| parse_path(self)
|
| redirect_to_mirror(self)
|
| version_string(self)
| Return the server software version string.
|
| ----------------------------------------------------------------------
| Methods inherited from ThreadedServers.PeeredQuickserve.PeeredQuickserveRequestHandler:
|
| do_authenticated_GET_or_HEAD(self, extend_resolved=None)
|
| do_authenticated_POST(self)
|
| handle_custom(self)
|
| ----------------------------------------------------------------------
| Methods inherited from ThreadedServers.Quickserve.QuickserveRequestHandler:
|
| do_authenticated_GET(self)
|
| do_authenticated_HEAD(self)
|
| unparse_path(self, path=None, page=None, extra_qs=None, ignored_qs=None)
|
| use_index(self)
| Return a boolean value to indicate if an index page should be used for a
| directory request.
|
| ----------------------------------------------------------------------
| Methods inherited from ThreadedServers.HTTPS.BaseHTTPSRequestHandler:
|
| __init__(self, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| authenticate(self, method)
| Attempt to authenticate HTTP requests and reject those that fail.
|
| The specification only supports GET and POST methods. GET should be used for
| HEAD requests.
|
| The return value indicates if the authentication succeeded.
|
| create_nonce(self)
| Create a nonce value.
|
| do_GET(self)
|
| do_HEAD(self)
|
| do_POST(self)
|
| get_nonce(self, opaque, nc)
| Get a nonce value from a given opaque if the nonce count (nc) matches.
|
| get_realm(self)
| Return the realm. Can be overridden in subclasses.
|
| log_date_time_string(self)
| Return the current time formatted for logging.
|
| log_error(self, fmt, *args)
| Log an error.
|
| This is called when a request cannot be fulfilled. By
| default it passes the message on to log_message().
|
| Arguments are the same as for log_message().
|
| XXX This should go to the separate error log.
|
| log_message(self, fmt, *args)
| Log an arbitrary message.
|
| This is used by all other logging functions. Override
| it if you have specific logging wishes.
|
| The first argument, FORMAT, is a format string for the
| message to be logged. If the format string contains
| any % escapes requiring parameters, they should be
| specified as subsequent arguments (it's just like
| printf!).
|
| The client ip and current date/time are prefixed to
| every message.
|
| redirect(self, location='/', status_code=303, message=None, close=True)
| Redirect to a local server path.
|
| reject_unauthenticated_request(self)
| Reject an unauthenticated request.
|
| transfer_directory(self, dpaths, name, *args, include_body=True, compression=None, hide_path=None, **kwargs)
| Transfer a directory by recursivingly adding its contents to a tar file.
|
| dpaths:
| The directories to transfer.
|
| include_body:
| If True, transfer the content, else only transfer the header.
|
| compression:
| A compression type supported by Python's tarfile module.
|
| All other positional and keyword arguments are passed to tarfile.open.
|
| transfer_file(self, fpath, include_body=True, chunk_size=None)
| Transfer the contents of a file, with support for the Range header.
|
| transfer_html(self, html, include_body=True, status_code=200, close=True)
| Transfer a UTF-8-encoded HTML page.
|
| transfer_json(self, obj, include_body=True, status_code=200, close=True, *args, **kwargs)
| Transfer UTF-8-encoded JSON data.
|
| transfer_plaintext(self, text, include_body=True, status_code=200, close=True)
| Transfer a UTF-8-encoded plaintext page.
|
| transfer_utf8_content(self, content, content_type='application/octet-stream', include_body=True, status_code=200, encode=True, location=None, close=False)
| Convenience method for transferring UTF-8 encoded content.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from ThreadedServers.HTTPS.BaseHTTPSRequestHandler:
|
| NONCE_LENGTH = 32
|
| protocol_version = 'HTTP/1.1'
|
| ----------------------------------------------------------------------
| Methods inherited from http.server.BaseHTTPRequestHandler:
|
| address_string(self)
| Return the client address.
|
| date_time_string(self, timestamp=None)
| Return the current date and time formatted for a message header.
|
| end_headers(self)
| Send the blank line ending the MIME headers.
|
| flush_headers(self)
|
| handle(self)
| Handle multiple requests if necessary.
|
| handle_expect_100(self)
| Decide what to do with an "Expect: 100-continue" header.
|
| If the client is expecting a 100 Continue response, we must
| respond with either a 100 Continue or a final response before
| waiting for the request body. The default is to always respond
| with a 100 Continue. You can behave differently (for example,
| reject unauthorized requests) by overriding this method.
|
| This method should either return True (possibly after sending
| a 100 Continue response) or send an error response and return
| False.
|
| handle_one_request(self)
| Handle a single HTTP request.
|
| You normally don't need to override this method; see the class
| __doc__ string for information on how to handle specific HTTP
| commands such as GET and POST.
|
| log_request(self, code='-', size='-')
| Log an accepted request.
|
| This is called by send_response().
|
| parse_request(self)
| Parse a request (internal).
|
| The request should be stored in self.raw_requestline; the results
| are in self.command, self.path, self.request_version and
| self.headers.
|
| Return True for success, False for failure; on failure, any relevant
| error response has already been sent back.
|
| send_error(self, code, message=None, explain=None)
| Send and log an error reply.
|
| Arguments are
| * code: an HTTP error code
| 3 digits
| * message: a simple optional 1 line reason phrase.
| *( HTAB / SP / VCHAR / %x80-FF )
| defaults to short entry matching the response code
| * explain: a detailed message defaults to the long entry
| matching the response code.
|
| This sends an error response (so it must be called before any
| output has been generated), logs the error, and finally sends
| a piece of HTML explaining the error to the user.
|
| send_header(self, keyword, value)
| Send a MIME header to the headers buffer.
|
| send_response(self, code, message=None)
| Add the response header to the headers buffer and log the
| response code.
|
| Also send two standard headers with the server software
| version and the current date.
|
| send_response_only(self, code, message=None)
| Send the response header only.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from http.server.BaseHTTPRequestHandler:
|
| MessageClass = <class 'http.client.HTTPMessage'>
|
| default_request_version = 'HTTP/0.9'
|
| error_content_type = 'text/html;charset=utf-8'
|
| error_message_format = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//...
|
| monthname = [None, 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'A...
|
| responses = {<HTTPStatus.CONTINUE: 100>: ('Continue', 'Request receive...
|
| server_version = 'BaseHTTP/0.6'
|
| sys_version = 'Python/3.10.5'
|
| weekdayname = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.StreamRequestHandler:
|
| finish(self)
|
| setup(self)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketserver.StreamRequestHandler:
|
| disable_nagle_algorithm = False
|
| rbufsize = -1
|
| timeout = None
|
| wbufsize = 0
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketserver.BaseRequestHandler:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
class PacserveServer(ThreadedServers.PeeredQuickserve.PeeredQuickserveServer)
| PacserveServer(*args, **kwargs)
|
| Pacserve server.
|
| Method resolution order:
| PacserveServer
| ThreadedServers.PeeredQuickserve.PeeredQuickserveServer
| ThreadedServers.Quickserve.QuickserveServer
| ThreadedServers.HTTPS.HTTPSServer
| ThreadedServers.Base.BaseServer
| socketserver.ThreadingMixIn
| http.server.HTTPServer
| socketserver.TCPServer
| socketserver.BaseServer
| ThreadedServers.Multicast.MulticastPeerManager
| ThreadedServers.Avahi.AvahiPeerManager
| builtins.object
|
| Methods defined here:
|
| __init__(self, *args, **kwargs)
| paths:
| A map of server paths to lists of localdirectories or single files. If a
| list is given then the contents of the directories will appear to be
| merged in a single directory on the server. The order of the list
| determines which item will be displayed if the same entry appears in
| multiple directories.
|
| clean_house(self)
|
| hide_peer_path(self, path)
| Return True if a peer path should not be accessible on the server. This is
| meant to be overridden in subclasses.
|
| ----------------------------------------------------------------------
| Methods inherited from ThreadedServers.PeeredQuickserve.PeeredQuickserveServer:
|
| announce_presence(self, uri)
| Announce presence to the given URI.
|
| get_navlinks(self, handler, page_generator)
|
| get_server_info(self, paths)
| Return a list of 2-tuples containing data to be displayed in __str__.
|
| handle_peer(self, uri, origin)
| Handle a peer. This check if the IP and port refer to this server. If not,
| the URI is passed to the maybe_add_peer() method.
|
| maybe_add_peer(self, uri, origin)
| Add a peer to to the poor of known peers. This may be overridden in
| subclasses to reject peers based on arbitrary criteria. If a peer is
| rejected, the overridden method should return False.
|
| notify_peers(self, peers=None)
| Notify peers of presence via an HTTP POST announcement.
|
| respond_to_post(self, handler, obj)
|
| shutdown(self)
| Stops the serve_forever loop.
|
| Blocks until the loop has finished. This must be called while
| serve_forever() is running in another thread, or it will
| deadlock.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from ThreadedServers.PeeredQuickserve.PeeredQuickserveServer:
|
| DEFAULT_PEER_PORT = 8000
|
| DEFAULT_PEER_SCHEME = 'http'
|
| MAX_HOPS = 1
|
| ----------------------------------------------------------------------
| Methods inherited from ThreadedServers.Quickserve.QuickserveServer:
|
| __str__(self)
| Return str(self).
|
| directory_listing(self, serverpath, localpath)
| Return a dictionary of items in a directory.
|
| get_motd(self, handler)
| Return an MOTD message if one has been set, else an emptry string.
|
| get_upload_path(self, handler, filename)
| Return a local file path for saving an uploaded file.
|
| The returned path is temporary reserved to prevent other threads from using
| the same path before a file has been created. The path should be released
| with release_upload_path once the file has been created or the path is no
| longer needed.
|
| hide_path(self, serverpath)
| Return True to hide the given server path.
|
| This function must not call functions from the os.path module. Use the
| posixpath module instead.
|
| load_filters(self)
|
| load_paths(self)
|
| release_upload_path(self, handler, path)
| Release an upload path.
|
| resolve_path(self, serverpath, dir_listings=True)
| Resolve a server path to a local file path or directory listing.
|
| dir_listings:
| If True, return directory paths as listings, otherwise as strings.
|
| root_listing(self)
| Variation of directory_listing() for special handling of the root directory.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from ThreadedServers.Quickserve.QuickserveServer:
|
| MAX_UPLOAD_COUNT = 255
|
| ----------------------------------------------------------------------
| Methods inherited from ThreadedServers.HTTPS.HTTPSServer:
|
| delete_opaque(self, opaque)
|
| finish_request(self, request, client_address)
| Finish one request by instantiating RequestHandlerClass.
|
| get_request(self)
| Overridden method for SSL support.
|
| get_scheme(self)
| This should return a scheme for constructing URIs.
|
| get_server_uris(self, path='/')
| Generator over all local URIs via which the server is accessible.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from ThreadedServers.HTTPS.HTTPSServer:
|
| NC_LIMIT = 4294967295
|
| OPAQUE_TIMEOUT = 3600
|
| ----------------------------------------------------------------------
| Methods inherited from ThreadedServers.Base.BaseServer:
|
| get_address_and_port(self)
|
| get_address_header_and_string(self)
|
| is_local_address(self, address)
| Check if an address is local. Returns True if the address is listed by
| the local_ips() method.
|
| local_ifnames_and_ips(self)
| Return an iterator over the detected interfaces and local IP addresses.
|
| local_ips(self)
| Return an iterator over the detected local IP addresses.
|
| log_debug(self, msg)
|
| log_error(self, msg)
|
| log_message(self, msg)
|
| log_warning(self, msg)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from ThreadedServers.Base.BaseServer:
|
| daemon_threads = True
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.ThreadingMixIn:
|
| process_request(self, request, client_address)
| Start a new thread to process the request.
|
| process_request_thread(self, request, client_address)
| Same as in BaseServer but as a thread.
|
| In addition, exception handling is done here.
|
| server_close(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketserver.ThreadingMixIn:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketserver.ThreadingMixIn:
|
| block_on_close = True
|
| ----------------------------------------------------------------------
| Methods inherited from http.server.HTTPServer:
|
| server_bind(self)
| Override server_bind to store the server name.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from http.server.HTTPServer:
|
| allow_reuse_address = 1
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.TCPServer:
|
| close_request(self, request)
| Called to clean up an individual request.
|
| fileno(self)
| Return socket file number.
|
| Interface required by selector.
|
| server_activate(self)
| Called by constructor to activate the server.
|
| May be overridden.
|
| shutdown_request(self, request)
| Called to shutdown and close an individual request.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketserver.TCPServer:
|
| address_family = <AddressFamily.AF_INET: 2>
|
| request_queue_size = 5
|
| socket_type = <SocketKind.SOCK_STREAM: 1>
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.BaseServer:
|
| __enter__(self)
|
| __exit__(self, *args)
|
| handle_error(self, request, client_address)
| Handle an error gracefully. May be overridden.
|
| The default is to print a traceback and continue.
|
| handle_request(self)
| Handle one request, possibly blocking.
|
| Respects self.timeout.
|
| handle_timeout(self)
| Called if no new request arrives within self.timeout.
|
| Overridden by ForkingMixIn.
|
| serve_forever(self, poll_interval=0.5)
| Handle one request at a time until shutdown.
|
| Polls for shutdown every poll_interval seconds. Ignores
| self.timeout. If you need to do periodic tasks, do them in
| another thread.
|
| service_actions(self)
| Called by the serve_forever() loop.
|
| May be overridden by a subclass / Mixin to implement any code that
| needs to be run during the loop.
|
| verify_request(self, request, client_address)
| Verify the request. May be overridden.
|
| Return True if we should proceed with this request.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketserver.BaseServer:
|
| timeout = None
|
| ----------------------------------------------------------------------
| Methods inherited from ThreadedServers.Multicast.MulticastPeerManager:
|
| get_multicast_info(self)
| Get multicast information.
|
| get_multicast_prefix(self)
| The multicast prefix is prepended to the contents of the multicasts. Only
| multicasts with the same prefix will be processed.
|
| start_multicast_threads(self)
| Start the multicast subserver to listen for multicast requests and start a
| thread to periodically announce the presence of this server.
|
| ----------------------------------------------------------------------
| Methods inherited from ThreadedServers.Avahi.AvahiPeerManager:
|
| get_avahi_info(self)
|
| get_avahi_service_name(self, prefix_only=False)
| Get the version-specific service name.
|
| get_avahi_service_type(self)
| Get the appropriate avahi service type.
|
| start_avahi_threads(self)
| Start the listener and announcer threads.
FUNCTIONS
add_Pacserve_argparse_groups(parser)
is_package(path)
main(args=None)
search_pkgs(url, pkgnames, hops=1)
DATA
DEFAULT_MIMETYPE = 'application/xhtml+xml'
DEFAULT_PAGE_GENERATORS = {'application/json': <class 'ThreadedServers...
MULTICAST_GROUP = '224.3.45.67'
MULTICAST_PORT = 15679
NAME = 'ThreadedServers.Pacserve'
PACMAN_PSEUDODIRECTORY = 'pacman'
PORT = 15678
SERVER_PACKAGE_DIRECTORY = 'pkg'
VERSION = '2022'
VERSION_STRING = 'ThreadedServers.Pacserve/2022'
ThreadedServers.PageGenerators
NAME
ThreadedServers.PageGenerators
PACKAGE CONTENTS
JSON
XML
base
plaintext
DATA
DEFAULT_MIMETYPE = 'application/xhtml+xml'
DEFAULT_PAGE_GENERATORS = {'application/json': <class 'ThreadedServers...
ThreadedServers.PageGenerators.JSON
NAME
ThreadedServers.PageGenerators.JSON
CLASSES
ThreadedServers.PageGenerators.base.PageGenerator(builtins.object)
JSONPageGenerator
class JSONPageGenerator(ThreadedServers.PageGenerators.base.PageGenerator)
| Generate JSON pages.
|
| Method resolution order:
| JSONPageGenerator
| ThreadedServers.PageGenerators.base.PageGenerator
| builtins.object
|
| Methods defined here:
|
| format_link(self, href, name=None)
|
| format_list(self, items, ordered=False)
|
| format_section(self, title, content, level=1)
|
| format_size(self, s)
|
| format_table(self, rows, with_head=True, alignments=('l',))
| If `with_head` is True, the first row is treated as the table headers.
|
| `alignment` is a tuple of characters representing the alignment of each
| column. If there are fewer characters than columns, the last character
| should be used for the remaining columns.
|
| l: left
| r: right
| c: center
|
| format_text(self, text)
|
| format_text_link(self, href)
| Text links are links that appear in the body of the page, such as file
| and directory links in directory listings. For some outputs it is clearer
| to simply use plaintext.
|
| format_time(self, t)
|
| join(self, blocks)
| Join multiple blocks together, in order.
|
| send_upload_page(self, handler, n)
|
| transfer(self, handler, content)
| Transfer the content using the appropriate method of the handler.
|
| ----------------------------------------------------------------------
| Methods inherited from ThreadedServers.PageGenerators.base.PageGenerator:
|
| send_directory_listing(self, handler, entries)
|
| send_page(self, handler, content, title=None, extra_navlinks=None)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from ThreadedServers.PageGenerators.base.PageGenerator:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
ThreadedServers.PageGenerators.XML
NAME
ThreadedServers.PageGenerators.XML
CLASSES
ThreadedServers.PageGenerators.base.PageGenerator(builtins.object)
XHTMLPageGenerator
builtins.object
XML
class XHTMLPageGenerator(ThreadedServers.PageGenerators.base.PageGenerator)
| ############################## XHTMLPageGenerator ##############################
|
| Method resolution order:
| XHTMLPageGenerator
| ThreadedServers.PageGenerators.base.PageGenerator
| builtins.object
|
| Methods defined here:
|
| format_link(self, href, name=None)
|
| format_list(self, items, ordered=False, attrs=None)
|
| format_section(self, title, content, level=1)
|
| format_size(self, s)
|
| format_table(self, rows, with_head=True, alignments=('l',))
| If `with_head` is True, the first row is treated as the table headers.
|
| `alignment` is a tuple of characters representing the alignment of each
| column. If there are fewer characters than columns, the last character
| should be used for the remaining columns.
|
| l: left
| r: right
| c: center
|
| format_text(self, text)
|
| format_text_link(self, href)
| Text links are links that appear in the body of the page, such as file
| and directory links in directory listings. For some outputs it is clearer
| to simply use plaintext.
|
| format_time(self, t)
|
| get_html(self, content=None)
|
| get_html_head(self, title, extra_items=None, extra_style=None, javascript=None)
|
| get_html_style(self, extra_style=None, indent=None)
|
| iter_table_rows(self, rows)
|
| join(self, blocks)
| Join multiple blocks together, in order.
|
| send_page(self, handler, content, title=None, extra_navlinks=None, extra_head_items=None, extra_style=None, javascript=None)
|
| send_upload_page(self, handler, n)
|
| transfer(self, handler, content)
| Transfer the content using the appropriate method of the handler.
|
| zip(self, alignments, items)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| html_doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Str...htt...
|
| icon_png_b64 = 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAA...4+P...
|
| ----------------------------------------------------------------------
| Methods inherited from ThreadedServers.PageGenerators.base.PageGenerator:
|
| send_directory_listing(self, handler, entries)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from ThreadedServers.PageGenerators.base.PageGenerator:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
class XML(builtins.object)
| XML(tag, attrs=None, content=None, indent=' ')
|
| ##################################### XML ######################################
|
| Methods defined here:
|
| __init__(self, tag, attrs=None, content=None, indent=' ')
| Initialize self. See help(type(self)) for accurate signature.
|
| __str__(self, level=0)
| Return str(self).
|
| format_attrs(self, attrs=None)
|
| str(self, obj, level=0)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
DATA
AUTHOR = 'Xyne'
HOMEPAGE = 'http://xyne.archlinux.ca/projects/quickserve'
ThreadedServers.PageGenerators.base
NAME
ThreadedServers.PageGenerators.base
CLASSES
builtins.object
PageGenerator
class PageGenerator(builtins.object)
| Base class for implementing page generators.
|
| All content should be sent through send_page() to ensure consistency. The
| other send_* functions should only prepare the content passed to send_page().
|
| Methods defined here:
|
| format_link(self, href, name=None)
|
| format_list(self, items, ordered=False)
|
| format_section(self, title, content, level=1)
|
| format_size(self, text)
|
| format_table(self, rows, with_head=True, alignments=('l',))
| If `with_head` is True, the first row is treated as the table headers.
|
| `alignment` is a tuple of characters representing the alignment of each
| column. If there are fewer characters than columns, the last character
| should be used for the remaining columns.
|
| l: left
| r: right
| c: center
|
| format_text(self, text)
|
| format_text_link(self, href)
| Text links are links that appear in the body of the page, such as file
| and directory links in directory listings. For some outputs it is clearer
| to simply use plaintext.
|
| format_time(self, text)
|
| join(self, blocks)
| Join multiple blocks together, in order.
|
| send_directory_listing(self, handler, entries)
|
| send_page(self, handler, content, title=None, extra_navlinks=None)
|
| send_upload_page(self, handler, n)
|
| transfer(self, handler, content)
| Transfer the content using the appropriate method of the handler.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
ThreadedServers.PageGenerators.plaintext
NAME
ThreadedServers.PageGenerators.plaintext
CLASSES
ThreadedServers.PageGenerators.base.PageGenerator(builtins.object)
PlaintextPageGenerator
class PlaintextPageGenerator(ThreadedServers.PageGenerators.base.PageGenerator)
| Generate plaintext (markdown) pages.
|
| Method resolution order:
| PlaintextPageGenerator
| ThreadedServers.PageGenerators.base.PageGenerator
| builtins.object
|
| Methods defined here:
|
| create_format_string(self, widths, alignments)
|
| format_link(self, href, name=None)
|
| format_list(self, items, ordered=False)
|
| format_section(self, title, content, level=1)
|
| format_size(self, s)
|
| format_table(self, rows, with_head=True, alignments=('l',))
| If `with_head` is True, the first row is treated as the table headers.
|
| `alignment` is a tuple of characters representing the alignment of each
| column. If there are fewer characters than columns, the last character
| should be used for the remaining columns.
|
| l: left
| r: right
| c: center
|
| format_text(self, text)
|
| format_text_link(self, href)
| Text links are links that appear in the body of the page, such as file
| and directory links in directory listings. For some outputs it is clearer
| to simply use plaintext.
|
| format_time(self, t)
|
| join(self, blocks)
| Join multiple blocks together, in order.
|
| send_upload_page(self, handler, n)
|
| transfer(self, handler, content)
| Transfer the content using the appropriate method of the handler.
|
| ----------------------------------------------------------------------
| Methods inherited from ThreadedServers.PageGenerators.base.PageGenerator:
|
| send_directory_listing(self, handler, entries)
|
| send_page(self, handler, content, title=None, extra_navlinks=None)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from ThreadedServers.PageGenerators.base.PageGenerator:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
ThreadedServers.PeeredQuickserve
NAME
ThreadedServers.PeeredQuickserve
DESCRIPTION
# Overview
The main server is an HTTP(S) server that serves files and provides various
interfaces (HTML, JSON, plaintext, etc.?). The main server may optionally run a
UDP subserver to listen for multicasts. When a multicast is received with a
valid datagram, the sending server is added to the server pool and a direct
reply is sent via an HTTP POST to avoid multicast flooding.
The server also provides various functions via HTTP POST requests. These are
mostly used internally.
CLASSES
ThreadedServers.Avahi.AvahiPeerManager(builtins.object)
PeeredQuickserveServer(ThreadedServers.Quickserve.QuickserveServer, ThreadedServers.Multicast.MulticastPeerManager, ThreadedServers.Avahi.AvahiPeerManager)
ThreadedServers.Multicast.MulticastPeerManager(builtins.object)
PeeredQuickserveServer(ThreadedServers.Quickserve.QuickserveServer, ThreadedServers.Multicast.MulticastPeerManager, ThreadedServers.Avahi.AvahiPeerManager)
ThreadedServers.Quickserve.QuickserveRequestHandler(ThreadedServers.HTTPS.BaseHTTPSRequestHandler)
PeeredQuickserveRequestHandler
ThreadedServers.Quickserve.QuickserveServer(ThreadedServers.HTTPS.HTTPSServer)
PeeredQuickserveServer(ThreadedServers.Quickserve.QuickserveServer, ThreadedServers.Multicast.MulticastPeerManager, ThreadedServers.Avahi.AvahiPeerManager)
class PeeredQuickserveRequestHandler(ThreadedServers.Quickserve.QuickserveRequestHandler)
| PeeredQuickserveRequestHandler(*args, **kwargs)
|
| Pacserve request handler.
|
| Method resolution order:
| PeeredQuickserveRequestHandler
| ThreadedServers.Quickserve.QuickserveRequestHandler
| ThreadedServers.HTTPS.BaseHTTPSRequestHandler
| http.server.BaseHTTPRequestHandler
| socketserver.StreamRequestHandler
| socketserver.BaseRequestHandler
| builtins.object
|
| Methods defined here:
|
| do_authenticated_GET_or_HEAD(self, extend_resolved=None)
|
| do_authenticated_POST(self)
|
| handle_custom(self)
|
| handle_unresolved(self)
|
| version_string(self)
| Return the server software version string.
|
| ----------------------------------------------------------------------
| Methods inherited from ThreadedServers.Quickserve.QuickserveRequestHandler:
|
| do_authenticated_GET(self)
|
| do_authenticated_HEAD(self)
|
| parse_path(self)
|
| unparse_path(self, path=None, page=None, extra_qs=None, ignored_qs=None)
|
| use_index(self)
| Return a boolean value to indicate if an index page should be used for a
| directory request.
|
| ----------------------------------------------------------------------
| Methods inherited from ThreadedServers.HTTPS.BaseHTTPSRequestHandler:
|
| __init__(self, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| authenticate(self, method)
| Attempt to authenticate HTTP requests and reject those that fail.
|
| The specification only supports GET and POST methods. GET should be used for
| HEAD requests.
|
| The return value indicates if the authentication succeeded.
|
| create_nonce(self)
| Create a nonce value.
|
| do_GET(self)
|
| do_HEAD(self)
|
| do_POST(self)
|
| get_nonce(self, opaque, nc)
| Get a nonce value from a given opaque if the nonce count (nc) matches.
|
| get_realm(self)
| Return the realm. Can be overridden in subclasses.
|
| log_date_time_string(self)
| Return the current time formatted for logging.
|
| log_error(self, fmt, *args)
| Log an error.
|
| This is called when a request cannot be fulfilled. By
| default it passes the message on to log_message().
|
| Arguments are the same as for log_message().
|
| XXX This should go to the separate error log.
|
| log_message(self, fmt, *args)
| Log an arbitrary message.
|
| This is used by all other logging functions. Override
| it if you have specific logging wishes.
|
| The first argument, FORMAT, is a format string for the
| message to be logged. If the format string contains
| any % escapes requiring parameters, they should be
| specified as subsequent arguments (it's just like
| printf!).
|
| The client ip and current date/time are prefixed to
| every message.
|
| redirect(self, location='/', status_code=303, message=None, close=True)
| Redirect to a local server path.
|
| reject_unauthenticated_request(self)
| Reject an unauthenticated request.
|
| transfer_directory(self, dpaths, name, *args, include_body=True, compression=None, hide_path=None, **kwargs)
| Transfer a directory by recursivingly adding its contents to a tar file.
|
| dpaths:
| The directories to transfer.
|
| include_body:
| If True, transfer the content, else only transfer the header.
|
| compression:
| A compression type supported by Python's tarfile module.
|
| All other positional and keyword arguments are passed to tarfile.open.
|
| transfer_file(self, fpath, include_body=True, chunk_size=None)
| Transfer the contents of a file, with support for the Range header.
|
| transfer_html(self, html, include_body=True, status_code=200, close=True)
| Transfer a UTF-8-encoded HTML page.
|
| transfer_json(self, obj, include_body=True, status_code=200, close=True, *args, **kwargs)
| Transfer UTF-8-encoded JSON data.
|
| transfer_plaintext(self, text, include_body=True, status_code=200, close=True)
| Transfer a UTF-8-encoded plaintext page.
|
| transfer_utf8_content(self, content, content_type='application/octet-stream', include_body=True, status_code=200, encode=True, location=None, close=False)
| Convenience method for transferring UTF-8 encoded content.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from ThreadedServers.HTTPS.BaseHTTPSRequestHandler:
|
| NONCE_LENGTH = 32
|
| protocol_version = 'HTTP/1.1'
|
| ----------------------------------------------------------------------
| Methods inherited from http.server.BaseHTTPRequestHandler:
|
| address_string(self)
| Return the client address.
|
| date_time_string(self, timestamp=None)
| Return the current date and time formatted for a message header.
|
| end_headers(self)
| Send the blank line ending the MIME headers.
|
| flush_headers(self)
|
| handle(self)
| Handle multiple requests if necessary.
|
| handle_expect_100(self)
| Decide what to do with an "Expect: 100-continue" header.
|
| If the client is expecting a 100 Continue response, we must
| respond with either a 100 Continue or a final response before
| waiting for the request body. The default is to always respond
| with a 100 Continue. You can behave differently (for example,
| reject unauthorized requests) by overriding this method.
|
| This method should either return True (possibly after sending
| a 100 Continue response) or send an error response and return
| False.
|
| handle_one_request(self)
| Handle a single HTTP request.
|
| You normally don't need to override this method; see the class
| __doc__ string for information on how to handle specific HTTP
| commands such as GET and POST.
|
| log_request(self, code='-', size='-')
| Log an accepted request.
|
| This is called by send_response().
|
| parse_request(self)
| Parse a request (internal).
|
| The request should be stored in self.raw_requestline; the results
| are in self.command, self.path, self.request_version and
| self.headers.
|
| Return True for success, False for failure; on failure, any relevant
| error response has already been sent back.
|
| send_error(self, code, message=None, explain=None)
| Send and log an error reply.
|
| Arguments are
| * code: an HTTP error code
| 3 digits
| * message: a simple optional 1 line reason phrase.
| *( HTAB / SP / VCHAR / %x80-FF )
| defaults to short entry matching the response code
| * explain: a detailed message defaults to the long entry
| matching the response code.
|
| This sends an error response (so it must be called before any
| output has been generated), logs the error, and finally sends
| a piece of HTML explaining the error to the user.
|
| send_header(self, keyword, value)
| Send a MIME header to the headers buffer.
|
| send_response(self, code, message=None)
| Add the response header to the headers buffer and log the
| response code.
|
| Also send two standard headers with the server software
| version and the current date.
|
| send_response_only(self, code, message=None)
| Send the response header only.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from http.server.BaseHTTPRequestHandler:
|
| MessageClass = <class 'http.client.HTTPMessage'>
|
| default_request_version = 'HTTP/0.9'
|
| error_content_type = 'text/html;charset=utf-8'
|
| error_message_format = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//...
|
| monthname = [None, 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'A...
|
| responses = {<HTTPStatus.CONTINUE: 100>: ('Continue', 'Request receive...
|
| server_version = 'BaseHTTP/0.6'
|
| sys_version = 'Python/3.10.5'
|
| weekdayname = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.StreamRequestHandler:
|
| finish(self)
|
| setup(self)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketserver.StreamRequestHandler:
|
| disable_nagle_algorithm = False
|
| rbufsize = -1
|
| timeout = None
|
| wbufsize = 0
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketserver.BaseRequestHandler:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
class PeeredQuickserveServer(ThreadedServers.Quickserve.QuickserveServer, ThreadedServers.Multicast.MulticastPeerManager, ThreadedServers.Avahi.AvahiPeerManager)
| PeeredQuickserveServer(*args, **kwargs)
|
| Multicast-enabled Quickserve server.
|
| Method resolution order:
| PeeredQuickserveServer
| ThreadedServers.Quickserve.QuickserveServer
| ThreadedServers.HTTPS.HTTPSServer
| ThreadedServers.Base.BaseServer
| socketserver.ThreadingMixIn
| http.server.HTTPServer
| socketserver.TCPServer
| socketserver.BaseServer
| ThreadedServers.Multicast.MulticastPeerManager
| ThreadedServers.Avahi.AvahiPeerManager
| builtins.object
|
| Methods defined here:
|
| __init__(self, *args, **kwargs)
| paths:
| A map of server paths to lists of localdirectories or single files. If a
| list is given then the contents of the directories will appear to be
| merged in a single directory on the server. The order of the list
| determines which item will be displayed if the same entry appears in
| multiple directories.
|
| announce_presence(self, uri)
| Announce presence to the given URI.
|
| get_navlinks(self, handler, page_generator)
|
| get_server_info(self, paths)
| Return a list of 2-tuples containing data to be displayed in __str__.
|
| handle_peer(self, uri, origin)
| Handle a peer. This check if the IP and port refer to this server. If not,
| the URI is passed to the maybe_add_peer() method.
|
| maybe_add_peer(self, uri, origin)
| Add a peer to to the poor of known peers. This may be overridden in
| subclasses to reject peers based on arbitrary criteria. If a peer is
| rejected, the overridden method should return False.
|
| notify_peers(self, peers=None)
| Notify peers of presence via an HTTP POST announcement.
|
| respond_to_post(self, handler, obj)
|
| shutdown(self)
| Stops the serve_forever loop.
|
| Blocks until the loop has finished. This must be called while
| serve_forever() is running in another thread, or it will
| deadlock.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| hide_peer_path(_path)
| Return True if a peer path should not be accessible on the server. This is
| meant to be overridden in subclasses.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_PEER_PORT = 8000
|
| DEFAULT_PEER_SCHEME = 'http'
|
| MAX_HOPS = 1
|
| ----------------------------------------------------------------------
| Methods inherited from ThreadedServers.Quickserve.QuickserveServer:
|
| __str__(self)
| Return str(self).
|
| clean_house(self)
|
| directory_listing(self, serverpath, localpath)
| Return a dictionary of items in a directory.
|
| get_motd(self, handler)
| Return an MOTD message if one has been set, else an emptry string.
|
| get_upload_path(self, handler, filename)
| Return a local file path for saving an uploaded file.
|
| The returned path is temporary reserved to prevent other threads from using
| the same path before a file has been created. The path should be released
| with release_upload_path once the file has been created or the path is no
| longer needed.
|
| hide_path(self, serverpath)
| Return True to hide the given server path.
|
| This function must not call functions from the os.path module. Use the
| posixpath module instead.
|
| load_filters(self)
|
| load_paths(self)
|
| release_upload_path(self, handler, path)
| Release an upload path.
|
| resolve_path(self, serverpath, dir_listings=True)
| Resolve a server path to a local file path or directory listing.
|
| dir_listings:
| If True, return directory paths as listings, otherwise as strings.
|
| root_listing(self)
| Variation of directory_listing() for special handling of the root directory.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from ThreadedServers.Quickserve.QuickserveServer:
|
| MAX_UPLOAD_COUNT = 255
|
| ----------------------------------------------------------------------
| Methods inherited from ThreadedServers.HTTPS.HTTPSServer:
|
| delete_opaque(self, opaque)
|
| finish_request(self, request, client_address)
| Finish one request by instantiating RequestHandlerClass.
|
| get_request(self)
| Overridden method for SSL support.
|
| get_scheme(self)
| This should return a scheme for constructing URIs.
|
| get_server_uris(self, path='/')
| Generator over all local URIs via which the server is accessible.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from ThreadedServers.HTTPS.HTTPSServer:
|
| NC_LIMIT = 4294967295
|
| OPAQUE_TIMEOUT = 3600
|
| ----------------------------------------------------------------------
| Methods inherited from ThreadedServers.Base.BaseServer:
|
| get_address_and_port(self)
|
| get_address_header_and_string(self)
|
| is_local_address(self, address)
| Check if an address is local. Returns True if the address is listed by
| the local_ips() method.
|
| local_ifnames_and_ips(self)
| Return an iterator over the detected interfaces and local IP addresses.
|
| local_ips(self)
| Return an iterator over the detected local IP addresses.
|
| log_debug(self, msg)
|
| log_error(self, msg)
|
| log_message(self, msg)
|
| log_warning(self, msg)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from ThreadedServers.Base.BaseServer:
|
| daemon_threads = True
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.ThreadingMixIn:
|
| process_request(self, request, client_address)
| Start a new thread to process the request.
|
| process_request_thread(self, request, client_address)
| Same as in BaseServer but as a thread.
|
| In addition, exception handling is done here.
|
| server_close(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketserver.ThreadingMixIn:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketserver.ThreadingMixIn:
|
| block_on_close = True
|
| ----------------------------------------------------------------------
| Methods inherited from http.server.HTTPServer:
|
| server_bind(self)
| Override server_bind to store the server name.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from http.server.HTTPServer:
|
| allow_reuse_address = 1
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.TCPServer:
|
| close_request(self, request)
| Called to clean up an individual request.
|
| fileno(self)
| Return socket file number.
|
| Interface required by selector.
|
| server_activate(self)
| Called by constructor to activate the server.
|
| May be overridden.
|
| shutdown_request(self, request)
| Called to shutdown and close an individual request.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketserver.TCPServer:
|
| address_family = <AddressFamily.AF_INET: 2>
|
| request_queue_size = 5
|
| socket_type = <SocketKind.SOCK_STREAM: 1>
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.BaseServer:
|
| __enter__(self)
|
| __exit__(self, *args)
|
| handle_error(self, request, client_address)
| Handle an error gracefully. May be overridden.
|
| The default is to print a traceback and continue.
|
| handle_request(self)
| Handle one request, possibly blocking.
|
| Respects self.timeout.
|
| handle_timeout(self)
| Called if no new request arrives within self.timeout.
|
| Overridden by ForkingMixIn.
|
| serve_forever(self, poll_interval=0.5)
| Handle one request at a time until shutdown.
|
| Polls for shutdown every poll_interval seconds. Ignores
| self.timeout. If you need to do periodic tasks, do them in
| another thread.
|
| service_actions(self)
| Called by the serve_forever() loop.
|
| May be overridden by a subclass / Mixin to implement any code that
| needs to be run during the loop.
|
| verify_request(self, request, client_address)
| Verify the request. May be overridden.
|
| Return True if we should proceed with this request.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketserver.BaseServer:
|
| timeout = None
|
| ----------------------------------------------------------------------
| Methods inherited from ThreadedServers.Multicast.MulticastPeerManager:
|
| get_multicast_info(self)
| Get multicast information.
|
| get_multicast_prefix(self)
| The multicast prefix is prepended to the contents of the multicasts. Only
| multicasts with the same prefix will be processed.
|
| start_multicast_threads(self)
| Start the multicast subserver to listen for multicast requests and start a
| thread to periodically announce the presence of this server.
|
| ----------------------------------------------------------------------
| Methods inherited from ThreadedServers.Avahi.AvahiPeerManager:
|
| get_avahi_info(self)
|
| get_avahi_service_name(self, prefix_only=False)
| Get the version-specific service name.
|
| get_avahi_service_type(self)
| Get the appropriate avahi service type.
|
| start_avahi_threads(self)
| Start the listener and announcer threads.
FUNCTIONS
add_PeeredQuickserve_argparse_groups(parser)
Add PeeredQuickserve arguments to argument parser.
announce_presence(peer_url, own_url)
Post messages to known peers to announce presence.
main(args=None)
post_json(url, obj)
Post a JSON-encoded object to the given url under the given name and interpret
the response as a JSON object.
remote_directory_listing(url, path, hops=0)
Get a remote directory listing.
remote_file_check(url, paths, hops=0)
Check if the remove host has a file.
DATA
AVAHI_MODULES_FOUND = True
DEFAULT_MIMETYPE = 'application/xhtml+xml'
DEFAULT_PAGE_GENERATORS = {'application/json': <class 'ThreadedServers...
MULTICAST_GROUP = '224.3.45.66'
MULTICAST_PORT = 15680
NAME = 'ThreadedServers.PeeredQuickserve'
PAGE_PEERS = 'peers'
PORT = 8000
POST_DIR_LISTING = 'directory listing'
POST_FILE_CHECK = 'file check'
POST_NUDGE = 'nudge'
TIMEOUT = 3
VERSION = '2022'
VERSION_STRING = 'ThreadedServers.PeeredQuickserve/2022'
ThreadedServers.Quickserve
NAME
ThreadedServers.Quickserve
CLASSES
ThreadedServers.HTTPS.BaseHTTPSRequestHandler(http.server.BaseHTTPRequestHandler, builtins.object)
QuickserveRequestHandler
ThreadedServers.HTTPS.HTTPSServer(ThreadedServers.Base.BaseServer, http.server.HTTPServer)
QuickserveServer
class QuickserveRequestHandler(ThreadedServers.HTTPS.BaseHTTPSRequestHandler)
| QuickserveRequestHandler(*args, **kwargs)
|
| Quickserve request handler.
|
| Method resolution order:
| QuickserveRequestHandler
| ThreadedServers.HTTPS.BaseHTTPSRequestHandler
| http.server.BaseHTTPRequestHandler
| socketserver.StreamRequestHandler
| socketserver.BaseRequestHandler
| builtins.object
|
| Methods defined here:
|
| do_authenticated_GET(self)
|
| do_authenticated_GET_or_HEAD(self, extend_resolved=None)
|
| do_authenticated_HEAD(self)
|
| do_authenticated_POST(self)
|
| handle_custom(self)
|
| handle_unresolved(self)
|
| parse_path(self)
|
| unparse_path(self, path=None, page=None, extra_qs=None, ignored_qs=None)
|
| use_index(self)
| Return a boolean value to indicate if an index page should be used for a
| directory request.
|
| version_string(self)
| Return the server software version string.
|
| ----------------------------------------------------------------------
| Methods inherited from ThreadedServers.HTTPS.BaseHTTPSRequestHandler:
|
| __init__(self, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| authenticate(self, method)
| Attempt to authenticate HTTP requests and reject those that fail.
|
| The specification only supports GET and POST methods. GET should be used for
| HEAD requests.
|
| The return value indicates if the authentication succeeded.
|
| create_nonce(self)
| Create a nonce value.
|
| do_GET(self)
|
| do_HEAD(self)
|
| do_POST(self)
|
| get_nonce(self, opaque, nc)
| Get a nonce value from a given opaque if the nonce count (nc) matches.
|
| get_realm(self)
| Return the realm. Can be overridden in subclasses.
|
| log_date_time_string(self)
| Return the current time formatted for logging.
|
| log_error(self, fmt, *args)
| Log an error.
|
| This is called when a request cannot be fulfilled. By
| default it passes the message on to log_message().
|
| Arguments are the same as for log_message().
|
| XXX This should go to the separate error log.
|
| log_message(self, fmt, *args)
| Log an arbitrary message.
|
| This is used by all other logging functions. Override
| it if you have specific logging wishes.
|
| The first argument, FORMAT, is a format string for the
| message to be logged. If the format string contains
| any % escapes requiring parameters, they should be
| specified as subsequent arguments (it's just like
| printf!).
|
| The client ip and current date/time are prefixed to
| every message.
|
| redirect(self, location='/', status_code=303, message=None, close=True)
| Redirect to a local server path.
|
| reject_unauthenticated_request(self)
| Reject an unauthenticated request.
|
| transfer_directory(self, dpaths, name, *args, include_body=True, compression=None, hide_path=None, **kwargs)
| Transfer a directory by recursivingly adding its contents to a tar file.
|
| dpaths:
| The directories to transfer.
|
| include_body:
| If True, transfer the content, else only transfer the header.
|
| compression:
| A compression type supported by Python's tarfile module.
|
| All other positional and keyword arguments are passed to tarfile.open.
|
| transfer_file(self, fpath, include_body=True, chunk_size=None)
| Transfer the contents of a file, with support for the Range header.
|
| transfer_html(self, html, include_body=True, status_code=200, close=True)
| Transfer a UTF-8-encoded HTML page.
|
| transfer_json(self, obj, include_body=True, status_code=200, close=True, *args, **kwargs)
| Transfer UTF-8-encoded JSON data.
|
| transfer_plaintext(self, text, include_body=True, status_code=200, close=True)
| Transfer a UTF-8-encoded plaintext page.
|
| transfer_utf8_content(self, content, content_type='application/octet-stream', include_body=True, status_code=200, encode=True, location=None, close=False)
| Convenience method for transferring UTF-8 encoded content.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from ThreadedServers.HTTPS.BaseHTTPSRequestHandler:
|
| NONCE_LENGTH = 32
|
| protocol_version = 'HTTP/1.1'
|
| ----------------------------------------------------------------------
| Methods inherited from http.server.BaseHTTPRequestHandler:
|
| address_string(self)
| Return the client address.
|
| date_time_string(self, timestamp=None)
| Return the current date and time formatted for a message header.
|
| end_headers(self)
| Send the blank line ending the MIME headers.
|
| flush_headers(self)
|
| handle(self)
| Handle multiple requests if necessary.
|
| handle_expect_100(self)
| Decide what to do with an "Expect: 100-continue" header.
|
| If the client is expecting a 100 Continue response, we must
| respond with either a 100 Continue or a final response before
| waiting for the request body. The default is to always respond
| with a 100 Continue. You can behave differently (for example,
| reject unauthorized requests) by overriding this method.
|
| This method should either return True (possibly after sending
| a 100 Continue response) or send an error response and return
| False.
|
| handle_one_request(self)
| Handle a single HTTP request.
|
| You normally don't need to override this method; see the class
| __doc__ string for information on how to handle specific HTTP
| commands such as GET and POST.
|
| log_request(self, code='-', size='-')
| Log an accepted request.
|
| This is called by send_response().
|
| parse_request(self)
| Parse a request (internal).
|
| The request should be stored in self.raw_requestline; the results
| are in self.command, self.path, self.request_version and
| self.headers.
|
| Return True for success, False for failure; on failure, any relevant
| error response has already been sent back.
|
| send_error(self, code, message=None, explain=None)
| Send and log an error reply.
|
| Arguments are
| * code: an HTTP error code
| 3 digits
| * message: a simple optional 1 line reason phrase.
| *( HTAB / SP / VCHAR / %x80-FF )
| defaults to short entry matching the response code
| * explain: a detailed message defaults to the long entry
| matching the response code.
|
| This sends an error response (so it must be called before any
| output has been generated), logs the error, and finally sends
| a piece of HTML explaining the error to the user.
|
| send_header(self, keyword, value)
| Send a MIME header to the headers buffer.
|
| send_response(self, code, message=None)
| Add the response header to the headers buffer and log the
| response code.
|
| Also send two standard headers with the server software
| version and the current date.
|
| send_response_only(self, code, message=None)
| Send the response header only.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from http.server.BaseHTTPRequestHandler:
|
| MessageClass = <class 'http.client.HTTPMessage'>
|
| default_request_version = 'HTTP/0.9'
|
| error_content_type = 'text/html;charset=utf-8'
|
| error_message_format = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//...
|
| monthname = [None, 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'A...
|
| responses = {<HTTPStatus.CONTINUE: 100>: ('Continue', 'Request receive...
|
| server_version = 'BaseHTTP/0.6'
|
| sys_version = 'Python/3.10.5'
|
| weekdayname = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.StreamRequestHandler:
|
| finish(self)
|
| setup(self)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketserver.StreamRequestHandler:
|
| disable_nagle_algorithm = False
|
| rbufsize = -1
|
| timeout = None
|
| wbufsize = 0
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketserver.BaseRequestHandler:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
class QuickserveServer(ThreadedServers.HTTPS.HTTPSServer)
| QuickserveServer(address, handler, options, page_generators, *args, **kwargs)
|
| Baseclass file server.
|
| Method resolution order:
| QuickserveServer
| ThreadedServers.HTTPS.HTTPSServer
| ThreadedServers.Base.BaseServer
| socketserver.ThreadingMixIn
| http.server.HTTPServer
| socketserver.TCPServer
| socketserver.BaseServer
| builtins.object
|
| Methods defined here:
|
| __init__(self, address, handler, options, page_generators, *args, **kwargs)
| paths:
| A map of server paths to lists of localdirectories or single files. If a
| list is given then the contents of the directories will appear to be
| merged in a single directory on the server. The order of the list
| determines which item will be displayed if the same entry appears in
| multiple directories.
|
| __str__(self)
| Return str(self).
|
| clean_house(self)
|
| directory_listing(self, serverpath, localpath)
| Return a dictionary of items in a directory.
|
| get_motd(self, handler)
| Return an MOTD message if one has been set, else an emptry string.
|
| get_navlinks(self, handler, page_generator)
|
| get_server_info(self, paths)
| Return a list of 2-tuples containing data to be displayed in __str__.
|
| get_upload_path(self, handler, filename)
| Return a local file path for saving an uploaded file.
|
| The returned path is temporary reserved to prevent other threads from using
| the same path before a file has been created. The path should be released
| with release_upload_path once the file has been created or the path is no
| longer needed.
|
| hide_path(self, serverpath)
| Return True to hide the given server path.
|
| This function must not call functions from the os.path module. Use the
| posixpath module instead.
|
| load_filters(self)
|
| load_paths(self)
|
| release_upload_path(self, handler, path)
| Release an upload path.
|
| resolve_path(self, serverpath, dir_listings=True)
| Resolve a server path to a local file path or directory listing.
|
| dir_listings:
| If True, return directory paths as listings, otherwise as strings.
|
| root_listing(self)
| Variation of directory_listing() for special handling of the root directory.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| MAX_UPLOAD_COUNT = 255
|
| ----------------------------------------------------------------------
| Methods inherited from ThreadedServers.HTTPS.HTTPSServer:
|
| delete_opaque(self, opaque)
|
| finish_request(self, request, client_address)
| Finish one request by instantiating RequestHandlerClass.
|
| get_request(self)
| Overridden method for SSL support.
|
| get_scheme(self)
| This should return a scheme for constructing URIs.
|
| get_server_uris(self, path='/')
| Generator over all local URIs via which the server is accessible.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from ThreadedServers.HTTPS.HTTPSServer:
|
| NC_LIMIT = 4294967295
|
| OPAQUE_TIMEOUT = 3600
|
| ----------------------------------------------------------------------
| Methods inherited from ThreadedServers.Base.BaseServer:
|
| get_address_and_port(self)
|
| get_address_header_and_string(self)
|
| is_local_address(self, address)
| Check if an address is local. Returns True if the address is listed by
| the local_ips() method.
|
| local_ifnames_and_ips(self)
| Return an iterator over the detected interfaces and local IP addresses.
|
| local_ips(self)
| Return an iterator over the detected local IP addresses.
|
| log_debug(self, msg)
|
| log_error(self, msg)
|
| log_message(self, msg)
|
| log_warning(self, msg)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from ThreadedServers.Base.BaseServer:
|
| daemon_threads = True
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.ThreadingMixIn:
|
| process_request(self, request, client_address)
| Start a new thread to process the request.
|
| process_request_thread(self, request, client_address)
| Same as in BaseServer but as a thread.
|
| In addition, exception handling is done here.
|
| server_close(self)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from socketserver.ThreadingMixIn:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketserver.ThreadingMixIn:
|
| block_on_close = True
|
| ----------------------------------------------------------------------
| Methods inherited from http.server.HTTPServer:
|
| server_bind(self)
| Override server_bind to store the server name.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from http.server.HTTPServer:
|
| allow_reuse_address = 1
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.TCPServer:
|
| close_request(self, request)
| Called to clean up an individual request.
|
| fileno(self)
| Return socket file number.
|
| Interface required by selector.
|
| server_activate(self)
| Called by constructor to activate the server.
|
| May be overridden.
|
| shutdown_request(self, request)
| Called to shutdown and close an individual request.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketserver.TCPServer:
|
| address_family = <AddressFamily.AF_INET: 2>
|
| request_queue_size = 5
|
| socket_type = <SocketKind.SOCK_STREAM: 1>
|
| ----------------------------------------------------------------------
| Methods inherited from socketserver.BaseServer:
|
| __enter__(self)
|
| __exit__(self, *args)
|
| handle_error(self, request, client_address)
| Handle an error gracefully. May be overridden.
|
| The default is to print a traceback and continue.
|
| handle_request(self)
| Handle one request, possibly blocking.
|
| Respects self.timeout.
|
| handle_timeout(self)
| Called if no new request arrives within self.timeout.
|
| Overridden by ForkingMixIn.
|
| serve_forever(self, poll_interval=0.5)
| Handle one request at a time until shutdown.
|
| Polls for shutdown every poll_interval seconds. Ignores
| self.timeout. If you need to do periodic tasks, do them in
| another thread.
|
| service_actions(self)
| Called by the serve_forever() loop.
|
| May be overridden by a subclass / Mixin to implement any code that
| needs to be run during the loop.
|
| shutdown(self)
| Stops the serve_forever loop.
|
| Blocks until the loop has finished. This must be called while
| serve_forever() is running in another thread, or it will
| deadlock.
|
| verify_request(self, request, client_address)
| Verify the request. May be overridden.
|
| Return True if we should proceed with this request.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from socketserver.BaseServer:
|
| timeout = None
FUNCTIONS
add_Quickserve_argparse_groups(parser)
load_paths(newpaths, loadedpaths=None)
Load paths into a paths dictionary.
Files map their basenames to their paths. Directories map their basenames to
lists. This allows a single visible directory to include contents from
multiple real directories by adding more paths to the list.
load_paths_from_file(fpath, last_loaded=None)
main(args=None)
DATA
DEFAULT_CHUNK_SIZE = 4096
DEFAULT_MIMETYPE = 'application/xhtml+xml'
DEFAULT_PAGE_GENERATORS = {'application/json': <class 'ThreadedServers...
NAME = 'ThreadedServers.Quickserve'
TAR_COMPRESSIONS = ('none', 'gz', 'bz2', 'xz')
VERSION = '2022'
VERSION_STRING = 'ThreadedServers.Quickserve/2022'
ThreadedServers.__version__
NAME
ThreadedServers.__version__
VERSION
2022
ThreadedServers.common
NAME
ThreadedServers.common
CLASSES
builtins.Exception(builtins.BaseException)
ServerError
class ServerError(builtins.Exception)
| Method resolution order:
| ServerError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __delattr__(self, name, /)
| Implement delattr(self, name).
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setattr__(self, name, value, /)
| Implement setattr(self, name, value).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
FUNCTIONS
add_common_argparse_groups(parser, port=8000)
configure_logging()
format_seconds(s)
Format seconds for inferior humans.
format_size(size)
Format bytes for humans.
format_time(t=None, UTC=True)
Format UNIX time to a ISO 8601 format.
format_uri(scheme, host, port, path)
Format a URI.
get_all_interfaces(n_max=128)
Generator to iterate over 2-tuples of names and IP address for all interfaces.
get_ip_addresses(ifname)
Return the IP address of an interface (if it has one).
get_local_ipv6_addresses()
# TODO
# Check if there is a better way to do this.
get_name(f, p)
Call with __file__ and __package__.
handle_interrupt(signum, frame)
Attempt to exit on SIGINT (ctrl+c). Bind the signal handler to kill_myself()
for subsequent calls.
host_or_interface_to_ip(host_or_interface)
Given a host (as an IP address or a name) or an interface name, get an
IPV4Address or an IPV6Address. If the argument is empty or None, it is
returned without modification.
host_to_ip(host)
Convert a host to an instance of IPv4Address or IPv6Address. This will raise a
socket.gaierror if the host is not known.
host:
A host as a string that can be parsed by ipaddress.ip_address or
socket.gethostbyname.
iterate_qs(qs)
Iterate values from urllib.parse.parse_qs-parsed query strings.
kill_myself(signum, frame)
replace_interfaces_with_ips(args=None)
Replace interface names with IP addresses. Other arguments are unchanged. If
args is None, return all interface IPs.
replace_uri_host_and_get_port(uri, host='ungabunga', scheme='http', port=80)
Replace the network location in the given URI.
run(main, args=None)
serverpath_from_uripath(uripath)
The path is assumed to have been extracted with urllib.parse.urlsplit
serverpath_to_localpath(path, start=None)
# Compare http.server's "translate_path"
unbound_address(ip)
Check if the given IP is considered unbound.
unparse_qs(qs)
Recreate a query string, i.e. reverse urllib.parse.parse_qs.
DATA
AUTHOR = 'Xyne'
DAEMON_THREADS = True
DEFAULT_CHUNK_FACTOR = 16
DEFAULT_CHUNK_SIZE = 4096
HOMEPAGE = 'http://xyne.archlinux.ca/projects/quickserve'
ISO_8601_TIME_FORMAT = '%Y-%m-%d %H:%M:%S %Z'
RFC_2822_TIME_FORMAT = '%a, %d %b %Y %H:%M:%S %Z'
SIGINTS_BEFORE_SIGKILL = 1
SIGINTS_RECEIVED = 0
VERSION = '2022'
VERSION
2022