Better flag argument name (use_v6 -> use_ipv6).
The flag is now stored into private classfield.
_get_dc ipv6 fix.
This commit is contained in:
Vladislav Kolesnichenko 2017-11-12 14:59:29 +03:00 committed by GitHub
parent f5c5110ce2
commit 07a36cfc76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -74,7 +74,7 @@ class TelegramBareClient:
def __init__(self, session, api_id, api_hash, def __init__(self, session, api_id, api_hash,
connection_mode=ConnectionMode.TCP_FULL, connection_mode=ConnectionMode.TCP_FULL,
use_v6=False, use_ipv6=False,
proxy=None, proxy=None,
update_workers=None, update_workers=None,
spawn_read_thread=False, spawn_read_thread=False,
@ -86,6 +86,8 @@ class TelegramBareClient:
"Your API ID or Hash cannot be empty or None. " "Your API ID or Hash cannot be empty or None. "
"Refer to Telethon's README.rst for more information.") "Refer to Telethon's README.rst for more information.")
self._use_ipv6 = use_ipv6
# Determine what session object we have # Determine what session object we have
if isinstance(session, str) or session is None: if isinstance(session, str) or session is None:
session = Session.try_load_or_create_new(session) session = Session.try_load_or_create_new(session)
@ -97,7 +99,7 @@ class TelegramBareClient:
if not session.server_address: if not session.server_address:
session.port = DEFAULT_PORT session.port = DEFAULT_PORT
session.server_address = \ session.server_address = \
DEFAULT_IPV6_IP if use_v6 else DEFAULT_IPV4_IP DEFAULT_IPV6_IP if self._use_ipv6 else DEFAULT_IPV4_IP
self.session = session self.session = session
self.api_id = int(api_id) self.api_id = int(api_id)
@ -298,7 +300,7 @@ class TelegramBareClient:
return self._recv_thread is not None and \ return self._recv_thread is not None and \
threading.get_ident() == self._recv_thread.ident threading.get_ident() == self._recv_thread.ident
def _get_dc(self, dc_id, ipv6=False, cdn=False): def _get_dc(self, dc_id, cdn=False):
"""Gets the Data Center (DC) associated to 'dc_id'""" """Gets the Data Center (DC) associated to 'dc_id'"""
if not TelegramBareClient._config: if not TelegramBareClient._config:
TelegramBareClient._config = self(GetConfigRequest()) TelegramBareClient._config = self(GetConfigRequest())
@ -311,7 +313,7 @@ class TelegramBareClient:
return next( return next(
dc for dc in TelegramBareClient._config.dc_options dc for dc in TelegramBareClient._config.dc_options
if dc.id == dc_id and bool(dc.ipv6) == ipv6 and bool(dc.cdn) == cdn if dc.id == dc_id and bool(dc.ipv6) == self._use_ipv6 and bool(dc.cdn) == cdn
) )
except StopIteration: except StopIteration:
if not cdn: if not cdn:
@ -319,7 +321,7 @@ class TelegramBareClient:
# New configuration, perhaps a new CDN was added? # New configuration, perhaps a new CDN was added?
TelegramBareClient._config = self(GetConfigRequest()) TelegramBareClient._config = self(GetConfigRequest())
return self._get_dc(dc_id, ipv6=ipv6, cdn=cdn) return self._get_dc(dc_id, cdn=cdn)
def _get_exported_client(self, dc_id): def _get_exported_client(self, dc_id):
"""Creates and connects a new TelegramBareClient for the desired DC. """Creates and connects a new TelegramBareClient for the desired DC.