mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-02-09 08:00:53 +03:00
Get rid of the initial_query= parameter on .connect()
This commit is contained in:
parent
2689b0750d
commit
c84e54b647
|
@ -48,11 +48,10 @@ class CdnDecrypter:
|
||||||
#
|
#
|
||||||
# We assume that cdn_redirect.cdn_file_hashes are ordered by offset,
|
# 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.
|
# 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,
|
# This relies on the fact that TelegramBareClient._dc_options is
|
||||||
offset=cdn_redirect.cdn_file_hashes[0].offset,
|
# static and it won't be called from this DC (it would fail).
|
||||||
limit=cdn_redirect.cdn_file_hashes[0].limit
|
cdn_client.connect()
|
||||||
))
|
|
||||||
|
|
||||||
# CDN client is ready, create the resulting CdnDecrypter
|
# CDN client is ready, create the resulting CdnDecrypter
|
||||||
decrypter = CdnDecrypter(
|
decrypter = CdnDecrypter(
|
||||||
|
@ -60,6 +59,11 @@ class CdnDecrypter:
|
||||||
cdn_aes, cdn_redirect.cdn_file_hashes
|
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):
|
if isinstance(cdn_file, CdnFileReuploadNeeded):
|
||||||
# We need to use the original client here
|
# We need to use the original client here
|
||||||
client(ReuploadCdnFileRequest(
|
client(ReuploadCdnFileRequest(
|
||||||
|
|
|
@ -94,7 +94,7 @@ class TelegramBareClient:
|
||||||
|
|
||||||
# region Connecting
|
# 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
|
"""Connects to the Telegram servers, executing authentication if
|
||||||
required. Note that authenticating to the Telegram servers is
|
required. Note that authenticating to the Telegram servers is
|
||||||
not the same as authenticating the desired user itself, which
|
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
|
If 'exported_auth' is not None, it will be used instead to
|
||||||
determine the authorization key for the current session.
|
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():
|
if self._sender and self._sender.is_connected():
|
||||||
# Try sending a ping to make sure we're connected already
|
# Try sending a ping to make sure we're connected already
|
||||||
# TODO Maybe there's a better way to check this
|
# TODO Maybe there's a better way to check this
|
||||||
try:
|
try:
|
||||||
if initial_query is None:
|
|
||||||
self(PingRequest(utils.generate_random_long()))
|
self(PingRequest(utils.generate_random_long()))
|
||||||
return True
|
return True
|
||||||
else:
|
|
||||||
return self(initial_query)
|
|
||||||
except:
|
except:
|
||||||
# If ping failed, ensure we're disconnected first
|
# If ping failed, ensure we're disconnected first
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
|
@ -146,19 +139,15 @@ class TelegramBareClient:
|
||||||
self._init_connection(ImportAuthorizationRequest(
|
self._init_connection(ImportAuthorizationRequest(
|
||||||
exported_auth.id, exported_auth.bytes
|
exported_auth.id, exported_auth.bytes
|
||||||
))
|
))
|
||||||
elif initial_query:
|
|
||||||
return self._init_connection(initial_query)
|
|
||||||
else:
|
else:
|
||||||
TelegramBareClient._dc_options = \
|
TelegramBareClient._dc_options = \
|
||||||
self._init_connection(GetConfigRequest()).dc_options
|
self._init_connection(GetConfigRequest()).dc_options
|
||||||
else:
|
|
||||||
# TODO Avoid duplicated code
|
elif exported_auth is not None:
|
||||||
if exported_auth is not None:
|
|
||||||
self(ImportAuthorizationRequest(
|
self(ImportAuthorizationRequest(
|
||||||
exported_auth.id, exported_auth.bytes
|
exported_auth.id, exported_auth.bytes
|
||||||
))
|
))
|
||||||
elif initial_query:
|
|
||||||
return self(initial_query)
|
|
||||||
if TelegramBareClient._dc_options is None:
|
if TelegramBareClient._dc_options is None:
|
||||||
TelegramBareClient._dc_options = \
|
TelegramBareClient._dc_options = \
|
||||||
self(GetConfigRequest()).dc_options
|
self(GetConfigRequest()).dc_options
|
||||||
|
|
Loading…
Reference in New Issue
Block a user