mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-17 18:46:40 +00: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 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):
|
||||||
|
Loading…
Reference in New Issue
Block a user