mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-08 04:52:30 +00:00
Apply several lints
This commit is contained in:
@@ -25,10 +25,7 @@ class StringSession(MemorySession):
|
||||
* `encode` definition must be ``def encode(value: bytes) -> str:``.
|
||||
* `decode` definition must be ``def decode(value: str) -> bytes:``.
|
||||
"""
|
||||
encode = lambda x: base64.urlsafe_b64encode(x).decode('ascii')
|
||||
decode = base64.urlsafe_b64decode
|
||||
|
||||
def __init__(self, string=None):
|
||||
def __init__(self, string: str = None):
|
||||
super().__init__()
|
||||
if string:
|
||||
if string[0] != CURRENT_VERSION:
|
||||
@@ -37,18 +34,26 @@ class StringSession(MemorySession):
|
||||
string = string[1:]
|
||||
ip_len = 4 if len(string) == 352 else 16
|
||||
self._dc_id, ip, self._port, key = struct.unpack(
|
||||
_STRUCT_PREFORMAT.format(ip_len), StringSession.decode(string))
|
||||
_STRUCT_PREFORMAT.format(ip_len), self.decode(string))
|
||||
|
||||
self._server_address = ipaddress.ip_address(ip).compressed
|
||||
if any(key):
|
||||
self._auth_key = AuthKey(key)
|
||||
|
||||
@staticmethod
|
||||
def encode(x: bytes) -> str:
|
||||
return base64.urlsafe_b64encode(x).decode('ascii')
|
||||
|
||||
@staticmethod
|
||||
def decode(x: str) -> bytes:
|
||||
return base64.urlsafe_b64decode(x)
|
||||
|
||||
def save(self):
|
||||
if not self._auth_key:
|
||||
return ''
|
||||
|
||||
ip = ipaddress.ip_address(self._server_address).packed
|
||||
return CURRENT_VERSION + StringSession.encode(struct.pack(
|
||||
return CURRENT_VERSION + self.encode(struct.pack(
|
||||
_STRUCT_PREFORMAT.format(len(ip)),
|
||||
self._dc_id,
|
||||
ip,
|
||||
|
Reference in New Issue
Block a user