From fc46e1ec20d731f5afb9ddc28d0c4043bfe3b867 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Tue, 25 Dec 2018 17:02:33 +0100 Subject: [PATCH] Workaround file references by using empty byte strings for cache They seem to work for now, so until there is a need to update it, cache will just rely on empty byte strings for the file_reference. --- telethon/client/uploads.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/telethon/client/uploads.py b/telethon/client/uploads.py index 549ca061..b2077e89 100644 --- a/telethon/client/uploads.py +++ b/telethon/client/uploads.py @@ -15,6 +15,18 @@ from ..tl import types, functions, custom __log__ = logging.getLogger(__name__) +class _CacheType: + """Like functools.partial but pretends to be the wrapped class.""" + def __init__(self, cls): + self._cls = cls + + def __call__(self, *args, **kwargs): + return self._cls(*args, file_reference=b'', **kwargs) + + def __eq__(self, other): + return self._cls == other + + class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods): # region Public methods @@ -332,7 +344,7 @@ class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods): hash_md5.update(file) if use_cache: cached = self.session.get_file( - hash_md5.digest(), file_size, cls=use_cache + hash_md5.digest(), file_size, cls=_CacheType(use_cache) ) if cached: return cached