Get rid of the initial_query= parameter on .connect()

This commit is contained in:
Lonami Exo 2017-09-17 16:06:43 +02:00
parent 2689b0750d
commit c84e54b647
2 changed files with 21 additions and 28 deletions

View File

@ -48,11 +48,10 @@ class CdnDecrypter:
#
# We assume that cdn_redirect.cdn_file_hashes are ordered by offset,
# and that there will be enough of these to retrieve the whole file.
cdn_file = cdn_client.connect(initial_query=GetCdnFileRequest(
file_token=cdn_redirect.file_token,
offset=cdn_redirect.cdn_file_hashes[0].offset,
limit=cdn_redirect.cdn_file_hashes[0].limit
))
#
# This relies on the fact that TelegramBareClient._dc_options is
# static and it won't be called from this DC (it would fail).
cdn_client.connect()
# CDN client is ready, create the resulting CdnDecrypter
decrypter = CdnDecrypter(
@ -60,6 +59,11 @@ class CdnDecrypter:
cdn_aes, cdn_redirect.cdn_file_hashes
)
cdn_file = client(GetCdnFileRequest(
file_token=cdn_redirect.file_token,
offset=cdn_redirect.cdn_file_hashes[0].offset,
limit=cdn_redirect.cdn_file_hashes[0].limit
))
if isinstance(cdn_file, CdnFileReuploadNeeded):
# We need to use the original client here
client(ReuploadCdnFileRequest(

View File

@ -94,7 +94,7 @@ class TelegramBareClient:
# region Connecting
def connect(self, exported_auth=None, initial_query=None):
def connect(self, exported_auth=None):
"""Connects to the Telegram servers, executing authentication if
required. Note that authenticating to the Telegram servers is
not the same as authenticating the desired user itself, which
@ -102,20 +102,13 @@ class TelegramBareClient:
If 'exported_auth' is not None, it will be used instead to
determine the authorization key for the current session.
If 'initial_query' is not None, it will override the default
'GetConfigRequest()', and its result will be returned ONLY
if the client wasn't connected already.
"""
if self._sender and self._sender.is_connected():
# Try sending a ping to make sure we're connected already
# TODO Maybe there's a better way to check this
try:
if initial_query is None:
self(PingRequest(utils.generate_random_long()))
return True
else:
return self(initial_query)
except:
# If ping failed, ensure we're disconnected first
self.disconnect()
@ -146,19 +139,15 @@ class TelegramBareClient:
self._init_connection(ImportAuthorizationRequest(
exported_auth.id, exported_auth.bytes
))
elif initial_query:
return self._init_connection(initial_query)
else:
TelegramBareClient._dc_options = \
self._init_connection(GetConfigRequest()).dc_options
else:
# TODO Avoid duplicated code
if exported_auth is not None:
elif exported_auth is not None:
self(ImportAuthorizationRequest(
exported_auth.id, exported_auth.bytes
))
elif initial_query:
return self(initial_query)
if TelegramBareClient._dc_options is None:
TelegramBareClient._dc_options = \
self(GetConfigRequest()).dc_options