STINNER Victor email@example.com added the comment:
Please revert 360e1e4c519cfc139de707bcdd1e6c871eec79ee. It's not a good example to put into the documentation.
I looked at other examples: they are nice but far from a "real application". I like the last example which combines multiple wsgiref features and is written like a real application: parse command line arguments, handle CTRL+c, etc.
It uses different naming convention. It would only confuse users relatively new to the wsgiref module and WSGI protocol.
Would you mind to elaborate? I don't understand what you mean by "naming convention" here, sorry.
FileWrapper was supposed to support __getitem__ and __iter__ protocols for compatibility with older Python versions, but its __getiem__ implementation is buggy and is already deprecated. It has no use case in modern Python code.
Do you mean that app() must not return FileWrapper? How do you return file content in that case?
Maybe FileWrapper API should be clarified? It's surprising to read Python 3.8 mentioning compatibility with Python 2.1 :-)
It has zero exception handling and will return a cryptic traceback if mimetype cannot detect type of the file.
Which kind of exceptions do you expect? The example checks if the file exists for example.