This commit is contained in:
Kovid Goyal 2020-10-25 13:47:12 +05:30
parent 75a94bcd96
commit 30b8991a73
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -24,16 +24,21 @@ def is_rc_file(path: str) -> bool:
return '.' not in name and name.endswith('rc')
def initialize_mime_database() -> None:
if hasattr(initialize_mime_database, 'inited'):
return
setattr(initialize_mime_database, 'inited', True)
from mimetypes import init
init(None)
from kitty.constants import config_dir
local_defs = os.path.join(config_dir, 'mime.types')
if os.path.exists(local_defs):
init((local_defs,))
def guess_type(path: str) -> Optional[str]:
if not hasattr(guess_type, 'inited'):
setattr(guess_type, 'inited', True)
from mimetypes import init
init(None)
from kitty.constants import config_dir
local_defs = os.path.join(config_dir, 'mime.types')
if os.path.exists(local_defs):
init((local_defs,))
from mimetypes import guess_type as stdlib_guess_type
initialize_mime_database()
mt = None
with suppress(Exception):
mt = stdlib_guess_type(path)[0]