summaryrefslogtreecommitdiff
path: root/Lib/mimetypes.py
diff options
context:
space:
mode:
authorBrian Curtin <brian.curtin@gmail.com>2010-10-21 14:11:48 +0000
committerBrian Curtin <brian.curtin@gmail.com>2010-10-21 14:11:48 +0000
commit000f974b44c570ea042e2e61823ae243dfb9b429 (patch)
tree23b8980f26f2caf50dbf43bd0c83a085ef27f0e1 /Lib/mimetypes.py
parent28928aef2ed23ae038ba2dd12b7adc51fa62805f (diff)
downloadcpython-git-000f974b44c570ea042e2e61823ae243dfb9b429.tar.gz
Fix #10162: Add try/except around _winreg.OpenKey for keys that are
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.
Diffstat (limited to 'Lib/mimetypes.py')
-rw-r--r--Lib/mimetypes.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py
index d5d0fc3461..9e7cbe8a20 100644
--- a/Lib/mimetypes.py
+++ b/Lib/mimetypes.py
@@ -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):