summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/mimetypes.py25
-rw-r--r--Misc/NEWS3
2 files changed, 16 insertions, 12 deletions
diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py
index 816f6cd..4c054c9 100644
--- a/Lib/mimetypes.py
+++ b/Lib/mimetypes.py
@@ -257,18 +257,19 @@ class MimeTypes:
with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT,
r'MIME\Database\Content Type') as mimedb:
for ctype in enum_types(mimedb):
- with _winreg.OpenKey(mimedb, ctype) as key:
- try:
- suffix, datatype = _winreg.QueryValueEx(key, 'Extension')
- except EnvironmentError:
- continue
- if datatype != _winreg.REG_SZ:
- continue
- try:
- suffix = suffix.encode(default_encoding) # omit in 3.x!
- except UnicodeEncodeError:
- continue
- self.add_type(ctype, suffix, strict)
+ try:
+ with _winreg.OpenKey(mimedb, ctype) as key:
+ suffix, datatype = _winreg.QueryValueEx(key,
+ 'Extension')
+ except EnvironmentError:
+ continue
+ if datatype != _winreg.REG_SZ:
+ continue
+ try:
+ suffix = suffix.encode(default_encoding) # omit in 3.x!
+ except UnicodeEncodeError:
+ continue
+ self.add_type(ctype, suffix, strict)
def guess_type(url, strict=True):
diff --git a/Misc/NEWS b/Misc/NEWS
index f25664a..d25e25e 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -60,6 +60,9 @@ Core and Builtins
Library
-------
+- Issue #10163: Skip unreadable registry keys during mimetypes
+ initialization.
+
- Issue #5117: Fixed root directory related issue on posixpath.relpath() and
ntpath.relpath().