Thanks, Tim! Works for me! A couple of code review comments:
1) On 2.7, guess_type(s)[0] is a byte string as usual if the type doesn't exist in the registry, but it's a unicode string if it came from the registry. Seems like it should be a byte string in all cases (the mime type can only be ASCII char). I would say .encode('ascii') and if it raises UnicodeError, ignore that key.
2) Would 'subkeyname[0] == "."' be better as subkeyname.startswith(".")? More idiomatic, and won't bomb out if subkeyname is zero length (though that probably can't happen). Relatedly, "not subkeyname.startswith()" with an early-continue would avoid an indent and is what the rest of the code does.
3) I believe the default_encoding variable is not needed anymore. That was used in the old registry code.
4) Super-minor: "raises EnvironmentError" would be the Pythonic way to say "throws EnvironmentError".
5) Would it be worth adding a test for 'foo.png' as well, as that was another super-common type that was wrong? |