From 2462bdc3949354a32ddcb3273405e251d90d48ca Mon Sep 17 00:00:00 2001 From: luckydonald Date: Sun, 8 Nov 2020 21:14:27 +0100 Subject: [PATCH] Remove _rle_decode, _rle_encode, _decode_telegram_base64 and _encode_telegram_base64. Those will be available via tg_file_api.utils, if needed. --- telethon/utils.py | 61 ----------------------------------------------- 1 file changed, 61 deletions(-) diff --git a/telethon/utils.py b/telethon/utils.py index d6cb6465..f8045d15 100644 --- a/telethon/utils.py +++ b/telethon/utils.py @@ -1032,67 +1032,6 @@ def resolve_id(marked_id): return -marked_id, types.PeerChat -def _rle_decode(data): - """ - Decodes run-length-encoded `data`. - """ - if not data: - return data - - new = b'' - last = b'' - for cur in data: - if last == b'\0': - new += last * cur - last = b'' - else: - new += last - last = bytes([cur]) - - return new + last - - -def _rle_encode(string): - new = b'' - count = 0 - for cur in string: - if not cur: - count += 1 - else: - if count: - new += b'\0' + bytes([count]) - count = 0 - - new += bytes([cur]) - return new - - -def _decode_telegram_base64(string): - """ - Decodes a url-safe base64-encoded string into its bytes - by first adding the stripped necessary padding characters. - - This is the way Telegram shares binary data as strings, - such as Bot API-style file IDs or invite links. - - Returns `None` if the input string was not valid. - """ - try: - return base64.urlsafe_b64decode(string + '=' * (len(string) % 4)) - except (binascii.Error, ValueError, TypeError): - return None # not valid base64, not valid ascii, not a string - - -def _encode_telegram_base64(string): - """ - Inverse for `_decode_telegram_base64`. - """ - try: - return base64.urlsafe_b64encode(string).rstrip(b'=').decode('ascii') - except (binascii.Error, ValueError, TypeError): - return None # not valid base64, not valid ascii, not a string - - def resolve_bot_file_id(file_id): """ Given a Bot API-style `file_id `,