Let File.ext work even with unknown mime types

This commit is contained in:
Lonami Exo 2019-06-26 11:31:15 +02:00
parent 80c9c5dad3
commit 4f1edeb750

View File

@ -1,4 +1,5 @@
import mimetypes import mimetypes
import os
from ... import utils from ... import utils
from ...tl import types from ...tl import types
@ -35,8 +36,15 @@ class File:
def ext(self): def ext(self):
""" """
The extension from the mime type of this file. The extension from the mime type of this file.
If the mime type is unknown, the extension
from the file name (if any) will be used.
""" """
return mimetypes.guess_extension(self.mime_type) return (
mimetypes.guess_extension(self.mime_type)
or os.path.splitext(self.name or '')[-1]
or None
)
@property @property
def mime_type(self): def mime_type(self):