]> granicus.if.org Git - python/commitdiff
Fix #10162: Add try/except around _winreg.OpenKey for keys that are
authorBrian Curtin <brian.curtin@gmail.com>
Thu, 21 Oct 2010 14:11:48 +0000 (14:11 +0000)
committerBrian Curtin <brian.curtin@gmail.com>
Thu, 21 Oct 2010 14:11:48 +0000 (14:11 +0000)
unreadable by all users, e.g., Flash, Silverlight, and Java keys were
causing errors.

We don't currently have a way to grant/deny permissions for a key
via winreg so there are no tests for this.

Lib/mimetypes.py
Misc/NEWS

index d5d0fc346174ee301d1988daa696187a0e49d5e6..9e7cbe8a20535413fe65668ed0257ec0012911b4 100644 (file)
@@ -253,14 +253,16 @@ 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
-                    self.add_type(ctype, suffix, strict)
+                try:
+                    with _winreg.OpenKey(mimedb, ctype) as key:
+                        try:
+                            suffix, datatype = _winreg.QueryValueEx(key,
+                                                                'Extension')
+                except EnvironmentError:
+                    continue
+                if datatype != _winreg.REG_SZ:
+                    continue
+                self.add_type(ctype, suffix, strict)
 
 
 def guess_type(url, strict=True):
index caf1b49a7d0802acd863ffb9c9ed24d569743f4a..a93cad94bc29e056b317fadb4877d9414c06e973 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -43,6 +43,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #10163: Skip unreadable registry keys during mimetypes
+  initialization.
+
 - logging: Made StreamHandler terminator configurable.
 
 - logging: Allowed filters to be just callables.