-
Notifications
You must be signed in to change notification settings - Fork 980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure makefsdata.py generates valid variable names #1841
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sounds sensible, if you're happy to put in the additional effort. The documentation for the mimetypes module suggests it relies on an external system-installed |
Sure, would be happy to add in those bits. The mimetypes module has a default, hard-coded map as well, and the system-installed files are only used to augment the map:
So we should be fine even if no system-wide I wrote a quick little script to check that all existing mappings exist in the defaults: import mimetypes
# Copied in from makefsdata.py
file_types = {
"html": "text/html",
"htm": "text/html",
"shtml": "text/html",
"shtm": "text/html",
"ssi": "text/html",
"gif": "image/gif",
"png": "image/png",
"jpg": "image/jpeg",
"bmp": "image/bmp",
"ico": "image/x-icon",
"class": "application/octet-stream",
"cls": "application/octet-stream",
"js": "application/javascript",
"ram": "application/javascript",
"css": "text/css",
"swf": "application/x-shockwave-flash",
"xml": "text/xml",
"xsl": "application/pdf",
"pdf": "text/xml",
"json": "application/json",
"svg": "image/svg+xml"
}
mimetypes.init(files=None)
for ext, mime in file_types.items():
guessed, _ = mimetypes.guess_type("abc." + ext)
if guessed != mime:
print(f"Diff: {ext}, expected: {mime}, got: {guessed}") I got this:
We can add in just these missing ones, but what's up with the current mappings for |
I have modified the code to use the mimetypes library and fixed another bug in the course of things. I don't know how important backwards compatibility is going to be for this, but here's how I've reconciled the differences between the hard-coded mimetypes and the library call:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. httpd example still works. Thanks!
Thanks, I've verified that this fixes the issue on Windows too. |
@kilograham Ok to merge this? |
@ndabas Were you still planning to add the "We could end up with duplicate variable names in some cases, if two or more file names differ only in special characters." feature? |
@lurch I wasn't planning to but I can if you think it's significant. Probably just a couple of extra lines of code? |
@lurch I gave it a shot and it was easier than expected. So that takes care of all of the issues I mentioned. |
This PR:
KeyError
.There are a couple more issues in the script which can potentially be fixed, please let me know if you think it's worthwhile to do so and I will add these changes too:
Fixes #1793.