bencher.file_server =================== .. py:module:: bencher.file_server .. autoapi-nested-parse:: Serve files from a directory over HTTP with CORS headers (stdlib only). Classes ------- .. autoapisummary:: bencher.file_server._CORSHandler bencher.file_server._ReusableServer Functions --------- .. autoapisummary:: bencher.file_server.create_server bencher.file_server.run_file_server Module Contents --------------- .. py:class:: _CORSHandler(*args, directory=None, **kwargs) Bases: :py:obj:`http.server.SimpleHTTPRequestHandler` Static file handler with full CORS support (including preflight). .. py:method:: end_headers() Send the blank line ending the MIME headers. .. py:method:: do_OPTIONS() .. py:method:: log_message(*_args, **_kwargs) 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. Unicode control characters are replaced with escaped hex before writing the output to stderr. .. py:class:: _ReusableServer(server_address, RequestHandlerClass, bind_and_activate=True) Bases: :py:obj:`http.server.ThreadingHTTPServer` Mix-in class to handle each request in a new thread. .. py:attribute:: allow_reuse_address :value: True .. py:function:: create_server(directory, port=8001) Create an HTTP server serving *directory* on *port*. .. py:function:: run_file_server(directory=None, port=8001) Start a background HTTP file server (daemon thread). If *port* is already in use the existing server is assumed to be running and the function returns ``None`` instead of raising. Returns the ``ThreadingHTTPServer`` so callers can query ``server.server_address[1]`` for the actual port (useful when *port=0*).