2020-03-21 14:43:32 +00:00
|
|
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
|
|
|
# Copyright (C) 2017-2020 Dan <https://github.com/delivrance>
|
2019-06-19 14:04:06 +00:00
|
|
|
#
|
2020-03-21 14:43:32 +00:00
|
|
|
# This file is part of Pyrogram.
|
2019-06-19 14:04:06 +00:00
|
|
|
#
|
2020-03-21 14:43:32 +00:00
|
|
|
# Pyrogram is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser General Public License as published
|
|
|
|
# by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
2019-06-19 14:04:06 +00:00
|
|
|
#
|
2020-03-21 14:43:32 +00:00
|
|
|
# Pyrogram is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Lesser General Public License for more details.
|
2019-06-19 14:04:06 +00:00
|
|
|
#
|
2020-03-21 14:43:32 +00:00
|
|
|
# You should have received a copy of the GNU Lesser General Public License
|
|
|
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
2019-06-19 14:04:06 +00:00
|
|
|
|
2019-09-14 17:39:21 +00:00
|
|
|
import base64
|
|
|
|
import struct
|
|
|
|
from typing import List, Tuple
|
|
|
|
|
2019-06-19 14:04:06 +00:00
|
|
|
|
|
|
|
class Storage:
|
2019-09-14 17:39:21 +00:00
|
|
|
SESSION_STRING_FORMAT = ">B?256sI?"
|
|
|
|
SESSION_STRING_SIZE = 351
|
|
|
|
|
2019-06-19 14:04:06 +00:00
|
|
|
def __init__(self, name: str):
|
|
|
|
self.name = name
|
|
|
|
|
2020-08-22 06:05:05 +00:00
|
|
|
async def open(self):
|
2019-06-19 14:04:06 +00:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2020-08-22 06:05:05 +00:00
|
|
|
async def save(self):
|
2019-06-19 14:04:06 +00:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2020-08-22 06:05:05 +00:00
|
|
|
async def close(self):
|
2019-06-19 14:04:06 +00:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2020-08-22 06:05:05 +00:00
|
|
|
async def delete(self):
|
2019-06-19 14:04:06 +00:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2020-08-22 06:05:05 +00:00
|
|
|
async def update_peers(self, peers: List[Tuple[int, int, str, str, str]]):
|
2019-06-19 14:04:06 +00:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2020-08-22 06:05:05 +00:00
|
|
|
async def get_peer_by_id(self, peer_id: int):
|
2019-06-19 14:04:06 +00:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2020-08-22 06:05:05 +00:00
|
|
|
async def get_peer_by_username(self, username: str):
|
2019-06-19 14:04:06 +00:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2020-08-22 06:05:05 +00:00
|
|
|
async def get_peer_by_phone_number(self, phone_number: str):
|
2019-06-19 14:04:06 +00:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2020-08-22 06:05:05 +00:00
|
|
|
async def dc_id(self, value: int = object):
|
2019-06-19 14:04:06 +00:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2020-08-22 06:05:05 +00:00
|
|
|
async def test_mode(self, value: bool = object):
|
2019-06-19 14:04:06 +00:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2020-08-22 06:05:05 +00:00
|
|
|
async def auth_key(self, value: bytes = object):
|
2019-06-19 14:04:06 +00:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2020-08-22 06:05:05 +00:00
|
|
|
async def date(self, value: int = object):
|
2019-06-19 14:04:06 +00:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2020-08-22 06:05:05 +00:00
|
|
|
async def user_id(self, value: int = object):
|
2019-06-19 14:04:06 +00:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2020-08-22 06:05:05 +00:00
|
|
|
async def is_bot(self, value: bool = object):
|
2019-06-19 14:04:06 +00:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2020-08-22 06:05:05 +00:00
|
|
|
async def export_session_string(self):
|
2019-09-14 17:39:21 +00:00
|
|
|
return base64.urlsafe_b64encode(
|
|
|
|
struct.pack(
|
|
|
|
self.SESSION_STRING_FORMAT,
|
2020-08-22 06:05:05 +00:00
|
|
|
await self.dc_id(),
|
|
|
|
await self.test_mode(),
|
|
|
|
await self.auth_key(),
|
|
|
|
await self.user_id(),
|
|
|
|
await self.is_bot()
|
2019-09-14 17:39:21 +00:00
|
|
|
)
|
|
|
|
).decode().rstrip("=")
|