mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-02-26 08:20:50 +03:00
Fix saving of StringSession
This commit is contained in:
parent
7d0efcf50f
commit
744f5f50fe
|
@ -20,6 +20,14 @@ class Session(ABC):
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
|
def dc_id(self):
|
||||||
|
"""
|
||||||
|
Returns the currently-used data center ID.
|
||||||
|
"""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def server_address(self):
|
def server_address(self):
|
||||||
|
|
|
@ -2,6 +2,7 @@ import base64
|
||||||
import ipaddress
|
import ipaddress
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
|
from .abstract import Session
|
||||||
from .memory import MemorySession
|
from .memory import MemorySession
|
||||||
from ..crypto import AuthKey
|
from ..crypto import AuthKey
|
||||||
|
|
||||||
|
@ -34,7 +35,7 @@ class StringSession(MemorySession):
|
||||||
string = string[1:]
|
string = string[1:]
|
||||||
ip_len = 4 if len(string) == 352 else 16
|
ip_len = 4 if len(string) == 352 else 16
|
||||||
self._dc_id, ip, self._port, key = struct.unpack(
|
self._dc_id, ip, self._port, key = struct.unpack(
|
||||||
_STRUCT_PREFORMAT.format(ip_len), self.decode(string))
|
_STRUCT_PREFORMAT.format(ip_len), StringSession.decode(string))
|
||||||
|
|
||||||
self._server_address = ipaddress.ip_address(ip).compressed
|
self._server_address = ipaddress.ip_address(ip).compressed
|
||||||
if any(key):
|
if any(key):
|
||||||
|
@ -48,15 +49,15 @@ class StringSession(MemorySession):
|
||||||
def decode(x: str) -> bytes:
|
def decode(x: str) -> bytes:
|
||||||
return base64.urlsafe_b64decode(x)
|
return base64.urlsafe_b64decode(x)
|
||||||
|
|
||||||
def save(self):
|
def save(self: Session):
|
||||||
if not self._auth_key:
|
if not self.auth_key:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
ip = ipaddress.ip_address(self._server_address).packed
|
ip = ipaddress.ip_address(self.server_address).packed
|
||||||
return CURRENT_VERSION + self.encode(struct.pack(
|
return CURRENT_VERSION + StringSession.encode(struct.pack(
|
||||||
_STRUCT_PREFORMAT.format(len(ip)),
|
_STRUCT_PREFORMAT.format(len(ip)),
|
||||||
self._dc_id,
|
self.dc_id,
|
||||||
ip,
|
ip,
|
||||||
self._port,
|
self.port,
|
||||||
self._auth_key.key
|
self.auth_key.key
|
||||||
))
|
))
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
# Versions should comply with PEP440.
|
# Versions should comply with PEP440.
|
||||||
# This line is parsed in setup.py:
|
# This line is parsed in setup.py:
|
||||||
__version__ = '1.7.6'
|
__version__ = '1.7.7'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user