From 3dd2fe1815e6c54be9878a1be56a8c9683ca6072 Mon Sep 17 00:00:00 2001 From: nibrag Date: Fri, 6 May 2016 18:04:38 +0300 Subject: [PATCH] Socks4Server/Socks5Server renamed on Socks4Addr/Socks5Addr --- README.md | 10 +++++----- aiosocks/__init__.py | 16 ++++++++-------- aiosocks/helpers.py | 8 ++++---- aiosocks/protocols.py | 6 +++--- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index df4e3b8..f7a11f4 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,12 @@ python 3.5+ ``` import asyncio from aiosocks import ( - Socks4Server, Socks5Server, Socks4Auth, Socks5Auth, create_connection + Socks4Addr, Socks5Addr, Socks4Auth, Socks5Auth, create_connection ) async def connect(): - socks5_serv = Socks5Server('127.0.0.1', 1080) - socks4_serv = Socks4Server('127.0.0.1', 1080) + socks5_serv = Socks5Addr('127.0.0.1', 1080) + socks4_serv = Socks4Addr('127.0.0.1', 1080) socks5_auth = Socks5Auth('login', 'pwd') socks4_auth = Socks4Auth('ident') @@ -42,11 +42,11 @@ if __name__ == '__main__': ``` import asyncio import aiohttp -from aiosocks import Socks5Server, Socks5Auth +from aiosocks import Socks5Addr, Socks5Auth from aiosocks.connector import SocksConnector async def load_github_main(): - serv = Socks5Server('127.0.0.1', 1080) + serv = Socks5Addr('127.0.0.1', 1080) auth = Socks5Auth('proxyuser1', password='pwd') conn = SocksConnector(proxy=serv, proxy_auth=auth, remote_resolve=False) diff --git a/aiosocks/__init__.py b/aiosocks/__init__.py index 9085401..b708e10 100644 --- a/aiosocks/__init__.py +++ b/aiosocks/__init__.py @@ -6,7 +6,7 @@ from .protocols import Socks4Protocol, Socks5Protocol __version__ = '0.1a' __all__ = ('Socks4Protocol', 'Socks5Protocol', 'Socks4Auth', - 'Socks5Auth', 'Socks4Server', 'Socks5Server', 'SocksError', + 'Socks5Auth', 'Socks4Addr', 'Socks5Addr', 'SocksError', 'NoAcceptableAuthMethods', 'LoginAuthenticationFailed', 'InvalidServerVersion', 'InvalidServerReply', 'create_connection') @@ -15,8 +15,8 @@ async def create_connection(protocol_factory, proxy, proxy_auth, dst, *, remote_ loop=None, ssl=None, family=0, proto=0, flags=0, sock=None, local_addr=None, server_hostname=None): - assert isinstance(proxy, SocksServer), ( - 'proxy must be Socks4Server() or Socks5Server() tuple' + assert isinstance(proxy, SocksAddr), ( + 'proxy must be Socks4Addr() or Socks5Addr() tuple' ) assert proxy_auth is None or isinstance(proxy_auth, (Socks4Auth, Socks5Auth)), ( @@ -26,18 +26,18 @@ async def create_connection(protocol_factory, proxy, proxy_auth, dst, *, remote_ 'invalid dst format, tuple("dst_host", dst_port))' ) - if (isinstance(proxy, Socks4Server) and not + if (isinstance(proxy, Socks4Addr) and not (proxy_auth is None or isinstance(proxy_auth, Socks4Auth))): - raise ValueError("proxy is Socks4Server but proxy_auth is not Socks4Auth") + raise ValueError("proxy is Socks4Addr but proxy_auth is not Socks4Auth") - if (isinstance(proxy, Socks5Server) and not + if (isinstance(proxy, Socks5Addr) and not (proxy_auth is None or isinstance(proxy_auth, Socks5Auth))): - raise ValueError("proxy is Socks5Server but proxy_auth is not Socks5Auth") + raise ValueError("proxy is Socks5Addr but proxy_auth is not Socks5Auth") loop = loop or asyncio.get_event_loop() def socks_factory(): - if isinstance(proxy, Socks4Server): + if isinstance(proxy, Socks4Addr): socks_proto = Socks4Protocol else: socks_proto = Socks5Protocol diff --git a/aiosocks/helpers.py b/aiosocks/helpers.py index 8093b66..abed611 100644 --- a/aiosocks/helpers.py +++ b/aiosocks/helpers.py @@ -1,6 +1,6 @@ from collections import namedtuple -__all__ = ('Socks4Auth', 'Socks5Auth', 'Socks4Server', 'Socks5Server', 'SocksServer') +__all__ = ('Socks4Auth', 'Socks5Auth', 'Socks4Addr', 'Socks5Addr', 'SocksAddr') class Socks4Auth(namedtuple('Socks4Auth', ['login', 'encoding'])): @@ -24,7 +24,7 @@ class Socks5Auth(namedtuple('Socks5Auth', ['login', 'password', 'encoding'])): password.encode(encoding), encoding) -class SocksServer(namedtuple('SocksServer', ['host', 'port'])): +class SocksAddr(namedtuple('SocksServer', ['host', 'port'])): def __new__(cls, host, port): if host is None: raise ValueError('None is not allowed as host value') @@ -35,9 +35,9 @@ class SocksServer(namedtuple('SocksServer', ['host', 'port'])): return super().__new__(cls, host, port) -class Socks4Server(SocksServer): +class Socks4Addr(SocksAddr): pass -class Socks5Server(SocksServer): +class Socks5Addr(SocksAddr): pass diff --git a/aiosocks/protocols.py b/aiosocks/protocols.py index c7036a8..98b5515 100644 --- a/aiosocks/protocols.py +++ b/aiosocks/protocols.py @@ -3,7 +3,7 @@ import socket import struct from . import constants as c from .helpers import ( - Socks4Server, Socks5Server, Socks5Auth, Socks4Auth + Socks4Addr, Socks5Addr, Socks5Auth, Socks4Auth ) from .errors import * @@ -67,7 +67,7 @@ class SocksProtocol(asyncio.StreamReaderProtocol): class Socks4Protocol(SocksProtocol): def __init__(self, proxy, proxy_auth, dst, remote_resolve=True, loop=None): - if not isinstance(proxy, Socks4Server): + if not isinstance(proxy, Socks4Addr): raise ValueError('Invalid proxy format') if proxy_auth is not None and not isinstance(proxy_auth, Socks4Auth): @@ -111,7 +111,7 @@ class Socks4Protocol(SocksProtocol): class Socks5Protocol(SocksProtocol): def __init__(self, proxy, proxy_auth, dst, remote_resolve=True, loop=None): - if not isinstance(proxy, Socks5Server): + if not isinstance(proxy, Socks5Addr): raise ValueError('Invalid proxy format') if proxy_auth is not None and not isinstance(proxy_auth, Socks5Auth):