Fix StringSession(None)

This commit is contained in:
Lonami Exo 2018-08-05 19:45:56 +02:00
parent 0011f19f8b
commit 8ce001318e

View File

@ -18,12 +18,14 @@ class StringSession(MemorySession):
"""
def __init__(self, string=None):
super().__init__()
if string and string[0] != CURRENT_VERSION:
if string:
if string[0] != CURRENT_VERSION:
raise ValueError('Not a valid string')
ip_len = 4 if len(string) == 353 else 16
string = string[1:]
ip_len = 4 if len(string) == 352 else 16
self._dc_id, ip, self._port, key = struct.unpack(
'>B{}sH256s'.format(ip_len), base64.urlsafe_b64decode(string[1:]))
'>B{}sH256s'.format(ip_len), base64.urlsafe_b64decode(string))
self._server_address = ipaddress.ip_address(ip).compressed
if any(key):