Make allow_cache do nothing for now, bump v1.10.5 (#1272)

This commit is contained in:
Lonami Exo 2019-09-27 15:12:17 +02:00
parent a360d74a4c
commit 5e6ff67d01
2 changed files with 9 additions and 31 deletions

View File

@ -188,10 +188,9 @@ class UploadMethods:
Width/height and dimensions/size ratios may be important. Width/height and dimensions/size ratios may be important.
allow_cache (`bool`, optional): allow_cache (`bool`, optional):
Whether to allow using the cached version stored in the This parameter currently does nothing, but is kept for
database or not. Defaults to `True` to avoid re-uploads. backward-compatibility (and it may get its use back in
Must be `False` if you wish to use different attributes the future).
or thumb than those that were used when the file was cached.
parse_mode (`object`, optional): parse_mode (`object`, optional):
See the `TelegramClient.parse_mode See the `TelegramClient.parse_mode
@ -202,16 +201,10 @@ class UploadMethods:
voice_note (`bool`, optional): voice_note (`bool`, optional):
If `True` the audio will be sent as a voice note. If `True` the audio will be sent as a voice note.
Set `allow_cache` to `False` if you sent the same file
without this setting before for it to work.
video_note (`bool`, optional): video_note (`bool`, optional):
If `True` the video will be sent as a video note, If `True` the video will be sent as a video note,
also known as a round video message. also known as a round video message.
Set `allow_cache` to `False` if you sent the same file
without this setting before for it to work.
buttons (`list`, `custom.Button <telethon.tl.custom.button.Button>`, :tl:`KeyboardButton`): buttons (`list`, `custom.Button <telethon.tl.custom.button.Button>`, :tl:`KeyboardButton`):
The matrix (list of lists), row list or button to be shown The matrix (list of lists), row list or button to be shown
after sending the message. This parameter will only work if after sending the message. This parameter will only work if
@ -265,6 +258,7 @@ class UploadMethods:
'/my/drawings/portrait.png' '/my/drawings/portrait.png'
]) ])
""" """
# TODO Properly implement allow_cache to reuse the sha256 of the file
# i.e. `None` was used # i.e. `None` was used
if not file: if not file:
raise TypeError('Cannot use {!r} as file'.format(file)) raise TypeError('Cannot use {!r} as file'.format(file))
@ -457,11 +451,9 @@ class UploadMethods:
and if this is not a `str`, it will be ``"unnamed"``. and if this is not a `str`, it will be ``"unnamed"``.
use_cache (`type`, optional): use_cache (`type`, optional):
The type of cache to use (currently either :tl:`InputDocument` This parameter currently does nothing, but is kept for
or :tl:`InputPhoto`). If present and the file is small enough backward-compatibility (and it may get its use back in
to need the MD5, it will be checked against the database, the future).
and if a match is found, the upload won't be made. Instead,
an instance of type ``use_cache`` will be returned.
progress_callback (`callable`, optional): progress_callback (`callable`, optional):
A callback function accepting two parameters: A callback function accepting two parameters:
@ -551,12 +543,6 @@ class UploadMethods:
with open(file, 'rb') as stream: with open(file, 'rb') as stream:
file = stream.read() file = stream.read()
hash_md5.update(file) hash_md5.update(file)
if use_cache:
cached = self.session.get_file(
hash_md5.digest(), file_size, cls=_CacheType(use_cache)
)
if cached:
return cached
part_count = (file_size + part_size - 1) // part_size part_count = (file_size + part_size - 1) // part_size
self._log[__name__].info('Uploading file of %d bytes in %d chunks of %d', self._log[__name__].info('Uploading file of %d bytes in %d chunks of %d',
@ -635,12 +621,10 @@ class UploadMethods:
media = None media = None
file_handle = None file_handle = None
use_cache = types.InputPhoto if as_image else types.InputDocument
if not isinstance(file, str) or os.path.isfile(file): if not isinstance(file, str) or os.path.isfile(file):
file_handle = await self.upload_file( file_handle = await self.upload_file(
_resize_photo_if_needed(file, as_image), _resize_photo_if_needed(file, as_image),
progress_callback=progress_callback, progress_callback=progress_callback
use_cache=use_cache if allow_cache else None
) )
elif re.match('https?://', file): elif re.match('https?://', file):
if as_image: if as_image:
@ -661,12 +645,6 @@ class UploadMethods:
'Failed to convert {} to media. Not an existing file, ' 'Failed to convert {} to media. Not an existing file, '
'an HTTP URL or a valid bot-API-like file ID'.format(file) 'an HTTP URL or a valid bot-API-like file ID'.format(file)
) )
elif isinstance(file_handle, use_cache):
# File was cached, so an instance of use_cache was returned
if as_image:
media = types.InputMediaPhoto(file_handle)
else:
media = types.InputMediaDocument(file_handle)
elif as_image: elif as_image:
media = types.InputMediaUploadedPhoto(file_handle) media = types.InputMediaUploadedPhoto(file_handle)
else: else:

View File

@ -1,3 +1,3 @@
# Versions should comply with PEP440. # Versions should comply with PEP440.
# This line is parsed in setup.py: # This line is parsed in setup.py:
__version__ = '1.10.4' __version__ = '1.10.5'