Allow using lists and dicts for passing proxy settings

This commit is contained in:
Dmitry D. Chernov 2017-06-05 14:04:01 +10:00 committed by Lonami
parent 3de398bae6
commit 5362f2578d
2 changed files with 6 additions and 3 deletions

View File

@ -234,8 +234,8 @@ Once this is done, pass the proxy settings to the ``TelegramClient`` constructor
... api_id=12345, api_hash='0123456789abcdef0123456789abcdef', ... api_id=12345, api_hash='0123456789abcdef0123456789abcdef',
... proxy=(socks.SOCKS5, 'localhost', 4444)) ... proxy=(socks.SOCKS5, 'localhost', 4444))
The ``proxy=`` parameter should be a tuple consisting of The ``proxy=`` argument should be a tuple, a list or a dict, consisting of parameters described
``(type, 'ip address', port)``, as described `here <https://github.com/Anorov/PySocks#sockssocksocket>`_. `here <https://github.com/Anorov/PySocks#usage-1>`_.
Disclaimer Disclaimer
========== ==========

View File

@ -25,7 +25,10 @@ class TcpClient:
else: else:
import socks import socks
self._socket = socks.socksocket(socket.AF_INET, socket.SOCK_STREAM) self._socket = socks.socksocket(socket.AF_INET, socket.SOCK_STREAM)
self._socket.set_proxy(*self._proxy) if type(self._proxy) is dict:
self._socket.set_proxy(**self._proxy)
else: # tuple, list, etc.
self._socket.set_proxy(*self._proxy)
def connect(self, ip, port): def connect(self, ip, port):
"""Connects to the specified IP and port number""" """Connects to the specified IP and port number"""