MTPyroger/pyrogram/client/storage/storage.py

84 lines
2.4 KiB
Python
Raw Normal View History

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
def open(self):
raise NotImplementedError
def save(self):
raise NotImplementedError
def close(self):
raise NotImplementedError
2019-09-14 17:39:21 +00:00
def delete(self):
2019-06-19 14:04:06 +00:00
raise NotImplementedError
2019-09-14 17:39:21 +00:00
def update_peers(self, peers: List[Tuple[int, int, str, str, str]]):
2019-06-19 14:04:06 +00:00
raise NotImplementedError
2019-09-14 17:39:21 +00:00
def get_peer_by_id(self, peer_id: int):
2019-06-19 14:04:06 +00:00
raise NotImplementedError
2019-09-14 17:39:21 +00:00
def get_peer_by_username(self, username: str):
2019-06-19 14:04:06 +00:00
raise NotImplementedError
2019-09-14 17:39:21 +00:00
def get_peer_by_phone_number(self, phone_number: str):
2019-06-19 14:04:06 +00:00
raise NotImplementedError
2019-09-14 17:39:21 +00:00
def dc_id(self, value: int = object):
2019-06-19 14:04:06 +00:00
raise NotImplementedError
2019-09-14 17:39:21 +00:00
def test_mode(self, value: bool = object):
2019-06-19 14:04:06 +00:00
raise NotImplementedError
2019-09-14 17:39:21 +00:00
def auth_key(self, value: bytes = object):
2019-06-19 14:04:06 +00:00
raise NotImplementedError
2019-09-14 17:39:21 +00:00
def date(self, value: int = object):
2019-06-19 14:04:06 +00:00
raise NotImplementedError
2019-09-14 17:39:21 +00:00
def user_id(self, value: int = object):
2019-06-19 14:04:06 +00:00
raise NotImplementedError
2019-09-14 17:39:21 +00:00
def is_bot(self, value: bool = object):
2019-06-19 14:04:06 +00:00
raise NotImplementedError
2019-09-14 17:39:21 +00:00
def export_session_string(self):
return base64.urlsafe_b64encode(
struct.pack(
self.SESSION_STRING_FORMAT,
self.dc_id(),
self.test_mode(),
self.auth_key(),
self.user_id(),
self.is_bot()
)
).decode().rstrip("=")