From f5c5110ce20c437fe5c0b6f620b9cfdf194bc3f0 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sun, 12 Nov 2017 12:20:57 +0100 Subject: [PATCH] Clean-up use_v6 usage --- telethon/telegram_bare_client.py | 12 +++++++++++- telethon/tl/session.py | 15 ++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/telethon/telegram_bare_client.py b/telethon/telegram_bare_client.py index b9329689..5c92a97c 100644 --- a/telethon/telegram_bare_client.py +++ b/telethon/telegram_bare_client.py @@ -39,6 +39,11 @@ from .update_state import UpdateState from .utils import get_appropriated_part_size +DEFAULT_IPV4_IP = '149.154.167.51' +DEFAULT_IPV6_IP = '[2001:67c:4e8:f002::a]' +DEFAULT_PORT = 443 + + class TelegramBareClient: """Bare Telegram Client with just the minimum - @@ -83,12 +88,17 @@ class TelegramBareClient: # Determine what session object we have if isinstance(session, str) or session is None: - session = Session.try_load_or_create_new(session, use_v6) + session = Session.try_load_or_create_new(session) elif not isinstance(session, Session): raise ValueError( 'The given session must be a str or a Session instance.' ) + if not session.server_address: + session.port = DEFAULT_PORT + session.server_address = \ + DEFAULT_IPV6_IP if use_v6 else DEFAULT_IPV4_IP + self.session = session self.api_id = int(api_id) self.api_hash = api_hash diff --git a/telethon/tl/session.py b/telethon/tl/session.py index 6ded7dc8..bbdcc590 100644 --- a/telethon/tl/session.py +++ b/telethon/tl/session.py @@ -18,7 +18,7 @@ class Session: If you think the session has been compromised, close all the sessions through an official Telegram client to revoke the authorization. """ - def __init__(self, session_user_id, use_v6=False): + def __init__(self, session_user_id): """session_user_id should either be a string or another Session. Note that if another session is given, only parameters like those required to init a connection will be copied. @@ -64,11 +64,8 @@ class Session: self._last_msg_id = 0 # Long # These values will be saved - if use_v6: - self.server_address = '[2001:67c:4e8:f002::a]' - else: - self.server_address = '91.108.56.165' - self.port = 443 + self.server_address = None + self.port = None self.auth_key = None self.layer = 0 self.salt = 0 # Unsigned long @@ -112,15 +109,15 @@ class Session: for f in os.listdir('.') if f.endswith('.session')] @staticmethod - def try_load_or_create_new(session_user_id, use_v6=False): + def try_load_or_create_new(session_user_id): """Loads a saved session_user_id.session or creates a new one. If session_user_id=None, later .save()'s will have no effect. """ if session_user_id is None: - return Session(None, use_v6) + return Session(None) else: path = '{}.session'.format(session_user_id) - result = Session(session_user_id, use_v6) + result = Session(session_user_id) if not file_exists(path): return result