mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 20:59:29 +00:00
Rename encode/decode to encode/decode_file_id
This commit is contained in:
parent
92c1b48132
commit
91d3508c13
@ -27,7 +27,7 @@ from . import BaseClient
|
||||
from ...api import types
|
||||
|
||||
|
||||
def decode(s: str) -> bytes:
|
||||
def decode_file_id(s: str) -> bytes:
|
||||
s = base64.urlsafe_b64decode(s + "=" * (-len(s) % 4))
|
||||
r = b""
|
||||
|
||||
@ -53,7 +53,7 @@ def decode(s: str) -> bytes:
|
||||
return r
|
||||
|
||||
|
||||
def encode(s: bytes) -> str:
|
||||
def encode_file_id(s: bytes) -> str:
|
||||
r = b""
|
||||
n = 0
|
||||
|
||||
@ -97,7 +97,7 @@ def get_input_media_from_file_id(
|
||||
expected_media_type: int = None
|
||||
) -> Union[types.InputMediaPhoto, types.InputMediaDocument]:
|
||||
try:
|
||||
decoded = decode(file_id_str)
|
||||
decoded = decode_file_id(file_id_str)
|
||||
except Exception:
|
||||
raise ValueError("Failed to decode file_id: {}".format(file_id_str))
|
||||
else:
|
||||
|
@ -141,7 +141,7 @@ class DownloadMedia(BaseClient):
|
||||
return dict(filter(lambda x: x[1] is not None, data.__dict__.items()))
|
||||
|
||||
try:
|
||||
decoded = utils.decode(file_id_str)
|
||||
decoded = utils.decode_file_id(file_id_str)
|
||||
media_type = decoded[0]
|
||||
|
||||
if media_type == 1:
|
||||
|
@ -55,7 +55,7 @@ class DeleteProfilePhotos(BaseClient):
|
||||
input_photos = []
|
||||
|
||||
for photo_id in photo_ids:
|
||||
unpacked = unpack("<iiqqc", utils.decode(photo_id))
|
||||
unpacked = unpack("<iiqqc", utils.decode_file_id(photo_id))
|
||||
|
||||
input_photos.append(
|
||||
types.InputPhoto(
|
||||
|
@ -23,7 +23,7 @@ import pyrogram
|
||||
from pyrogram.api import types
|
||||
from .thumbnail import Thumbnail
|
||||
from ..object import Object
|
||||
from ...ext.utils import encode, encode_file_ref
|
||||
from ...ext.utils import encode_file_id, encode_file_ref
|
||||
|
||||
|
||||
class Animation(Object):
|
||||
@ -97,7 +97,7 @@ class Animation(Object):
|
||||
file_name: str
|
||||
) -> "Animation":
|
||||
return Animation(
|
||||
file_id=encode(
|
||||
file_id=encode_file_id(
|
||||
pack(
|
||||
"<iiqq",
|
||||
10,
|
||||
|
@ -23,7 +23,7 @@ import pyrogram
|
||||
from pyrogram.api import types
|
||||
from .thumbnail import Thumbnail
|
||||
from ..object import Object
|
||||
from ...ext.utils import encode, encode_file_ref
|
||||
from ...ext.utils import encode_file_id, encode_file_ref
|
||||
|
||||
|
||||
class Audio(Object):
|
||||
@ -97,7 +97,7 @@ class Audio(Object):
|
||||
file_name: str
|
||||
) -> "Audio":
|
||||
return Audio(
|
||||
file_id=encode(
|
||||
file_id=encode_file_id(
|
||||
pack(
|
||||
"<iiqq",
|
||||
9,
|
||||
|
@ -23,7 +23,7 @@ import pyrogram
|
||||
from pyrogram.api import types
|
||||
from .thumbnail import Thumbnail
|
||||
from ..object import Object
|
||||
from ...ext.utils import encode, encode_file_ref
|
||||
from ...ext.utils import encode_file_id, encode_file_ref
|
||||
|
||||
|
||||
class Document(Object):
|
||||
@ -77,7 +77,7 @@ class Document(Object):
|
||||
@staticmethod
|
||||
def _parse(client, document: types.Document, file_name: str) -> "Document":
|
||||
return Document(
|
||||
file_id=encode(
|
||||
file_id=encode_file_id(
|
||||
pack(
|
||||
"<iiqq",
|
||||
5,
|
||||
|
@ -23,7 +23,7 @@ import pyrogram
|
||||
from pyrogram.api import types
|
||||
from .thumbnail import Thumbnail
|
||||
from ..object import Object
|
||||
from ...ext.utils import encode, encode_file_ref
|
||||
from ...ext.utils import encode_file_id, encode_file_ref
|
||||
|
||||
|
||||
class Photo(Object):
|
||||
@ -80,7 +80,7 @@ class Photo(Object):
|
||||
big = photo.sizes[-1]
|
||||
|
||||
return Photo(
|
||||
file_id=encode(
|
||||
file_id=encode_file_id(
|
||||
pack(
|
||||
"<iiqqqiiii",
|
||||
2, photo.dc_id, photo.id, photo.access_hash,
|
||||
|
@ -25,7 +25,7 @@ from pyrogram.api import types, functions
|
||||
from pyrogram.errors import StickersetInvalid
|
||||
from .thumbnail import Thumbnail
|
||||
from ..object import Object
|
||||
from ...ext.utils import encode, encode_file_ref
|
||||
from ...ext.utils import encode_file_id, encode_file_ref
|
||||
|
||||
|
||||
class Sticker(Object):
|
||||
@ -131,7 +131,7 @@ class Sticker(Object):
|
||||
set_name = None
|
||||
|
||||
return Sticker(
|
||||
file_id=encode(
|
||||
file_id=encode_file_id(
|
||||
pack(
|
||||
"<iiqq",
|
||||
8,
|
||||
|
@ -21,7 +21,7 @@ from typing import Union, List
|
||||
|
||||
import pyrogram
|
||||
from pyrogram.api import types
|
||||
from pyrogram.client.ext.utils import encode
|
||||
from pyrogram.client.ext.utils import encode_file_id
|
||||
from .stripped_thumbnail import StrippedThumbnail
|
||||
from ..object import Object
|
||||
|
||||
@ -85,7 +85,7 @@ class Thumbnail(Object):
|
||||
if isinstance(thumbnail, types.PhotoSize):
|
||||
thumbnails.append(
|
||||
Thumbnail(
|
||||
file_id=encode(
|
||||
file_id=encode_file_id(
|
||||
pack(
|
||||
"<iiqqqiiii",
|
||||
media_type, media.dc_id, media.id, media.access_hash,
|
||||
|
@ -23,7 +23,7 @@ import pyrogram
|
||||
from pyrogram.api import types
|
||||
from .thumbnail import Thumbnail
|
||||
from ..object import Object
|
||||
from ...ext.utils import encode, encode_file_ref
|
||||
from ...ext.utils import encode_file_id, encode_file_ref
|
||||
|
||||
|
||||
class Video(Object):
|
||||
@ -102,7 +102,7 @@ class Video(Object):
|
||||
file_name: str
|
||||
) -> "Video":
|
||||
return Video(
|
||||
file_id=encode(
|
||||
file_id=encode_file_id(
|
||||
pack(
|
||||
"<iiqq",
|
||||
4,
|
||||
|
@ -23,7 +23,7 @@ import pyrogram
|
||||
from pyrogram.api import types
|
||||
from .thumbnail import Thumbnail
|
||||
from ..object import Object
|
||||
from ...ext.utils import encode, encode_file_ref
|
||||
from ...ext.utils import encode_file_id, encode_file_ref
|
||||
|
||||
|
||||
class VideoNote(Object):
|
||||
@ -82,7 +82,7 @@ class VideoNote(Object):
|
||||
@staticmethod
|
||||
def _parse(client, video_note: types.Document, video_attributes: types.DocumentAttributeVideo) -> "VideoNote":
|
||||
return VideoNote(
|
||||
file_id=encode(
|
||||
file_id=encode_file_id(
|
||||
pack(
|
||||
"<iiqq",
|
||||
13,
|
||||
|
@ -21,7 +21,7 @@ from struct import pack
|
||||
import pyrogram
|
||||
from pyrogram.api import types
|
||||
from ..object import Object
|
||||
from ...ext.utils import encode, encode_file_ref
|
||||
from ...ext.utils import encode_file_id, encode_file_ref
|
||||
|
||||
|
||||
class Voice(Object):
|
||||
@ -75,7 +75,7 @@ class Voice(Object):
|
||||
@staticmethod
|
||||
def _parse(client, voice: types.Document, attributes: types.DocumentAttributeAudio) -> "Voice":
|
||||
return Voice(
|
||||
file_id=encode(
|
||||
file_id=encode_file_id(
|
||||
pack(
|
||||
"<iiqq",
|
||||
3,
|
||||
|
@ -22,7 +22,7 @@ import pyrogram
|
||||
from pyrogram.api import types
|
||||
from pyrogram.client.ext import utils
|
||||
from ..object import Object
|
||||
from ...ext.utils import encode
|
||||
from ...ext.utils import encode_file_id
|
||||
|
||||
|
||||
class ChatPhoto(Object):
|
||||
@ -73,7 +73,7 @@ class ChatPhoto(Object):
|
||||
x = -234
|
||||
|
||||
return ChatPhoto(
|
||||
small_file_id=encode(
|
||||
small_file_id=encode_file_id(
|
||||
pack(
|
||||
"<iiqqqiiiqi",
|
||||
1, chat_photo.dc_id, photo_id,
|
||||
@ -81,7 +81,7 @@ class ChatPhoto(Object):
|
||||
2, peer_id, x, peer_access_hash, loc_small.local_id
|
||||
)
|
||||
),
|
||||
big_file_id=encode(
|
||||
big_file_id=encode_file_id(
|
||||
pack(
|
||||
"<iiqqqiiiqi",
|
||||
1, chat_photo.dc_id, photo_id,
|
||||
|
Loading…
Reference in New Issue
Block a user