mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
Issue #15207: Fix mimetypes to read from correct area in Windows registry (Original patch by Dave Chambers)
This commit is contained in:
parent
49e61806f5
commit
27a856495e
5 changed files with 21 additions and 11 deletions
|
@ -249,19 +249,21 @@ class MimeTypes:
|
|||
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')
|
||||
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