Allow switching from IPv4 to IPv6 and vice versa

This commit is contained in:
Lonami Exo 2017-11-16 13:40:25 +01:00
parent ee5915e86d
commit edd73ed69a

View File

@ -96,7 +96,9 @@ class TelegramBareClient:
'The given session must be a str or a Session instance.' 'The given session must be a str or a Session instance.'
) )
if not session.server_address: # ':' in session.server_address is True if it's an IPv6 address
if (not session.server_address or
(':' in session.server_address) != use_ipv6):
session.port = DEFAULT_PORT session.port = DEFAULT_PORT
session.server_address = \ session.server_address = \
DEFAULT_IPV6_IP if self._use_ipv6 else DEFAULT_IPV4_IP DEFAULT_IPV6_IP if self._use_ipv6 else DEFAULT_IPV4_IP