mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-07-31 10:19:48 +03:00
Change signature of _parse_proxy() to maintain
backwards compatibility with PySocks format.
This commit is contained in:
parent
e4eaecb1cd
commit
795e5c7854
|
@ -136,23 +136,31 @@ consisting of parameters described `in aiosocks usage`__.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
* .. code-block:: python
|
* All of these are equal:
|
||||||
|
|
||||||
proxy = ('socks5', '1.1.1.1', 5555, 'foo', 'bar', True)
|
.. code-block:: python
|
||||||
|
|
||||||
* .. code-block:: python
|
proxy = ('socks5', '1.1.1.1', 5555, True, 'foo', 'bar')
|
||||||
|
proxy = (socks.SOCKS5, '1.1.1.1', 5555, True, 'foo', 'bar')
|
||||||
|
proxy = (2, '1.1.1.1', 5555, True, 'foo', 'bar')
|
||||||
|
|
||||||
proxy = ['socks5', '1.1.1.1', 5555, 'foo', 'bar', True]
|
* All of these are equal:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
proxy = ['socks5', '1.1.1.1', 5555, True, 'foo', 'bar']
|
||||||
|
proxy = [socks.SOCKS5, '1.1.1.1', 5555, True, 'foo', 'bar']
|
||||||
|
proxy = [2, '1.1.1.1', 5555, True, 'foo', 'bar']
|
||||||
|
|
||||||
* .. code-block:: python
|
* .. code-block:: python
|
||||||
|
|
||||||
proxy = {
|
proxy = {
|
||||||
'protocol': 'socks5', # (mandatory) protocol to use, default socks5, allowed values: 'socks5' (or 2), 'socks4' (or 1)
|
'proxy_type': 'socks5', # (mandatory) protocol to use, allowed values: 'socks5' (or 2), 'socks4' (or 1)
|
||||||
'host': '1.1.1.1', # (mandatory) proxy IP address
|
'addr': '1.1.1.1', # (mandatory) proxy IP address
|
||||||
'port': 5555, # (mandatory) proxy port number
|
'port': 5555, # (mandatory) proxy port number
|
||||||
'username': 'foo', # (optional) username if the proxy requires auth
|
'username': 'foo', # (optional) username if the proxy requires auth
|
||||||
'password': 'bar', # (optional) password if the proxy requires auth
|
'password': 'bar', # (optional) password if the proxy requires auth
|
||||||
'remote_resolve': True # (optional) whether to use remote or local resolve, default remote
|
'rdns': True # (optional) whether to use remote or local resolve, default remote
|
||||||
}
|
}
|
||||||
|
|
||||||
.. __: https://github.com/nibrag/aiosocks#installation
|
.. __: https://github.com/nibrag/aiosocks#installation
|
||||||
|
|
|
@ -104,30 +104,30 @@ class Connection(abc.ABC):
|
||||||
await self._writer.drain()
|
await self._writer.drain()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse_proxy(protocol, host, port, username=None, password=None, remote_resolve=True):
|
def _parse_proxy(proxy_type, addr, port, rdns=True, username=None, password=None):
|
||||||
|
|
||||||
proxy, auth = None, None
|
proxy, auth = None, None
|
||||||
|
|
||||||
if isinstance(protocol, str):
|
if isinstance(proxy_type, str):
|
||||||
protocol = protocol.lower()
|
proxy_type = proxy_type.lower()
|
||||||
|
|
||||||
# We do the check for numerical values here
|
# We do the check for numerical values here
|
||||||
# to be backwards compatible with PySocks proxy format,
|
# to be backwards compatible with PySocks proxy format,
|
||||||
# (since socks.SOCKS5 = 2 and socks.SOCKS4 = 1)
|
# (since socks.SOCKS5 = 2 and socks.SOCKS4 = 1)
|
||||||
|
|
||||||
if protocol == 'socks5' or protocol == 2:
|
if proxy_type == 'socks5' or proxy_type == 2:
|
||||||
proxy = aiosocks.Socks5Addr(host, port)
|
proxy = aiosocks.Socks5Addr(addr, port)
|
||||||
if username and password:
|
if username and password:
|
||||||
auth = aiosocks.Socks5Auth(username, password)
|
auth = aiosocks.Socks5Auth(username, password)
|
||||||
|
|
||||||
elif protocol == 'socks4' or protocol == 1:
|
elif proxy_type == 'socks4' or proxy_type == 1:
|
||||||
proxy = aiosocks.Socks4Addr(host, port)
|
proxy = aiosocks.Socks4Addr(addr, port)
|
||||||
if username:
|
if username:
|
||||||
auth = aiosocks.Socks4Auth(username)
|
auth = aiosocks.Socks4Auth(username)
|
||||||
else:
|
else:
|
||||||
raise ValueError('Unsupported proxy protocol {}'.format(protocol))
|
raise ValueError('Unsupported proxy protocol {}'.format(proxy_type))
|
||||||
|
|
||||||
return proxy, auth, remote_resolve
|
return proxy, auth, rdns
|
||||||
|
|
||||||
async def connect(self, timeout=None, ssl=None):
|
async def connect(self, timeout=None, ssl=None):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user