2018-03-02 00:34:32 +03:00
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
|
|
|
|
|
|
|
|
class Session(ABC):
|
2018-03-02 12:10:11 +03:00
|
|
|
def __init__(self):
|
2018-06-26 17:09:16 +03:00
|
|
|
pass
|
2018-03-02 12:10:11 +03:00
|
|
|
|
2018-03-02 14:20:11 +03:00
|
|
|
def clone(self, to_instance=None):
|
2018-03-03 14:13:42 +03:00
|
|
|
"""
|
|
|
|
Creates a clone of this session file.
|
|
|
|
"""
|
2018-06-26 17:09:16 +03:00
|
|
|
return to_instance or self.__class__()
|
2018-03-02 00:34:32 +03:00
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def set_dc(self, dc_id, server_address, port):
|
2018-03-03 14:13:42 +03:00
|
|
|
"""
|
|
|
|
Sets the information of the data center address and port that
|
|
|
|
the library should connect to, as well as the data center ID,
|
|
|
|
which is currently unused.
|
|
|
|
"""
|
2018-03-02 00:34:32 +03:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2019-05-06 09:55:24 +03:00
|
|
|
@property
|
|
|
|
@abstractmethod
|
|
|
|
def dc_id(self):
|
|
|
|
"""
|
|
|
|
Returns the currently-used data center ID.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2018-03-02 00:34:32 +03:00
|
|
|
@property
|
|
|
|
@abstractmethod
|
|
|
|
def server_address(self):
|
2018-03-03 14:13:42 +03:00
|
|
|
"""
|
|
|
|
Returns the server address where the library should connect to.
|
|
|
|
"""
|
2018-03-02 00:34:32 +03:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
@property
|
|
|
|
@abstractmethod
|
|
|
|
def port(self):
|
2018-03-03 14:13:42 +03:00
|
|
|
"""
|
|
|
|
Returns the port to which the library should connect to.
|
|
|
|
"""
|
2018-03-02 00:34:32 +03:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
@property
|
|
|
|
@abstractmethod
|
|
|
|
def auth_key(self):
|
2018-03-03 14:13:42 +03:00
|
|
|
"""
|
|
|
|
Returns an ``AuthKey`` instance associated with the saved
|
2019-07-06 13:10:25 +03:00
|
|
|
data center, or `None` if a new one should be generated.
|
2018-03-03 14:13:42 +03:00
|
|
|
"""
|
2018-03-02 00:34:32 +03:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
@auth_key.setter
|
|
|
|
@abstractmethod
|
|
|
|
def auth_key(self, value):
|
2018-03-03 14:13:42 +03:00
|
|
|
"""
|
|
|
|
Sets the ``AuthKey`` to be used for the saved data center.
|
|
|
|
"""
|
2018-03-02 00:34:32 +03:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2019-02-10 13:10:41 +03:00
|
|
|
@property
|
|
|
|
@abstractmethod
|
|
|
|
def takeout_id(self):
|
|
|
|
"""
|
|
|
|
Returns an ID of the takeout process initialized for this session,
|
2019-07-06 13:10:25 +03:00
|
|
|
or `None` if there's no were any unfinished takeout requests.
|
2019-02-10 13:10:41 +03:00
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
@takeout_id.setter
|
|
|
|
@abstractmethod
|
|
|
|
def takeout_id(self, value):
|
|
|
|
"""
|
|
|
|
Sets the ID of the unfinished takeout process for this session.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2018-04-25 14:37:29 +03:00
|
|
|
@abstractmethod
|
2021-12-20 19:52:02 +03:00
|
|
|
async def get_update_state(self, entity_id):
|
2018-04-25 14:37:29 +03:00
|
|
|
"""
|
|
|
|
Returns the ``UpdateState`` associated with the given `entity_id`.
|
|
|
|
If the `entity_id` is 0, it should return the ``UpdateState`` for
|
|
|
|
no specific channel (the "general" state). If no state is known
|
|
|
|
it should ``return None``.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
@abstractmethod
|
2021-12-20 19:52:02 +03:00
|
|
|
async def set_update_state(self, entity_id, state):
|
2018-04-25 14:37:29 +03:00
|
|
|
"""
|
|
|
|
Sets the given ``UpdateState`` for the specified `entity_id`, which
|
|
|
|
should be 0 if the ``UpdateState`` is the "general" state (and not
|
|
|
|
for any specific channel).
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2022-05-13 18:40:03 +03:00
|
|
|
@abstractmethod
|
|
|
|
async def get_update_states(self):
|
|
|
|
"""
|
|
|
|
Returns an iterable over all known pairs of ``(entity ID, update state)``.
|
|
|
|
"""
|
|
|
|
|
2018-03-02 00:34:32 +03:00
|
|
|
@abstractmethod
|
2021-12-20 19:52:02 +03:00
|
|
|
async def close(self):
|
2018-03-03 14:13:42 +03:00
|
|
|
"""
|
|
|
|
Called on client disconnection. Should be used to
|
|
|
|
free any used resources. Can be left empty if none.
|
|
|
|
"""
|
2018-03-02 00:34:32 +03:00
|
|
|
|
|
|
|
@abstractmethod
|
2021-12-20 19:52:02 +03:00
|
|
|
async def save(self):
|
2018-03-03 14:13:42 +03:00
|
|
|
"""
|
|
|
|
Called whenever important properties change. It should
|
|
|
|
make persist the relevant session information to disk.
|
|
|
|
"""
|
2018-03-02 00:34:32 +03:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
@abstractmethod
|
2021-12-20 19:52:02 +03:00
|
|
|
async def delete(self):
|
2018-03-03 14:13:42 +03:00
|
|
|
"""
|
|
|
|
Called upon client.log_out(). Should delete the stored
|
|
|
|
information from disk since it's not valid anymore.
|
|
|
|
"""
|
2018-03-02 00:34:32 +03:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
@abstractmethod
|
2021-12-20 19:52:02 +03:00
|
|
|
async def process_entities(self, tlo):
|
2018-03-03 14:13:42 +03:00
|
|
|
"""
|
|
|
|
Processes the input ``TLObject`` or ``list`` and saves
|
|
|
|
whatever information is relevant (e.g., ID or access hash).
|
|
|
|
"""
|
2018-03-02 00:34:32 +03:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
@abstractmethod
|
2021-12-20 19:52:02 +03:00
|
|
|
async def get_input_entity(self, key):
|
2018-03-03 14:13:42 +03:00
|
|
|
"""
|
|
|
|
Turns the given key into an ``InputPeer`` (e.g. ``InputPeerUser``).
|
|
|
|
The library uses this method whenever an ``InputPeer`` is needed
|
|
|
|
to suit several purposes (e.g. user only provided its ID or wishes
|
|
|
|
to use a cached username to avoid extra RPC).
|
|
|
|
"""
|
2018-03-02 00:34:32 +03:00
|
|
|
raise NotImplementedError
|