diff options
Diffstat (limited to 'Lib/mimetypes.py')
-rw-r--r-- | Lib/mimetypes.py | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py index 7f28b89..ec8fd99 100644 --- a/Lib/mimetypes.py +++ b/Lib/mimetypes.py @@ -247,23 +247,26 @@ class MimeTypes: break i += 1 + default_encoding = sys.getdefaultencoding() with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr: for subkeyname in enum_types(hkcr): - # Only check file extensions, not all possible classes - if not subkeyname.startswith("."): - continue - - with _winreg.OpenKey(hkcr, subkeyname) as subkey: - # If there is no "Content Type" value, or if it is not - # a simple string, simply skip - try: + try: + with _winreg.OpenKey(hkcr, subkeyname) as subkey: + # Only check file extensions + if not subkeyname.startswith("."): + continue + # raises EnvironmentError if no 'Content Type' value mimetype, datatype = _winreg.QueryValueEx( subkey, 'Content Type') - except EnvironmentError: - continue - if datatype != _winreg.REG_SZ: - continue - self.add_type(mimetype, subkeyname, strict) + if datatype != _winreg.REG_SZ: + continue + try: + mimetype = mimetype.encode(default_encoding) + except UnicodeEncodeError: + continue + self.add_type(mimetype, subkeyname, strict) + except EnvironmentError: + continue def guess_type(url, strict=True): """Guess the type of a file based on its URL. |