April 2018
Intermediate to advanced
408 pages
10h 42m
English
One central feature of WSGI applications is that each stage along the chain is responsible for filtering the requests. The idea is to reject faulty requests as early in the processing as possible. Python's exception handling makes this particularly simple.
We can define a WSGI application that provides static content as follows:
def static_app( environ: Dict, start_response: SR_Func ) -> Union[Iterator[bytes], List[bytes]]: log = environ['wsgi.errors'] try: print(f"CWD={Path.cwd()}", file=log) static_path = Path.cwd()/environ['PATH_INFO'][1:] with static_path.open() as static_file: content = static_file.read().encode("utf-8") headers = [ ("Content-Type", 'text/plain;charset="utf-8"'), ("Content-Length", ...