Repository navigation
Keep webmapper importable on Python 3.13 (cgi removed) - #49
Merged
Merged
Conversation
The cgi module was removed in Python 3.13 (PEP 594). webmapper_http_server.py imported it at module level, so webmapper.py exited with ModuleNotFoundError before the server started. Only do_POST uses cgi, so the import moves into that method.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Python 3.13
python3 webmapper.pyexits before the server starts, becausewebmapper_http_server.pyimportscgiat module level and PEP 594 removed that module in 3.13. CI still builds with 3.11, so it does not show up there.The only user of
cgiisMprHTTPServer.do_POST, so this change moves the import into that method. Nothing else changes.What I ran, in
python:3.13-slimwithlibmapper==2.6.1,mappersession==0.0.18andnetifaces==0.11.0fromrequirements.txt, usingpython webmapper.py --no-browser --stay-alive --iface lo --port 50123and then aGET /:Something I noticed while checking
do_POST. It already fails on every Python 3 version before it reachescgi, becauseself.headers.getheader()is the Python 2 API. A multipartPOST /loadon 3.11 givesAttributeError: 'HTTPMessage' object has no attribute 'getheader'onmainand on this branch alike. I could not find a caller foron_load()injs/MapProperties.js, the only form that posts to/load, so I left the handler as it is. If you want it removed or ported offcgi, I can do that in a separate PR.Happy to adjust this or close it if it does not fit the project.