mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-02-16 19:41:07 +03:00
Let File.ext work even with unknown mime types
This commit is contained in:
parent
80c9c5dad3
commit
4f1edeb750
|
@ -1,4 +1,5 @@
|
|||
import mimetypes
|
||||
import os
|
||||
|
||||
from ... import utils
|
||||
from ...tl import types
|
||||
|
@ -35,8 +36,15 @@ class File:
|
|||
def ext(self):
|
||||
"""
|
||||
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
|
||||
def mime_type(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user