Remove missed async keywords from the revert

This should've been in 7d21b40401.
This completes the revert of async sessions.
This commit is contained in:
Lonami Exo
2022-08-30 12:39:17 +02:00
parent e87e6738b5
commit 48d7dbe90b
5 changed files with 7 additions and 24 deletions

View File

@@ -11,15 +11,6 @@ _STRUCT_PREFORMAT = '>B{}sH256s'
CURRENT_VERSION = '1'
class _AsyncString(str):
"""
Ugly hack to enable awaiting strings.
"""
def __await__(self):
yield
return self
class StringSession(MemorySession):
"""
This session file can be easily saved and loaded as a string. According
@@ -59,17 +50,14 @@ class StringSession(MemorySession):
return base64.urlsafe_b64decode(x)
def save(self: Session):
# save should be async but that would break code which relies on sync StringSession.
# Return a type which behaves like a string for all intents and purposes, but can be awaited.
# The await is necessary for the library to save all sessions in the same way.
if not self.auth_key:
return _AsyncString('')
return ''
ip = ipaddress.ip_address(self.server_address).packed
return _AsyncString(CURRENT_VERSION + StringSession.encode(struct.pack(
return CURRENT_VERSION + StringSession.encode(struct.pack(
_STRUCT_PREFORMAT.format(len(ip)),
self.dc_id,
ip,
self.port,
self.auth_key.key
)))
))