|
|
|
@ -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. |
|
|
|
|