From 4f1edeb7500a67858622c3407f33225754ac6c47 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Wed, 26 Jun 2019 11:31:15 +0200 Subject: [PATCH] Let File.ext work even with unknown mime types --- telethon/tl/custom/file.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/telethon/tl/custom/file.py b/telethon/tl/custom/file.py index 21e99d3e..1c17149a 100644 --- a/telethon/tl/custom/file.py +++ b/telethon/tl/custom/file.py @@ -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):