mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
Issue #15207: Fix mimetypes to read from correct area in Windows registry (Original patch by Dave Chambers)
This commit is contained in:
commit
a4df90ceb9
5 changed files with 23 additions and 13 deletions
|
@ -243,25 +243,27 @@ class MimeTypes:
|
|||
while True:
|
||||
try:
|
||||
ctype = _winreg.EnumKey(mimedb, i)
|
||||
except OSError:
|
||||
except EnvironmentError:
|
||||
break
|
||||
else:
|
||||
yield ctype
|
||||
i += 1
|
||||
|
||||
with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT,
|
||||
r'MIME\Database\Content Type') as mimedb:
|
||||
for ctype in enum_types(mimedb):
|
||||
with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr:
|
||||
for subkeyname in enum_types(hkcr):
|
||||
try:
|
||||
with _winreg.OpenKey(mimedb, ctype) as key:
|
||||
suffix, datatype = _winreg.QueryValueEx(key,
|
||||
'Extension')
|
||||
except OSError:
|
||||
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')
|
||||
if datatype != _winreg.REG_SZ:
|
||||
continue
|
||||
self.add_type(mimetype, subkeyname, strict)
|
||||
except EnvironmentError:
|
||||
continue
|
||||
if datatype != _winreg.REG_SZ:
|
||||
continue
|
||||
self.add_type(ctype, suffix, strict)
|
||||
|
||||
|
||||
def guess_type(url, strict=True):
|
||||
"""Guess the type of a file based on its URL.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue