From 08e0a6c4963756bc6a3e0528286cabae018640e1 Mon Sep 17 00:00:00 2001 From: DoomedRaven Date: Sun, 13 Oct 2019 10:32:47 +0200 Subject: [PATCH 01/62] py3first in --- docs/source/conf.py | 1 + setup.py | 10 ++-------- socks5man/config.py | 7 ++++--- socks5man/database.py | 11 ++++++----- socks5man/helpers.py | 8 +++++--- socks5man/logs.py | 1 + socks5man/main.py | 18 +++++++++++------- socks5man/manager.py | 1 + socks5man/misc.py | 1 + socks5man/setupdata/db_migration/env.py | 1 + .../versions/add_socks_dns_port.py | 1 + socks5man/socks5.py | 1 + socks5man/tools.py | 16 ++++++++-------- tests/helpers.py | 1 + tests/test_config.py | 12 +++++++----- tests/test_config_values.py | 9 +++++---- tests/test_database.py | 2 ++ tests/test_helpers.py | 5 +++-- tests/test_logs.py | 1 + tests/test_manager.py | 2 ++ tests/test_misc.py | 1 + tests/test_socks5.py | 1 + tests/test_tools.py | 1 + 23 files changed, 67 insertions(+), 45 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index bb1d6a2..4c9b6ab 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -19,6 +19,7 @@ # -- Project information ----------------------------------------------------- +from __future__ import absolute_import project = u'Socks5man' copyright = u'2016-2018' author = u'Ricardo van Zutphen' diff --git a/setup.py b/setup.py index 951e091..a139d14 100644 --- a/setup.py +++ b/setup.py @@ -1,14 +1,8 @@ +from __future__ import absolute_import import sys from setuptools import setup -if sys.version[0] != "2": - sys.exit( - "Socks5man currently only supports Python 2.7. 3.5+ is on the roadmap" - ", but is not supported yet. For now, please install it in the" - " following way: `pip2 install -U socks5man`." - ) - setup( name="Socks5man", version="0.1.3", @@ -47,7 +41,7 @@ "click==6.6", "alembic>=1.0.7, <1.1", ], - python_requires=">=2.7, <3.0", + python_requires=">=2.7, <3.8", extras_require={ ":sys_platform == 'win32'": [ "win-inet-pton==1.0.1", diff --git a/socks5man/config.py b/socks5man/config.py index 2664afc..5375dda 100644 --- a/socks5man/config.py +++ b/socks5man/config.py @@ -1,4 +1,5 @@ -import ConfigParser +from __future__ import absolute_import +import six.moves.configparser import os from socks5man.exceptions import Socks5ConfigError @@ -43,7 +44,7 @@ def read(self): if Config._cache: Config._cache = {} - config = ConfigParser.ConfigParser() + config = six.moves.configparser.ConfigParser() confpath = cwd("conf", "socks5man.conf") if not os.path.isfile(confpath): @@ -53,7 +54,7 @@ def read(self): ) try: config.read(confpath) - except ConfigParser.Error as e: + except six.moves.configparser.Error as e: raise Socks5ConfigError( "Cannot parse config file. Error: %s" % e ) diff --git a/socks5man/database.py b/socks5man/database.py index d4df08a..852bf55 100644 --- a/socks5man/database.py +++ b/socks5man/database.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import logging import os from datetime import datetime @@ -12,6 +13,8 @@ from socks5man.exceptions import Socks5manError, Socks5manDatabaseError from socks5man.misc import cwd, Singleton +import six +from six.moves import range log = logging.getLogger(__name__) @@ -62,7 +65,7 @@ def to_dict(self): value = getattr(self, column.name) if isinstance(value, datetime): socks_dict[column.name] = value.strftime("%Y-%m-%d %H:%M:%S") - elif isinstance(value, (str, basestring)): + elif isinstance(value, (str, six.string_types)): socks_dict[column.name] = value.encode("utf-8") else: socks_dict[column.name] = value @@ -77,9 +80,7 @@ def __repr__(self): ) -class Database(object): - - __metaclass__ = Singleton +class Database(six.with_metaclass(Singleton, object)): def __init__(self): self.connect(create=True) @@ -381,7 +382,7 @@ def bulk_delete_socks5(self, ids_list): @param ids_list: A list of socks5 ids to delete""" chunk = 100 try: - for c in xrange(0, len(ids_list), chunk): + for c in range(0, len(ids_list), chunk): self.engine.execute( Socks5.__table__.delete().where( Socks5.id.in_(ids_list[c:c+chunk]) diff --git a/socks5man/helpers.py b/socks5man/helpers.py index d7477c4..055d223 100644 --- a/socks5man/helpers.py +++ b/socks5man/helpers.py @@ -1,9 +1,10 @@ +from __future__ import absolute_import import logging import socket import socks import struct import time -import urllib2 +import six.moves.urllib.request, six.moves.urllib.error, six.moves.urllib.parse from socks5man.config import cfg from socks5man.constants import IANA_RESERVERD_IPV4_RANGES @@ -11,6 +12,7 @@ from geoip2 import database as geodatabase from geoip2.errors import GeoIP2Error +from six.moves import range log = logging.getLogger(__name__) @@ -133,8 +135,8 @@ def get_over_socks5(url, host, port, username=None, password=None, timeout=3): response = None try: socket.socket = socks.socksocket - response = urllib2.urlopen(url, timeout=timeout).read() - except (socket.error, urllib2.URLError, socks.ProxyError) as e: + response = six.moves.urllib.request.urlopen(url, timeout=timeout).read() + except (socket.error, six.moves.urllib.error.URLError, socks.ProxyError) as e: log.error("Error making HTTP GET over socks5: %s", e) finally: socket.socket = socket._socketobject diff --git a/socks5man/logs.py b/socks5man/logs.py index 9772201..e8e4d62 100644 --- a/socks5man/logs.py +++ b/socks5man/logs.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import copy import logging import sys diff --git a/socks5man/main.py b/socks5man/main.py index 8549933..00386f6 100644 --- a/socks5man/main.py +++ b/socks5man/main.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import +from __future__ import print_function import click import csv import logging @@ -11,6 +13,8 @@ from socks5man.manager import Manager from socks5man.tools import verify_all, update_geodb from socks5man.misc import cwd +import six +from six.moves import range log = logging.getLogger(__name__) @@ -75,7 +79,7 @@ def add(host, port, username, password, description): try: entry = m.add( host, port, username=username, password=password, - description=unicode(description) + description=six.text_type(description) ) except Socks5manError as e: log.error("Failed to add socks5 server: %s", e) @@ -217,20 +221,20 @@ def list(country, code, city, host, operational, non_operational, count, sys.exit(0) if not export: - print( + print(( "{:<4} {:<12} {:<20} {:<5} {:<16} {:<12} {:<16} {:<16} {:<16}{:<16}".format( "ID", "Operational", "Host", "Port", "Country", "Country Code", "City", "Username", "Password", "Description", ) - ) + )) for socks5 in socks5s: - print( + print(( "{:<4} {:<12} {:<20} {:<5} {:<16} {:<12} {:<16} {:<16} {:<16} {:<16}".format( socks5.id, "Yes" if socks5.operational else "No", socks5.host, socks5.port, socks5.country, socks5.country_code, socks5.city, socks5.username, socks5.password, socks5.description ) - ) + )) sys.exit(0) if os.path.exists(export): @@ -243,10 +247,10 @@ def list(country, code, city, host, operational, non_operational, count, for socks5 in socks5s: socks5_d = socks5.to_dict() if header: - csv_w.writerow(socks5_d.keys()) + csv_w.writerow(list(socks5_d.keys())) header = False - csv_w.writerow(socks5_d.values()) + csv_w.writerow(list(socks5_d.values())) @main.command() diff --git a/socks5man/manager.py b/socks5man/manager.py index 3ba3a90..f945aca 100644 --- a/socks5man/manager.py +++ b/socks5man/manager.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import logging from socks5man.database import Database diff --git a/socks5man/misc.py b/socks5man/misc.py index dd6f91e..6f5795b 100644 --- a/socks5man/misc.py +++ b/socks5man/misc.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import hashlib import os import shutil diff --git a/socks5man/setupdata/db_migration/env.py b/socks5man/setupdata/db_migration/env.py index 0294697..dc6de6f 100644 --- a/socks5man/setupdata/db_migration/env.py +++ b/socks5man/setupdata/db_migration/env.py @@ -1,5 +1,6 @@ from __future__ import with_statement +from __future__ import absolute_import from logging.config import fileConfig from alembic import context diff --git a/socks5man/setupdata/db_migration/versions/add_socks_dns_port.py b/socks5man/setupdata/db_migration/versions/add_socks_dns_port.py index 634218d..546f9e9 100644 --- a/socks5man/setupdata/db_migration/versions/add_socks_dns_port.py +++ b/socks5man/setupdata/db_migration/versions/add_socks_dns_port.py @@ -7,6 +7,7 @@ """ # Revision identifiers, used by Alembic. +from __future__ import absolute_import revision = '2910ee00d182' down_revision = '2b221e84eb82' diff --git a/socks5man/socks5.py b/socks5man/socks5.py index fffdaa6..03ae66d 100644 --- a/socks5man/socks5.py +++ b/socks5man/socks5.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import logging import socket import socks diff --git a/socks5man/tools.py b/socks5man/tools.py index 9d1081d..ce45ef2 100644 --- a/socks5man/tools.py +++ b/socks5man/tools.py @@ -1,9 +1,10 @@ +from __future__ import absolute_import import logging import os import socket import shutil import time -import urllib2 +import six.moves.urllib.request, six.moves.urllib.error, six.moves.urllib.parse from socks5man.config import cfg from socks5man.database import Database @@ -54,7 +55,6 @@ def verify_all(repeated=False, operational=None, unverified=None): continue if cfg("bandwidth", "enabled"): - print "BLABLA 2" if last_bandwidth: waited = time.time() - last_bandwidth if waited < cfg("socks5man", "bandwidth_interval"): @@ -63,9 +63,9 @@ def verify_all(repeated=False, operational=None, unverified=None): if not download_verified: download_url = cfg("bandwidth", "download_url") try: - urllib2.urlopen(download_url, timeout=5) + six.moves.urllib.request.urlopen(download_url, timeout=5) download_verified = True - except (socket.error, urllib2.URLError) as e: + except (socket.error, six.moves.urllib.error.URLError) as e: log.error( "Failed to download speed test file: '%s'. Please" " verify the configured file is still online!" @@ -106,8 +106,8 @@ def update_geodb(): current_version = fp.read() try: - latest_version = urllib2.urlopen(cfg("geodb", "geodb_md5_url")).read() - except urllib2.URLError as e: + latest_version = six.moves.urllib.request.urlopen(cfg("geodb", "geodb_md5_url")).read() + except six.moves.urllib.error.URLError as e: log.error("Error retrieving latest geodb version hash: %s", e) return @@ -124,8 +124,8 @@ def update_geodb(): try: url = cfg("geodb", "geodb_url") log.info("Downloading latest version: '%s'", url) - mmdbtar = urllib2.urlopen(url).read() - except urllib2.URLError as e: + mmdbtar = six.moves.urllib.request.urlopen(url).read() + except six.moves.urllib.error.URLError as e: log.error( "Failed to download new mmdb tar. Is the URL correct? %s", e ) diff --git a/tests/helpers.py b/tests/helpers.py index 059201b..50e771c 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import os import shutil import tempfile diff --git a/tests/test_config.py b/tests/test_config.py index e8ee22e..3739280 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import copy import os import pytest @@ -8,6 +9,7 @@ from socks5man.misc import set_cwd, create_cwd, cwd from tests.helpers import CleanedTempFile +import six class TestConfig(object): @@ -31,18 +33,18 @@ def test_cfg_defaults(self): create_cwd(cwd()) assert isinstance(cfg("socks5man", "verify_interval"), int) assert isinstance(cfg("socks5man", "bandwidth_interval"), int) - assert isinstance(cfg("operationality", "ip_api"), (str, basestring)) + assert isinstance(cfg("operationality", "ip_api"), (str, six.string_types)) assert isinstance(cfg("operationality", "timeout"), int) assert isinstance(cfg("connection_time", "enabled"), bool) assert isinstance(cfg("connection_time", "timeout"), int) - assert isinstance(cfg("connection_time", "hostname"),(str, basestring)) + assert isinstance(cfg("connection_time", "hostname"),(str, six.string_types)) assert isinstance(cfg("connection_time", "port"), int) assert isinstance(cfg("bandwidth", "enabled"), bool) - assert isinstance(cfg("bandwidth", "download_url"), (str, basestring)) + assert isinstance(cfg("bandwidth", "download_url"), (str, six.string_types)) assert isinstance(cfg("bandwidth", "times"), int) assert isinstance(cfg("bandwidth", "timeout"), int) - assert isinstance(cfg("geodb", "geodb_url"), (str, basestring)) - assert isinstance(cfg("geodb", "geodb_md5_url"), (str, basestring)) + assert isinstance(cfg("geodb", "geodb_url"), (str, six.string_types)) + assert isinstance(cfg("geodb", "geodb_md5_url"), (str, six.string_types)) def test_cfg_values(self): create_cwd(cwd()) diff --git a/tests/test_config_values.py b/tests/test_config_values.py index 8062d2e..b92cde1 100644 --- a/tests/test_config_values.py +++ b/tests/test_config_values.py @@ -1,6 +1,7 @@ +from __future__ import absolute_import import re import socket -import urllib2 +import six.moves.urllib.request, six.moves.urllib.error, six.moves.urllib.parse from socks5man.config import cfg from socks5man.misc import set_cwd, create_cwd, cwd @@ -20,7 +21,7 @@ def setup(self): def test_ip_api(self): """Verify that the default ip api returns an actual ip""" create_cwd(cwd()) - res = urllib2.urlopen( + res = six.moves.urllib.request.urlopen( cfg("operationality", "ip_api"), timeout=cfg("operationality", "timeout") ) @@ -42,7 +43,7 @@ def test_download_url(self): """Verify that the url used to measure an approximate bandwidth is still available""" create_cwd(cwd()) - res = urllib2.urlopen( + res = six.moves.urllib.request.urlopen( cfg("bandwidth", "download_url"), timeout=cfg("bandwidth", "timeout") ) @@ -51,6 +52,6 @@ def test_download_url(self): def test_geoipdb_hash_url(self): create_cwd(cwd()) - res = urllib2.urlopen(cfg("geodb", "geodb_md5_url")) + res = six.moves.urllib.request.urlopen(cfg("geodb", "geodb_md5_url")) assert res.getcode() == 200 assert len(res.read()) == 32 diff --git a/tests/test_database.py b/tests/test_database.py index 1d8fc33..500d4b3 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import time import pytest @@ -6,6 +7,7 @@ from socks5man.exceptions import Socks5manDatabaseError from socks5man.misc import set_cwd from tests.helpers import CleanedTempFile +from six.moves import range class TestSocks5(object): diff --git a/tests/test_helpers.py b/tests/test_helpers.py index d6a384c..5b4c07d 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -1,5 +1,6 @@ +from __future__ import absolute_import import mock -import urllib2 +import six.moves.urllib.request, six.moves.urllib.error, six.moves.urllib.parse from socks5man.helpers import ( Dictionary, is_ipv4, is_reserved_ipv4, GeoInfo, get_ipv4_hostname, @@ -161,7 +162,7 @@ def test_get_over_socks5_fail(ms, mu, mss): mss.socket = "DOGE" mss._socketobject = "socket" httpresponse = mock.MagicMock() - httpresponse.read.side_effect = urllib2.URLError("Error") + httpresponse.read.side_effect = six.moves.urllib.error.URLError("Error") mu.return_value = httpresponse ms.socksocket = "socksocket" res = get_over_socks5( diff --git a/tests/test_logs.py b/tests/test_logs.py index 31d7b6c..994b20d 100644 --- a/tests/test_logs.py +++ b/tests/test_logs.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import logging import mock import os diff --git a/tests/test_manager.py b/tests/test_manager.py index 64687f0..7f1529e 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import datetime import pytest @@ -8,6 +9,7 @@ from socks5man.socks5 import Socks5 from tests.helpers import CleanedTempFile +from six.moves import range class TestManager(object): diff --git a/tests/test_misc.py b/tests/test_misc.py index ad14173..40f8cda 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import mock import os import tempfile diff --git a/tests/test_socks5.py b/tests/test_socks5.py index 15f590c..6ae4b9f 100644 --- a/tests/test_socks5.py +++ b/tests/test_socks5.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import datetime import mock import socket diff --git a/tests/test_tools.py b/tests/test_tools.py index 7cbcdad..1f102a5 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import mock import socket From 31e5ab546ff3ac1cc0eba760ca1f5b81ded1bd1d Mon Sep 17 00:00:00 2001 From: DoomedRaven Date: Sun, 13 Oct 2019 10:34:54 +0200 Subject: [PATCH 02/62] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a139d14..8a64109 100644 --- a/setup.py +++ b/setup.py @@ -31,7 +31,7 @@ ], license="GPLv3", description="SOCKS5 server management tool and library", - long_description=open("README.rst", "rb").read(), + long_description=open("README.rst", "r").read(), include_package_data=True, url="https://github.com/RicoVZ/socks5man", install_requires=[ From 60ff544ad5b7dcc8cc2db4c1547e71f3c12d02cb Mon Sep 17 00:00:00 2001 From: DoomedRaven Date: Sun, 13 Oct 2019 10:58:43 +0200 Subject: [PATCH 03/62] Update setup.py --- setup.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 8a64109..0435f4d 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,10 @@ from __future__ import absolute_import -import sys from setuptools import setup setup( name="Socks5man", - version="0.1.3", + version="0.2.1", author="Ricardo van Zutphen", author_email="ricardo@hatching.io", packages=[ From 0b3c54f49dacf10ef087f76d061a3f933e4ba1de Mon Sep 17 00:00:00 2001 From: DoomedRaven Date: Sun, 13 Oct 2019 11:19:13 +0200 Subject: [PATCH 04/62] fix bytes vs string --- socks5man/misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/socks5man/misc.py b/socks5man/misc.py index 6f5795b..4fa24b6 100644 --- a/socks5man/misc.py +++ b/socks5man/misc.py @@ -49,7 +49,7 @@ def unpack_mmdb(tarpath, to): break geodb_hash = md5(tarpath) - with open(cwd("geodb", ".version"), "wb") as fw: + with open(cwd("geodb", ".version"), "w") as fw: fw.write(geodb_hash) def set_cwd(path): From f05cfea945e446c8446754c8433d2835f55446e3 Mon Sep 17 00:00:00 2001 From: DoomedRaven Date: Sun, 13 Oct 2019 12:12:33 +0200 Subject: [PATCH 05/62] more py3 friendly and better error handling try/except in socks5 needed for timeout to not raise error `AttributeError: module 'socket' has no attribute '_socketobject'` --- socks5man/helpers.py | 2 +- socks5man/main.py | 8 +++++--- socks5man/socks5.py | 13 ++++++++----- socks5man/tools.py | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/socks5man/helpers.py b/socks5man/helpers.py index 055d223..ba73997 100644 --- a/socks5man/helpers.py +++ b/socks5man/helpers.py @@ -50,7 +50,7 @@ def is_ipv4(ip): """Try to parse string as Ipv4. Return True if success, False otherwise""" try: - socket.inet_aton(ip) + socket.inet_aton(ip.decode("utf-8")) return True except socket.error: return False diff --git a/socks5man/main.py b/socks5man/main.py index 00386f6..a6140ac 100644 --- a/socks5man/main.py +++ b/socks5man/main.py @@ -230,11 +230,13 @@ def list(country, code, city, host, operational, non_operational, count, for socks5 in socks5s: print(( "{:<4} {:<12} {:<20} {:<5} {:<16} {:<12} {:<16} {:<16} {:<16} {:<16}".format( - socks5.id, "Yes" if socks5.operational else "No", socks5.host, socks5.port, - socks5.country, socks5.country_code, socks5.city, - socks5.username, socks5.password, socks5.description + socks5.id, "Yes" if socks5.operational else "No", socks5.host.decode("utf-8"), socks5.port, + socks5.country.decode("utf-8"), socks5.country_code, socks5.city.decode("utf-8"), + socks5.username if socks5.username else "" , socks5.password if socks5.password else "", + socks5.description.decode("utf-8") if socks5.description else None ) )) + sys.exit(0) if os.path.exists(export): diff --git a/socks5man/socks5.py b/socks5man/socks5.py index 03ae66d..7a296f4 100644 --- a/socks5man/socks5.py +++ b/socks5man/socks5.py @@ -44,11 +44,14 @@ def verify(self): if not is_ipv4(ip): ip = get_ipv4_hostname(ip) - response = get_over_socks5( - cfg("operationality", "ip_api"), self.host, self.port, - username=self.username, password=self.password, - timeout=cfg("operationality", "timeout") - ) + try: + response = get_over_socks5( + cfg("operationality", "ip_api"), self.host, self.port, + username=self.username, password=self.password, + timeout=cfg("operationality", "timeout") + ) + except AttributeError: + return operational if response: if ip == response: diff --git a/socks5man/tools.py b/socks5man/tools.py index ce45ef2..03e7e17 100644 --- a/socks5man/tools.py +++ b/socks5man/tools.py @@ -32,7 +32,7 @@ def verify_all(repeated=False, operational=None, unverified=None): socks5 = Socks5(socks5) log.info( - "Testing socks5 server: '%s:%s'", socks5.host, socks5.port + "Testing socks5 server: '%s:%s'", socks5.host.decode("utf-8"), socks5.port ) if socks5.verify(): log.info("Operationality check: OK") From 8543e18997a92fa170c7081e183550ff64fc5e82 Mon Sep 17 00:00:00 2001 From: DoomedRaven Date: Tue, 15 Oct 2019 23:59:50 +0200 Subject: [PATCH 06/62] remove six, pure py3, tests update few tests still fails, if you can check them also would be great tests/test_config.py .....F..... [ 8%] tests/test_config_values.py .... [ 12%] tests/test_database.py ....F................................ [ 41%] tests/test_helpers.py .........FF....... [ 56%] tests/test_logs.py . [ 56%] tests/test_manager.py ............................ [ 79%] tests/test_misc.py ....... [ 84%] tests/test_socks5.py .........F.... [ 96%] tests/test_tools.py ..... --- socks5man/config.py | 6 +++--- socks5man/database.py | 6 ++---- socks5man/helpers.py | 11 ++++++----- socks5man/main.py | 4 +--- socks5man/socks5.py | 5 ++++- socks5man/tools.py | 16 ++++++++-------- tests/test_config.py | 14 +++++++------- tests/test_config_values.py | 10 +++++----- tests/test_database.py | 1 - tests/test_helpers.py | 4 ++-- tests/test_manager.py | 4 ++-- tests/test_misc.py | 4 ++-- tests/test_socks5.py | 26 +++++++++++++------------- tests/test_tools.py | 2 +- 14 files changed, 56 insertions(+), 57 deletions(-) diff --git a/socks5man/config.py b/socks5man/config.py index 5375dda..c0a2d9c 100644 --- a/socks5man/config.py +++ b/socks5man/config.py @@ -1,6 +1,6 @@ from __future__ import absolute_import -import six.moves.configparser import os +import configparser from socks5man.exceptions import Socks5ConfigError from socks5man.misc import cwd @@ -44,7 +44,7 @@ def read(self): if Config._cache: Config._cache = {} - config = six.moves.configparser.ConfigParser() + config = configparser.ConfigParser() confpath = cwd("conf", "socks5man.conf") if not os.path.isfile(confpath): @@ -54,7 +54,7 @@ def read(self): ) try: config.read(confpath) - except six.moves.configparser.Error as e: + except configparser.Error as e: raise Socks5ConfigError( "Cannot parse config file. Error: %s" % e ) diff --git a/socks5man/database.py b/socks5man/database.py index 852bf55..e001206 100644 --- a/socks5man/database.py +++ b/socks5man/database.py @@ -13,8 +13,6 @@ from socks5man.exceptions import Socks5manError, Socks5manDatabaseError from socks5man.misc import cwd, Singleton -import six -from six.moves import range log = logging.getLogger(__name__) @@ -65,7 +63,7 @@ def to_dict(self): value = getattr(self, column.name) if isinstance(value, datetime): socks_dict[column.name] = value.strftime("%Y-%m-%d %H:%M:%S") - elif isinstance(value, (str, six.string_types)): + elif isinstance(value, str): socks_dict[column.name] = value.encode("utf-8") else: socks_dict[column.name] = value @@ -80,7 +78,7 @@ def __repr__(self): ) -class Database(six.with_metaclass(Singleton, object)): +class Database(object, metaclass=Singleton): def __init__(self): self.connect(create=True) diff --git a/socks5man/helpers.py b/socks5man/helpers.py index ba73997..19358d5 100644 --- a/socks5man/helpers.py +++ b/socks5man/helpers.py @@ -4,7 +4,7 @@ import socks import struct import time -import six.moves.urllib.request, six.moves.urllib.error, six.moves.urllib.parse +import urllib from socks5man.config import cfg from socks5man.constants import IANA_RESERVERD_IPV4_RANGES @@ -12,7 +12,6 @@ from geoip2 import database as geodatabase from geoip2.errors import GeoIP2Error -from six.moves import range log = logging.getLogger(__name__) @@ -50,7 +49,9 @@ def is_ipv4(ip): """Try to parse string as Ipv4. Return True if success, False otherwise""" try: - socket.inet_aton(ip.decode("utf-8")) + if not isinstance(ip, type(str)): + ip = str(ip) + socket.inet_aton(ip) return True except socket.error: return False @@ -135,8 +136,8 @@ def get_over_socks5(url, host, port, username=None, password=None, timeout=3): response = None try: socket.socket = socks.socksocket - response = six.moves.urllib.request.urlopen(url, timeout=timeout).read() - except (socket.error, six.moves.urllib.error.URLError, socks.ProxyError) as e: + response = urllib.request.urlopen(url, timeout=timeout).read() + except (socket.error, urllib.error.URLError, socks.ProxyError) as e: log.error("Error making HTTP GET over socks5: %s", e) finally: socket.socket = socket._socketobject diff --git a/socks5man/main.py b/socks5man/main.py index a6140ac..82d8b78 100644 --- a/socks5man/main.py +++ b/socks5man/main.py @@ -13,8 +13,6 @@ from socks5man.manager import Manager from socks5man.tools import verify_all, update_geodb from socks5man.misc import cwd -import six -from six.moves import range log = logging.getLogger(__name__) @@ -79,7 +77,7 @@ def add(host, port, username, password, description): try: entry = m.add( host, port, username=username, password=password, - description=six.text_type(description) + description=description ) except Socks5manError as e: log.error("Failed to add socks5 server: %s", e) diff --git a/socks5man/socks5.py b/socks5man/socks5.py index 7a296f4..5abda6e 100644 --- a/socks5man/socks5.py +++ b/socks5man/socks5.py @@ -106,7 +106,10 @@ def measure_connection_time(self): cfg("connection_time", "port") )) s.close() - except (socks.ProxyError, socket.error) as e: + except socks.ProxyError as e: + log.error("Error connecting in connection time test: %s", e) + connect_time = None + except socket.error as e: log.error("Error connecting in connection time test: %s", e) connect_time = None else: diff --git a/socks5man/tools.py b/socks5man/tools.py index 03e7e17..a2eee33 100644 --- a/socks5man/tools.py +++ b/socks5man/tools.py @@ -4,7 +4,7 @@ import socket import shutil import time -import six.moves.urllib.request, six.moves.urllib.error, six.moves.urllib.parse +import urllib from socks5man.config import cfg from socks5man.database import Database @@ -32,7 +32,7 @@ def verify_all(repeated=False, operational=None, unverified=None): socks5 = Socks5(socks5) log.info( - "Testing socks5 server: '%s:%s'", socks5.host.decode("utf-8"), socks5.port + "Testing socks5 server: '%s:%s'", socks5.host, socks5.port ) if socks5.verify(): log.info("Operationality check: OK") @@ -63,9 +63,9 @@ def verify_all(repeated=False, operational=None, unverified=None): if not download_verified: download_url = cfg("bandwidth", "download_url") try: - six.moves.urllib.request.urlopen(download_url, timeout=5) + urllib.request.urlopen(download_url, timeout=5) download_verified = True - except (socket.error, six.moves.urllib.error.URLError) as e: + except (socket.error, urllib.error.URLError) as e: log.error( "Failed to download speed test file: '%s'. Please" " verify the configured file is still online!" @@ -106,8 +106,8 @@ def update_geodb(): current_version = fp.read() try: - latest_version = six.moves.urllib.request.urlopen(cfg("geodb", "geodb_md5_url")).read() - except six.moves.urllib.error.URLError as e: + latest_version = urllib.request.urlopen(cfg("geodb", "geodb_md5_url")).read() + except urllib.error.URLError as e: log.error("Error retrieving latest geodb version hash: %s", e) return @@ -124,8 +124,8 @@ def update_geodb(): try: url = cfg("geodb", "geodb_url") log.info("Downloading latest version: '%s'", url) - mmdbtar = six.moves.urllib.request.urlopen(url).read() - except six.moves.urllib.error.URLError as e: + mmdbtar = urllib.request.urlopen(url).read() + except urllib.error.URLError as e: log.error( "Failed to download new mmdb tar. Is the URL correct? %s", e ) diff --git a/tests/test_config.py b/tests/test_config.py index 3739280..fbd13a3 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,6 +1,6 @@ from __future__ import absolute_import -import copy import os +import copy import pytest from socks5man.config import Config, cfg, confbool @@ -9,7 +9,7 @@ from socks5man.misc import set_cwd, create_cwd, cwd from tests.helpers import CleanedTempFile -import six + class TestConfig(object): @@ -33,18 +33,18 @@ def test_cfg_defaults(self): create_cwd(cwd()) assert isinstance(cfg("socks5man", "verify_interval"), int) assert isinstance(cfg("socks5man", "bandwidth_interval"), int) - assert isinstance(cfg("operationality", "ip_api"), (str, six.string_types)) + assert isinstance(cfg("operationality", "ip_api"), (str)) assert isinstance(cfg("operationality", "timeout"), int) assert isinstance(cfg("connection_time", "enabled"), bool) assert isinstance(cfg("connection_time", "timeout"), int) - assert isinstance(cfg("connection_time", "hostname"),(str, six.string_types)) + assert isinstance(cfg("connection_time", "hostname"), (str)) assert isinstance(cfg("connection_time", "port"), int) assert isinstance(cfg("bandwidth", "enabled"), bool) - assert isinstance(cfg("bandwidth", "download_url"), (str, six.string_types)) + assert isinstance(cfg("bandwidth", "download_url"), (str)) assert isinstance(cfg("bandwidth", "times"), int) assert isinstance(cfg("bandwidth", "timeout"), int) - assert isinstance(cfg("geodb", "geodb_url"), (str, six.string_types)) - assert isinstance(cfg("geodb", "geodb_md5_url"), (str, six.string_types)) + assert isinstance(cfg("geodb", "geodb_url"), (str)) + assert isinstance(cfg("geodb", "geodb_md5_url"), (str)) def test_cfg_values(self): create_cwd(cwd()) diff --git a/tests/test_config_values.py b/tests/test_config_values.py index b92cde1..c5a21a9 100644 --- a/tests/test_config_values.py +++ b/tests/test_config_values.py @@ -1,7 +1,7 @@ from __future__ import absolute_import import re import socket -import six.moves.urllib.request, six.moves.urllib.error, six.moves.urllib.parse +import urllib.request from socks5man.config import cfg from socks5man.misc import set_cwd, create_cwd, cwd @@ -21,12 +21,12 @@ def setup(self): def test_ip_api(self): """Verify that the default ip api returns an actual ip""" create_cwd(cwd()) - res = six.moves.urllib.request.urlopen( + res = urllib.request.urlopen( cfg("operationality", "ip_api"), timeout=cfg("operationality", "timeout") ) assert res.getcode() == 200 - assert re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$", res.read()) + assert re.match(rb"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$", res.read()) def test_measure_time_host(self): """Verify that the default connection measurement still accepts @@ -43,7 +43,7 @@ def test_download_url(self): """Verify that the url used to measure an approximate bandwidth is still available""" create_cwd(cwd()) - res = six.moves.urllib.request.urlopen( + res = urllib.request.urlopen( cfg("bandwidth", "download_url"), timeout=cfg("bandwidth", "timeout") ) @@ -52,6 +52,6 @@ def test_download_url(self): def test_geoipdb_hash_url(self): create_cwd(cwd()) - res = six.moves.urllib.request.urlopen(cfg("geodb", "geodb_md5_url")) + res = urllib.request.urlopen(cfg("geodb", "geodb_md5_url")) assert res.getcode() == 200 assert len(res.read()) == 32 diff --git a/tests/test_database.py b/tests/test_database.py index 009de24..9b0729b 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -7,7 +7,6 @@ from socks5man.exceptions import Socks5manDatabaseError from socks5man.misc import set_cwd from tests.helpers import CleanedTempFile -from six.moves import range class TestSocks5(object): diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 5b4c07d..b065585 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -1,6 +1,6 @@ from __future__ import absolute_import import mock -import six.moves.urllib.request, six.moves.urllib.error, six.moves.urllib.parse +import urllib.request, urllib.error, urllib.parse from socks5man.helpers import ( Dictionary, is_ipv4, is_reserved_ipv4, GeoInfo, get_ipv4_hostname, @@ -162,7 +162,7 @@ def test_get_over_socks5_fail(ms, mu, mss): mss.socket = "DOGE" mss._socketobject = "socket" httpresponse = mock.MagicMock() - httpresponse.read.side_effect = six.moves.urllib.error.URLError("Error") + httpresponse.read.side_effect = urllib.error.URLError("Error") mu.return_value = httpresponse ms.socksocket = "socksocket" res = get_over_socks5( diff --git a/tests/test_manager.py b/tests/test_manager.py index 638c6b4..a342e4f 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -56,7 +56,7 @@ def test_acquire_country(self): m = Manager() socks5_1 = m.acquire(country="germany") assert socks5_1.id == 3 - assert socks5_1.country == "Germany" + assert socks5_1.country == b"Germany" socks5_2 = m.acquire(country="france") assert socks5_2 is None @@ -95,7 +95,7 @@ def test_acquire_city(self): m = Manager() socks5_1 = m.acquire(city="tallinn") assert socks5_1.id == 3 - assert socks5_1.city == "Tallinn" + assert socks5_1.city == b"Tallinn" socks5_2 = m.acquire(city="Nowhere") assert socks5_2 is None diff --git a/tests/test_misc.py b/tests/test_misc.py index 40f8cda..08e958a 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -72,7 +72,7 @@ def teardown_class(self): def test_md5(self): fd, path = self.tempfile.mkstemp() - os.write(fd, "tosti") + os.write(fd, b"tosti") os.close(fd) assert md5(path) == "9e796589d183889f5c65af8b736490bb" @@ -87,7 +87,7 @@ def test_unpack_mmdb(self): assert os.path.isfile(mmdb_p) version_file = os.path.join(tmpdir, "geodb", ".version") assert os.path.isfile(version_file) - assert md5(tar_p) == open(version_file, "rb").read() + assert md5(tar_p) == open(version_file, "r").read() r = geodatabase.Reader(mmdb_p) geodata = r.city("8.8.8.8") assert geodata.country.name.lower() == "united states" diff --git a/tests/test_socks5.py b/tests/test_socks5.py index 6ae4b9f..9de6883 100644 --- a/tests/test_socks5.py +++ b/tests/test_socks5.py @@ -34,7 +34,7 @@ def test_attrs(self): s = Socks5(db_socks5) assert s.id == 1 - assert s.host == "8.8.8.8" + assert s.host == b"8.8.8.8" assert s.port == 1337 assert s.country == "germany" assert s.city == "Frankfurt" @@ -83,7 +83,7 @@ def test_verify(self, mg): s = Socks5(db_socks5) assert s.verify() mg.assert_called_once_with( - "http://api.ipify.org", "8.8.8.8", 1337, username="doge", + "http://api.ipify.org", b"8.8.8.8", 1337, username=b"doge", password="wow", timeout=3 ) db_socks5_2 = self.db.view_socks5(1) @@ -148,7 +148,7 @@ def test_approx_bandwidth(self, ma): res = s.approx_bandwidth() assert res == 15.10 ma.assert_called_once_with( - "example.com", 1337, username="doge", password="wow", + b"example.com", 1337, username=b"doge", password="wow", times=2, timeout=10 ) db_socks5_2 = self.db.view_socks5(1) @@ -186,7 +186,7 @@ def test_measure_conn_time(self, ms): assert isinstance(res, float) socksocket.set_proxy.assert_called_once_with( - ms.SOCKS5, "example.com", 1337, username="doge", password="wow" + ms.SOCKS5, b"example.com", 1337, username=b"doge", password="wow" ) socksocket.settimeout.assert_called_once_with(3) socksocket.connect.assert_called_once_with( @@ -219,15 +219,15 @@ def test_socks5_to_dict(self): s = self.db.view_socks5(1) socks5 = Socks5(s) d = socks5.to_dict() - assert d["host"] == "example.com" + assert d["host"] == b"example.com" assert d["port"] == 1337 - assert d["country"] == "germany" - assert d["country_code"] == "DE" - assert d["city"] == "Frankfurt" + assert d["country"] == b"germany" + assert d["country_code"] == b"DE" + assert d["city"] == b"Frankfurt" assert not d["operational"] - assert d["username"] == "doge" - assert d["password"] == "wow" - assert d["description"] == "Such wow, many socks5" + assert d["username"] == b"doge" + assert d["password"] == b"wow" + assert d["description"] == b"Such wow, many socks5" assert d["added_on"] == socks5.added_on.strftime("%Y-%m-%d %H:%M:%S") def test_repr(self): @@ -238,7 +238,7 @@ def test_repr(self): ) s = self.db.view_socks5(1) socks5 = Socks5(s) - assert repr(socks5) == "" + assert repr(socks5) == "" def test_repr_nonauth(self): self.db.add_socks5( @@ -248,7 +248,7 @@ def test_repr_nonauth(self): ) s = self.db.view_socks5(1) socks5 = Socks5(s) - assert repr(socks5) == "" + assert repr(socks5) == "" def test_win_imported_win_inet_pton(self): if sys.platform == "win32": diff --git a/tests/test_tools.py b/tests/test_tools.py index 1f102a5..d1bbe44 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -83,7 +83,7 @@ def test_conntime_fail(self, ms): socks5.approx_bandwidth.assert_not_called() Config._cache["bandwidth"]["enabled"] = False - @mock.patch("socks5man.tools.urllib2.urlopen") + @mock.patch("socks5man.tools.urllib.request.urlopen") @mock.patch("socks5man.tools.Socks5") def test_download_verify_fail(self, ms, mu): create_cwd(cwd()) From 7ec61a0342415b2e29fd73909b617adf780ebed8 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Thu, 17 Oct 2019 10:16:38 +0200 Subject: [PATCH 07/62] Update .travis.yml --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8c3abff..45ed4b3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ language: python matrix: fast_finish: true include: - - python: 2.7 + - python: 3.6 - os: osx osx_image: xcode9.3beta language: generic @@ -13,14 +13,14 @@ before_install: if [[ $TRAVIS_OS_NAME == "osx" ]]; then brew update || brew update wget https://bootstrap.pypa.io/get-pip.py - sudo python get-pip.py - sudo pip install virtualenv + sudo python3 get-pip.py + sudo pip3 install virtualenv virtualenv $HOME source $HOME/bin/activate fi install: - - python setup.py install - - pip install pytest>=3.6 mock "pytest-cov<2.6.0" codecov + - python3 setup.py install + - pip3 install pytest>=3.6 mock "pytest-cov<2.6.0" codecov script: - py.test --cov=socks5man after_success: From 51a3e5a64cdc60fe50935134166085740649e6cb Mon Sep 17 00:00:00 2001 From: DoomedRaven Date: Thu, 17 Oct 2019 10:26:11 +0200 Subject: [PATCH 08/62] Update test_socks5.py --- tests/test_socks5.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_socks5.py b/tests/test_socks5.py index 9de6883..8280fe7 100644 --- a/tests/test_socks5.py +++ b/tests/test_socks5.py @@ -36,7 +36,7 @@ def test_attrs(self): assert s.id == 1 assert s.host == b"8.8.8.8" assert s.port == 1337 - assert s.country == "germany" + assert s.country == b"germany" assert s.city == "Frankfurt" assert s.country_code == "DE" assert s.username == "doge" From 4cfa302df5f6e5aa33eeb51b1abb2492565127b7 Mon Sep 17 00:00:00 2001 From: DoomedRaven Date: Thu, 17 Oct 2019 10:37:58 +0200 Subject: [PATCH 09/62] coerceutf8 --- socks5man/database.py | 27 ++++++++++++++++++++------- tests/test_helpers.py | 2 +- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/socks5man/database.py b/socks5man/database.py index e001206..35e52d7 100644 --- a/socks5man/database.py +++ b/socks5man/database.py @@ -10,6 +10,7 @@ from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker +from sqlalchemy.types import TypeDecorator, Unicode from socks5man.exceptions import Socks5manError, Socks5manDatabaseError from socks5man.misc import cwd, Singleton @@ -21,6 +22,18 @@ SCHEMA_VERSION = "2910ee00d182" +class CoerceUTF8(TypeDecorator): + """Safely coerce Python bytestrings to Unicode + before passing off to the database.""" + + impl = Unicode + + def process_bind_param(self, value, dialect): + if isinstance(value, str): + value = value.decode('utf-8') + return value + + class AlembicVersion(Base): __tablename__ = "alembic_version" @@ -31,20 +44,20 @@ class Socks5(Base): __tablename__ = "socks5s" id = Column(Integer(), primary_key=True) - host = Column(String(255), nullable=False) + host = Column(CoerceUTF8, nullable=False) port = Column(Integer(), nullable=False) - country = Column(String(255), nullable=False) - country_code = Column(String(2), nullable=False) - city = Column(String(255), nullable=True) - username = Column(String(255), nullable=True) - password = Column(String(255), nullable=True) + country = Column(CoerceUTF8, nullable=False) + country_code = Column(CoerceUTF8, nullable=False) + city = Column(CoerceUTF8, nullable=True) + username = Column(CoerceUTF8, nullable=True) + password = Column(CoerceUTF8, nullable=True) added_on = Column(DateTime(), default=datetime.now, nullable=False) last_use = Column(DateTime(), nullable=True) last_check = Column(DateTime(), nullable=True) operational = Column(Boolean, nullable=False, default=False) bandwidth = Column(Float(), nullable=True) connect_time = Column(Float(), nullable=True) - description = Column(Text(), nullable=True) + description = Column(CoerceUTF8, nullable=True) dnsport = Column(Integer(), nullable=True) def __init__(self, host, port, country, country_code): diff --git a/tests/test_helpers.py b/tests/test_helpers.py index b065585..21c6749 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -156,7 +156,7 @@ def test_get_over_socks5(ms, mu, mss): assert mss.socket == "socket" @mock.patch("socks5man.helpers.socket") -@mock.patch("urllib2.urlopen") +@mock.patch("urllib.request.urlopen") @mock.patch("socks5man.helpers.socks") def test_get_over_socks5_fail(ms, mu, mss): mss.socket = "DOGE" From 5e8981e0ab2ecc7948b4ed78146a475ed2b2c87d Mon Sep 17 00:00:00 2001 From: DoomedRaven Date: Thu, 17 Oct 2019 10:45:15 +0200 Subject: [PATCH 10/62] no coerce utf-8 --- socks5man/database.py | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/socks5man/database.py b/socks5man/database.py index 35e52d7..e001206 100644 --- a/socks5man/database.py +++ b/socks5man/database.py @@ -10,7 +10,6 @@ from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker -from sqlalchemy.types import TypeDecorator, Unicode from socks5man.exceptions import Socks5manError, Socks5manDatabaseError from socks5man.misc import cwd, Singleton @@ -22,18 +21,6 @@ SCHEMA_VERSION = "2910ee00d182" -class CoerceUTF8(TypeDecorator): - """Safely coerce Python bytestrings to Unicode - before passing off to the database.""" - - impl = Unicode - - def process_bind_param(self, value, dialect): - if isinstance(value, str): - value = value.decode('utf-8') - return value - - class AlembicVersion(Base): __tablename__ = "alembic_version" @@ -44,20 +31,20 @@ class Socks5(Base): __tablename__ = "socks5s" id = Column(Integer(), primary_key=True) - host = Column(CoerceUTF8, nullable=False) + host = Column(String(255), nullable=False) port = Column(Integer(), nullable=False) - country = Column(CoerceUTF8, nullable=False) - country_code = Column(CoerceUTF8, nullable=False) - city = Column(CoerceUTF8, nullable=True) - username = Column(CoerceUTF8, nullable=True) - password = Column(CoerceUTF8, nullable=True) + country = Column(String(255), nullable=False) + country_code = Column(String(2), nullable=False) + city = Column(String(255), nullable=True) + username = Column(String(255), nullable=True) + password = Column(String(255), nullable=True) added_on = Column(DateTime(), default=datetime.now, nullable=False) last_use = Column(DateTime(), nullable=True) last_check = Column(DateTime(), nullable=True) operational = Column(Boolean, nullable=False, default=False) bandwidth = Column(Float(), nullable=True) connect_time = Column(Float(), nullable=True) - description = Column(CoerceUTF8, nullable=True) + description = Column(Text(), nullable=True) dnsport = Column(Integer(), nullable=True) def __init__(self, host, port, country, country_code): From c07d5bd092cf929700ac760c0651b77b3b3f158a Mon Sep 17 00:00:00 2001 From: DoomedRaven Date: Thu, 17 Oct 2019 10:49:40 +0200 Subject: [PATCH 11/62] fixes --- tests/test_socks5.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_socks5.py b/tests/test_socks5.py index 8280fe7..6188ab1 100644 --- a/tests/test_socks5.py +++ b/tests/test_socks5.py @@ -37,11 +37,11 @@ def test_attrs(self): assert s.host == b"8.8.8.8" assert s.port == 1337 assert s.country == b"germany" - assert s.city == "Frankfurt" + assert s.city == b"Frankfurt" assert s.country_code == "DE" - assert s.username == "doge" + assert s.username == b"doge" assert s.password == "wow" - assert s.description == "Such wow, many socks5" + assert s.description == b"Such wow, many socks5" assert s.operational assert s.bandwidth == 10.55 assert s.connect_time == 0.07 From e8dfdbf5a9de89ae4f498127d832fc38cf357519 Mon Sep 17 00:00:00 2001 From: DoomedRaven Date: Thu, 17 Oct 2019 21:11:59 +0200 Subject: [PATCH 12/62] fix them all yey --- socks5man/helpers.py | 2 +- socks5man/socks5.py | 6 ++---- tests/test_config.py | 4 ++-- tests/test_helpers.py | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/socks5man/helpers.py b/socks5man/helpers.py index 19358d5..86dddcb 100644 --- a/socks5man/helpers.py +++ b/socks5man/helpers.py @@ -137,7 +137,7 @@ def get_over_socks5(url, host, port, username=None, password=None, timeout=3): try: socket.socket = socks.socksocket response = urllib.request.urlopen(url, timeout=timeout).read() - except (socket.error, urllib.error.URLError, socks.ProxyError) as e: + except urllib.error.URLError as e: log.error("Error making HTTP GET over socks5: %s", e) finally: socket.socket = socket._socketobject diff --git a/socks5man/socks5.py b/socks5man/socks5.py index 5abda6e..6e7e513 100644 --- a/socks5man/socks5.py +++ b/socks5man/socks5.py @@ -106,10 +106,8 @@ def measure_connection_time(self): cfg("connection_time", "port") )) s.close() - except socks.ProxyError as e: - log.error("Error connecting in connection time test: %s", e) - connect_time = None - except socket.error as e: + # socket.error, socks.ProxyError + except Exception as e: log.error("Error connecting in connection time test: %s", e) connect_time = None else: diff --git a/tests/test_config.py b/tests/test_config.py index fbd13a3..81d8b7b 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -78,8 +78,8 @@ def test_missing_conf(self): def test_invalid_conf(self): create_cwd(cwd()) Config._cache = {} - with open(cwd("conf", "socks5man.conf"), "wb") as fw: - fw.write(os.urandom(512)) + with open(cwd("conf", "socks5man.conf"), "w") as fw: + fw.write("socks5man to dominate them all") with pytest.raises(Socks5ConfigError): cfg("socks5man", "verify_interval") diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 21c6749..a6cc60b 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -135,7 +135,7 @@ def test_validify_host_port(): assert res11 is None @mock.patch("socks5man.helpers.socket") -@mock.patch("urllib2.urlopen") +@mock.patch("urllib.request.urlopen") @mock.patch("socks5man.helpers.socks") def test_get_over_socks5(ms, mu, mss): mss.socket = "DOGE" From 96889f1737bb424a1c4de563f31ce9ba7147b5ce Mon Sep 17 00:00:00 2001 From: DoomedRaven Date: Thu, 17 Oct 2019 21:22:06 +0200 Subject: [PATCH 13/62] update version and base python3.6 as lower --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index e7c6451..bf82cf9 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ setup( name="Socks5man", - version="0.2.1", + version="0.3.0", author="Ricardo van Zutphen", author_email="ricardo@hatching.io", packages=[ @@ -34,7 +34,7 @@ include_package_data=True, url="https://github.com/RicoVZ/socks5man", install_requires=[r.strip() for r in open("requirements.txt", "r").readlines()], - python_requires=">=2.7, <3.8", + python_requires=">=3.6, <3.8", extras_require={ ":sys_platform == 'win32'": [ "win-inet-pton==1.0.1", From ac2db90f21b9630446aae687876bca07765fe25c Mon Sep 17 00:00:00 2001 From: DoomedRaven Date: Thu, 17 Oct 2019 21:26:38 +0200 Subject: [PATCH 14/62] fix travis and appveyor --- .travis.yml | 8 ++++---- appveyor.yml | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 45ed4b3..2a556b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,14 +13,14 @@ before_install: if [[ $TRAVIS_OS_NAME == "osx" ]]; then brew update || brew update wget https://bootstrap.pypa.io/get-pip.py - sudo python3 get-pip.py - sudo pip3 install virtualenv + sudo python get-pip.py + sudo pip install virtualenv virtualenv $HOME source $HOME/bin/activate fi install: - - python3 setup.py install - - pip3 install pytest>=3.6 mock "pytest-cov<2.6.0" codecov + - python setup.py install + - pip install pytest>=3.6 mock "pytest-cov<2.6.0" codecov script: - py.test --cov=socks5man after_success: diff --git a/appveyor.yml b/appveyor.yml index 210a176..72fa03e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,7 @@ environment: matrix: - - PYTHON: "C:/Python27" + - PYTHON: "C:\Python36" + - PYTHON: "C:\Python37" install: - "python.exe setup.py install" From 060fca485ab23298d1b0e572c458c07ed4323e2b Mon Sep 17 00:00:00 2001 From: doomedraven Date: Thu, 17 Oct 2019 21:27:59 +0200 Subject: [PATCH 15/62] test --- socks5man/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/socks5man/__init__.py b/socks5man/__init__.py index e69de29..56f3b36 100644 --- a/socks5man/__init__.py +++ b/socks5man/__init__.py @@ -0,0 +1 @@ + From 53b4efd85ede8831984c6f7348d62cbaa8b18a62 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Fri, 18 Oct 2019 09:04:12 +0200 Subject: [PATCH 16/62] Update .travis.yml --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 45ed4b3..2a556b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,14 +13,14 @@ before_install: if [[ $TRAVIS_OS_NAME == "osx" ]]; then brew update || brew update wget https://bootstrap.pypa.io/get-pip.py - sudo python3 get-pip.py - sudo pip3 install virtualenv + sudo python get-pip.py + sudo pip install virtualenv virtualenv $HOME source $HOME/bin/activate fi install: - - python3 setup.py install - - pip3 install pytest>=3.6 mock "pytest-cov<2.6.0" codecov + - python setup.py install + - pip install pytest>=3.6 mock "pytest-cov<2.6.0" codecov script: - py.test --cov=socks5man after_success: From 5da3629447acc2a829d386248ba00dec89f608c7 Mon Sep 17 00:00:00 2001 From: DoomedRaven Date: Fri, 18 Oct 2019 15:21:54 +0200 Subject: [PATCH 17/62] few fixes --- socks5man/helpers.py | 7 +++++-- socks5man/socks5.py | 5 ++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/socks5man/helpers.py b/socks5man/helpers.py index 86dddcb..a6fc2af 100644 --- a/socks5man/helpers.py +++ b/socks5man/helpers.py @@ -4,7 +4,8 @@ import socks import struct import time -import urllib +import urllib.request +import urllib.error from socks5man.config import cfg from socks5man.constants import IANA_RESERVERD_IPV4_RANGES @@ -128,19 +129,21 @@ def validify_host_port(host, port): def get_over_socks5(url, host, port, username=None, password=None, timeout=3): """Make a HTTP GET request over socks5 of the given URL""" + socks.set_default_proxy( socks.SOCKS5, host, port, username=username, password=password ) response = None + original_socket = socket.socket try: socket.socket = socks.socksocket response = urllib.request.urlopen(url, timeout=timeout).read() except urllib.error.URLError as e: log.error("Error making HTTP GET over socks5: %s", e) finally: - socket.socket = socket._socketobject + socket.socket = original_socket return response def approximate_bandwidth(host, port, username=None, password=None, diff --git a/socks5man/socks5.py b/socks5man/socks5.py index 6e7e513..86e0aa8 100644 --- a/socks5man/socks5.py +++ b/socks5man/socks5.py @@ -1,6 +1,5 @@ from __future__ import absolute_import import logging -import socket import socks import sys import time @@ -40,13 +39,13 @@ def verify(self): :rtype: bool """ operational = False - ip = self.host + ip = self.host.decode("utf-8") if not is_ipv4(ip): ip = get_ipv4_hostname(ip) try: response = get_over_socks5( - cfg("operationality", "ip_api"), self.host, self.port, + cfg("operationality", "ip_api"), self.host.decode("utf-8"), self.port, username=self.username, password=self.password, timeout=cfg("operationality", "timeout") ) From c2c045312b87aaf4eb7378d29bc4ecc30ff18ba5 Mon Sep 17 00:00:00 2001 From: DoomedRaven Date: Fri, 18 Oct 2019 16:22:00 +0200 Subject: [PATCH 18/62] sync --- requirements.txt | 2 +- socks5man/helpers.py | 5 +++-- socks5man/socks5.py | 2 +- socks5man/tools.py | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/requirements.txt b/requirements.txt index a982365..1bec948 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -PySocks==1.5.7 +PySocks>=1.7 geoip2==2.9.0 SQLAlchemy>=1.3.3, <1.4 click==6.6 diff --git a/socks5man/helpers.py b/socks5man/helpers.py index a6fc2af..97bb65a 100644 --- a/socks5man/helpers.py +++ b/socks5man/helpers.py @@ -130,20 +130,21 @@ def validify_host_port(host, port): def get_over_socks5(url, host, port, username=None, password=None, timeout=3): """Make a HTTP GET request over socks5 of the given URL""" + original_socket = socket.socket socks.set_default_proxy( socks.SOCKS5, host, port, username=username, password=password ) response = None - original_socket = socket.socket + clean_socket = socket.socket try: socket.socket = socks.socksocket response = urllib.request.urlopen(url, timeout=timeout).read() except urllib.error.URLError as e: log.error("Error making HTTP GET over socks5: %s", e) finally: - socket.socket = original_socket + socket.socket = clean_socket return response def approximate_bandwidth(host, port, username=None, password=None, diff --git a/socks5man/socks5.py b/socks5man/socks5.py index 86e0aa8..a4d13d4 100644 --- a/socks5man/socks5.py +++ b/socks5man/socks5.py @@ -53,7 +53,7 @@ def verify(self): return operational if response: - if ip == response: + if ip == response.decode("utf-8"): operational = True # If a private ip is used, the api response will not match with diff --git a/socks5man/tools.py b/socks5man/tools.py index a2eee33..18ecea6 100644 --- a/socks5man/tools.py +++ b/socks5man/tools.py @@ -32,14 +32,14 @@ def verify_all(repeated=False, operational=None, unverified=None): socks5 = Socks5(socks5) log.info( - "Testing socks5 server: '%s:%s'", socks5.host, socks5.port + "Testing socks5 server: '%s:%s'", socks5.host.decode("utf-8"), socks5.port ) if socks5.verify(): log.info("Operationality check: OK") else: log.warning( "Operationality check (%s:%s): FAILED", - socks5.host, socks5.port + socks5.host.decode("utf-8"), socks5.port ) continue From 07049d8b4059e2a0d6869a79cc2eaa9950cc0946 Mon Sep 17 00:00:00 2001 From: DoomedRaven Date: Fri, 18 Oct 2019 16:43:58 +0200 Subject: [PATCH 19/62] test --- socks5man/helpers.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/socks5man/helpers.py b/socks5man/helpers.py index 97bb65a..7fd7cb4 100644 --- a/socks5man/helpers.py +++ b/socks5man/helpers.py @@ -130,11 +130,9 @@ def validify_host_port(host, port): def get_over_socks5(url, host, port, username=None, password=None, timeout=3): """Make a HTTP GET request over socks5 of the given URL""" - original_socket = socket.socket - socks.set_default_proxy( - socks.SOCKS5, host, port, - username=username, password=password - ) + sock = socks.socksocket() + sock.set_proxy(socks.SOCKS5, host, port, username=username, password=password) + #socks.set_default_proxy(socks.SOCKS5, host, port, username=username, password=password) response = None clean_socket = socket.socket From 1927d628898d16e251931c8408834c7576259c0d Mon Sep 17 00:00:00 2001 From: DoomedRaven Date: Sun, 20 Oct 2019 14:30:54 +0200 Subject: [PATCH 20/62] we don't need to encode data to late decode --- socks5man/main.py | 2 +- socks5man/socks5.py | 14 +++++++------- tests/test_manager.py | 4 ++-- tests/test_misc.py | 2 +- tests/test_socks5.py | 34 +++++++++++++++++----------------- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/socks5man/main.py b/socks5man/main.py index 82d8b78..2cc72ad 100644 --- a/socks5man/main.py +++ b/socks5man/main.py @@ -231,7 +231,7 @@ def list(country, code, city, host, operational, non_operational, count, socks5.id, "Yes" if socks5.operational else "No", socks5.host.decode("utf-8"), socks5.port, socks5.country.decode("utf-8"), socks5.country_code, socks5.city.decode("utf-8"), socks5.username if socks5.username else "" , socks5.password if socks5.password else "", - socks5.description.decode("utf-8") if socks5.description else None + socks5.description.decode("utf-8") if socks5.description else "" ) )) diff --git a/socks5man/socks5.py b/socks5man/socks5.py index a4d13d4..637e402 100644 --- a/socks5man/socks5.py +++ b/socks5man/socks5.py @@ -39,13 +39,13 @@ def verify(self): :rtype: bool """ operational = False - ip = self.host.decode("utf-8") + ip = self.host if not is_ipv4(ip): ip = get_ipv4_hostname(ip) try: response = get_over_socks5( - cfg("operationality", "ip_api"), self.host.decode("utf-8"), self.port, + cfg("operationality", "ip_api"), self.host, self.port, username=self.username, password=self.password, timeout=cfg("operationality", "timeout") ) @@ -141,7 +141,7 @@ def host(self): :rtype: str """ if self.db_socks5.host: - return self.db_socks5.host.encode("utf-8") + return self.db_socks5.host return None @property @@ -161,7 +161,7 @@ def country(self): :rtype: str """ if self.db_socks5.country: - return self.db_socks5.country.encode("utf-8") + return self.db_socks5.country return None @property @@ -182,7 +182,7 @@ def city(self): :rtype: str """ if self.db_socks5.city: - return self.db_socks5.city.encode("utf-8") + return self.db_socks5.city return None @property @@ -193,7 +193,7 @@ def username(self): :rtype: str """ if self.db_socks5.username: - return self.db_socks5.username.encode("utf-8") + return self.db_socks5.username return None @property @@ -270,7 +270,7 @@ def description(self): :rtype: str """ if self.db_socks5.description: - return self.db_socks5.description.encode("utf-8") + return self.db_socks5.description return None def __repr__(self): diff --git a/tests/test_manager.py b/tests/test_manager.py index a342e4f..638c6b4 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -56,7 +56,7 @@ def test_acquire_country(self): m = Manager() socks5_1 = m.acquire(country="germany") assert socks5_1.id == 3 - assert socks5_1.country == b"Germany" + assert socks5_1.country == "Germany" socks5_2 = m.acquire(country="france") assert socks5_2 is None @@ -95,7 +95,7 @@ def test_acquire_city(self): m = Manager() socks5_1 = m.acquire(city="tallinn") assert socks5_1.id == 3 - assert socks5_1.city == b"Tallinn" + assert socks5_1.city == "Tallinn" socks5_2 = m.acquire(city="Nowhere") assert socks5_2 is None diff --git a/tests/test_misc.py b/tests/test_misc.py index 08e958a..ceafb68 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -72,7 +72,7 @@ def teardown_class(self): def test_md5(self): fd, path = self.tempfile.mkstemp() - os.write(fd, b"tosti") + os.write(fd, "tosti") os.close(fd) assert md5(path) == "9e796589d183889f5c65af8b736490bb" diff --git a/tests/test_socks5.py b/tests/test_socks5.py index 6188ab1..6513391 100644 --- a/tests/test_socks5.py +++ b/tests/test_socks5.py @@ -34,14 +34,14 @@ def test_attrs(self): s = Socks5(db_socks5) assert s.id == 1 - assert s.host == b"8.8.8.8" + assert s.host == "8.8.8.8" assert s.port == 1337 - assert s.country == b"germany" - assert s.city == b"Frankfurt" + assert s.country == "germany" + assert s.city == "Frankfurt" assert s.country_code == "DE" - assert s.username == b"doge" + assert s.username == "doge" assert s.password == "wow" - assert s.description == b"Such wow, many socks5" + assert s.description == "Such wow, many socks5" assert s.operational assert s.bandwidth == 10.55 assert s.connect_time == 0.07 @@ -83,7 +83,7 @@ def test_verify(self, mg): s = Socks5(db_socks5) assert s.verify() mg.assert_called_once_with( - "http://api.ipify.org", b"8.8.8.8", 1337, username=b"doge", + "http://api.ipify.org", "8.8.8.8", 1337, username="doge", password="wow", timeout=3 ) db_socks5_2 = self.db.view_socks5(1) @@ -148,7 +148,7 @@ def test_approx_bandwidth(self, ma): res = s.approx_bandwidth() assert res == 15.10 ma.assert_called_once_with( - b"example.com", 1337, username=b"doge", password="wow", + "example.com", 1337, username="doge", password="wow", times=2, timeout=10 ) db_socks5_2 = self.db.view_socks5(1) @@ -186,7 +186,7 @@ def test_measure_conn_time(self, ms): assert isinstance(res, float) socksocket.set_proxy.assert_called_once_with( - ms.SOCKS5, b"example.com", 1337, username=b"doge", password="wow" + ms.SOCKS5, "example.com", 1337, username="doge", password="wow" ) socksocket.settimeout.assert_called_once_with(3) socksocket.connect.assert_called_once_with( @@ -219,15 +219,15 @@ def test_socks5_to_dict(self): s = self.db.view_socks5(1) socks5 = Socks5(s) d = socks5.to_dict() - assert d["host"] == b"example.com" + assert d["host"] == "example.com" assert d["port"] == 1337 - assert d["country"] == b"germany" - assert d["country_code"] == b"DE" - assert d["city"] == b"Frankfurt" + assert d["country"] == "germany" + assert d["country_code"] == "DE" + assert d["city"] == "Frankfurt" assert not d["operational"] - assert d["username"] == b"doge" - assert d["password"] == b"wow" - assert d["description"] == b"Such wow, many socks5" + assert d["username"] == "doge" + assert d["password"] == "wow" + assert d["description"] == "Such wow, many socks5" assert d["added_on"] == socks5.added_on.strftime("%Y-%m-%d %H:%M:%S") def test_repr(self): @@ -238,7 +238,7 @@ def test_repr(self): ) s = self.db.view_socks5(1) socks5 = Socks5(s) - assert repr(socks5) == "" + assert repr(socks5) == "" def test_repr_nonauth(self): self.db.add_socks5( @@ -248,7 +248,7 @@ def test_repr_nonauth(self): ) s = self.db.view_socks5(1) socks5 = Socks5(s) - assert repr(socks5) == "" + assert repr(socks5) == "" def test_win_imported_win_inet_pton(self): if sys.platform == "win32": From 9edcc2bfd9cf69b47f329a6e9d0e4f16c696e252 Mon Sep 17 00:00:00 2001 From: DoomedRaven Date: Sun, 20 Oct 2019 14:34:44 +0200 Subject: [PATCH 21/62] Update helpers.py --- socks5man/helpers.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/socks5man/helpers.py b/socks5man/helpers.py index 7fd7cb4..5ae560e 100644 --- a/socks5man/helpers.py +++ b/socks5man/helpers.py @@ -130,9 +130,7 @@ def validify_host_port(host, port): def get_over_socks5(url, host, port, username=None, password=None, timeout=3): """Make a HTTP GET request over socks5 of the given URL""" - sock = socks.socksocket() - sock.set_proxy(socks.SOCKS5, host, port, username=username, password=password) - #socks.set_default_proxy(socks.SOCKS5, host, port, username=username, password=password) + socks.set_default_proxy(socks.SOCKS5, host, port, username=username, password=password) response = None clean_socket = socket.socket From 1d7d6159bd925d23c5d6832fd48ca9206544e6e2 Mon Sep 17 00:00:00 2001 From: DoomedRaven Date: Sun, 20 Oct 2019 14:56:16 +0200 Subject: [PATCH 22/62] fixes --- socks5man/socks5.py | 2 +- socks5man/tools.py | 4 ++-- tests/test_helpers.py | 5 +++-- tests/test_misc.py | 2 +- tests/test_socks5.py | 19 ++++++++++--------- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/socks5man/socks5.py b/socks5man/socks5.py index 637e402..bb2814d 100644 --- a/socks5man/socks5.py +++ b/socks5man/socks5.py @@ -53,7 +53,7 @@ def verify(self): return operational if response: - if ip == response.decode("utf-8"): + if ip == response: operational = True # If a private ip is used, the api response will not match with diff --git a/socks5man/tools.py b/socks5man/tools.py index 18ecea6..a2eee33 100644 --- a/socks5man/tools.py +++ b/socks5man/tools.py @@ -32,14 +32,14 @@ def verify_all(repeated=False, operational=None, unverified=None): socks5 = Socks5(socks5) log.info( - "Testing socks5 server: '%s:%s'", socks5.host.decode("utf-8"), socks5.port + "Testing socks5 server: '%s:%s'", socks5.host, socks5.port ) if socks5.verify(): log.info("Operationality check: OK") else: log.warning( "Operationality check (%s:%s): FAILED", - socks5.host.decode("utf-8"), socks5.port + socks5.host, socks5.port ) continue diff --git a/tests/test_helpers.py b/tests/test_helpers.py index a6cc60b..30ba0a7 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -153,7 +153,7 @@ def test_get_over_socks5(ms, mu, mss): ) mu.assert_called_once_with("http://example.com", timeout=10) assert res == "many content, such wow" - assert mss.socket == "socket" + assert mss.socket == "DOGE" @mock.patch("socks5man.helpers.socket") @mock.patch("urllib.request.urlopen") @@ -170,7 +170,7 @@ def test_get_over_socks5_fail(ms, mu, mss): password="doge", timeout=10 ) assert res is None - assert mss.socket == "socket" + assert mss.socket == "DOGE" @mock.patch("time.time") @mock.patch("socks5man.helpers.cfg") @@ -267,3 +267,4 @@ def test_approximate_bandwidth_failed(mg, mc, mt): times=2, maxfail=1 ) assert speed is None + diff --git a/tests/test_misc.py b/tests/test_misc.py index ceafb68..08e958a 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -72,7 +72,7 @@ def teardown_class(self): def test_md5(self): fd, path = self.tempfile.mkstemp() - os.write(fd, "tosti") + os.write(fd, b"tosti") os.close(fd) assert md5(path) == "9e796589d183889f5c65af8b736490bb" diff --git a/tests/test_socks5.py b/tests/test_socks5.py index 6513391..ead954f 100644 --- a/tests/test_socks5.py +++ b/tests/test_socks5.py @@ -219,15 +219,15 @@ def test_socks5_to_dict(self): s = self.db.view_socks5(1) socks5 = Socks5(s) d = socks5.to_dict() - assert d["host"] == "example.com" + assert d["host"] == b"example.com" assert d["port"] == 1337 - assert d["country"] == "germany" - assert d["country_code"] == "DE" - assert d["city"] == "Frankfurt" + assert d["country"] == b"germany" + assert d["country_code"] == b"DE" + assert d["city"] == b"Frankfurt" assert not d["operational"] - assert d["username"] == "doge" - assert d["password"] == "wow" - assert d["description"] == "Such wow, many socks5" + assert d["username"] == b"doge" + assert d["password"] == b"wow" + assert d["description"] == b"Such wow, many socks5" assert d["added_on"] == socks5.added_on.strftime("%Y-%m-%d %H:%M:%S") def test_repr(self): @@ -238,7 +238,7 @@ def test_repr(self): ) s = self.db.view_socks5(1) socks5 = Socks5(s) - assert repr(socks5) == "" + assert repr(socks5) == "" def test_repr_nonauth(self): self.db.add_socks5( @@ -248,10 +248,11 @@ def test_repr_nonauth(self): ) s = self.db.view_socks5(1) socks5 = Socks5(s) - assert repr(socks5) == "" + assert repr(socks5) == "" def test_win_imported_win_inet_pton(self): if sys.platform == "win32": assert "win_inet_pton" in sys.modules else: assert "win_inet_pton" not in sys.modules + From 5ad5d327f88ed4740887d3a3b3654bc50be4fcb6 Mon Sep 17 00:00:00 2001 From: DoomedRaven Date: Sun, 20 Oct 2019 16:07:15 +0200 Subject: [PATCH 23/62] improve main --- socks5man/main.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/socks5man/main.py b/socks5man/main.py index 2cc72ad..3b23378 100644 --- a/socks5man/main.py +++ b/socks5man/main.py @@ -226,14 +226,14 @@ def list(country, code, city, host, operational, non_operational, count, ) )) for socks5 in socks5s: - print(( + print( "{:<4} {:<12} {:<20} {:<5} {:<16} {:<12} {:<16} {:<16} {:<16} {:<16}".format( - socks5.id, "Yes" if socks5.operational else "No", socks5.host.decode("utf-8"), socks5.port, - socks5.country.decode("utf-8"), socks5.country_code, socks5.city.decode("utf-8"), - socks5.username if socks5.username else "" , socks5.password if socks5.password else "", - socks5.description.decode("utf-8") if socks5.description else "" + socks5.id, "Yes" if socks5.operational else "No", socks5.host, socks5.port, + socks5.country, socks5.country_code, socks5.city, + socks5.username if socks5.username else "", socks5.password if socks5.password else "", + socks5.description if socks5.description else "" ) - )) + ) sys.exit(0) From f4ef76a3a6db509aa8cf14409b33deb02098e886 Mon Sep 17 00:00:00 2001 From: DoomedRaven Date: Sun, 20 Oct 2019 16:48:01 +0200 Subject: [PATCH 24/62] add private option for server if ip isn't in privare ip range --- socks5man/database.py | 8 +++++--- socks5man/main.py | 5 +++-- socks5man/manager.py | 11 +++++++---- socks5man/socks5.py | 14 ++++++++++++-- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/socks5man/database.py b/socks5man/database.py index e001206..75a70b3 100644 --- a/socks5man/database.py +++ b/socks5man/database.py @@ -46,12 +46,14 @@ class Socks5(Base): connect_time = Column(Float(), nullable=True) description = Column(Text(), nullable=True) dnsport = Column(Integer(), nullable=True) + private = Column(Boolean, nullable=True) - def __init__(self, host, port, country, country_code): + def __init__(self, host, port, country, country_code, private): self.host = host self.port = port self.country = country self.country_code = country_code + self.private = private def to_dict(self): """Converts object to dict. @@ -116,9 +118,9 @@ def db_migratable(self): ses.close() def add_socks5(self, host, port, country, country_code, operational=False, - city=None, username=None, password=None, dnsport=None, description=None): + city=None, username=None, password=None, dnsport=None, description=None, private=False): """Add new socks5 server to the database""" - socks5 = Socks5(host, port, country, country_code) + socks5 = Socks5(host, port, country, country_code, private) socks5.operational = operational socks5.city = city socks5.username = username diff --git a/socks5man/main.py b/socks5man/main.py index 3b23378..7a7667b 100644 --- a/socks5man/main.py +++ b/socks5man/main.py @@ -65,7 +65,8 @@ def verify(repeated, operational, non_operational, unverified): @click.option("-u", "--username", help="Username for this socks5 server") @click.option("-p", "--password", help="Password for this socks5 server") @click.option("-d", "--description", help="Description for this socks5 server") -def add(host, port, username, password, description): +@click.option("-pi", "--private", is_flag=True, help="Private server ip") +def add(host, port, username, password, description, private): """Add socks5 server.""" if username and not password or password and not username: log.warning( @@ -77,7 +78,7 @@ def add(host, port, username, password, description): try: entry = m.add( host, port, username=username, password=password, - description=description + description=description, private=private ) except Socks5manError as e: log.error("Failed to add socks5 server: %s", e) diff --git a/socks5man/manager.py b/socks5man/manager.py index cb1f912..d47b52e 100644 --- a/socks5man/manager.py +++ b/socks5man/manager.py @@ -54,7 +54,7 @@ def acquire(self, country=None, country_code=None, city=None, return None def add(self, host, port, username=None, password=None, dnsport=None, - description=None): + description=None, private=False): """Add a socks5 server. :param host: IP or a valid hostname of the socks5 server. @@ -67,6 +67,8 @@ def add(self, host, port, username=None, password=None, dnsport=None, (optional) :param description: Description to store with the socks5 server (optional) + :param private: IP type, private server + (optional) :return: A dictionary containing the provided information, the generated id, the determined country, country code, and city. :rtype: dict @@ -122,13 +124,13 @@ def add(self, host, port, username=None, password=None, dnsport=None, host=host, port=port, username=username, - password=password + password=password, ) entry.update(GeoInfo.ipv4info(valid_entry.ip)) socksid = db.add_socks5( entry.host, entry.port, entry.country, entry.country_code, city=entry.city, username=entry.username, password=entry.password, - dnsport=dnsport, description=description, + dnsport=dnsport, description=description, private=private, ) entry["id"] = socksid @@ -191,7 +193,8 @@ def bulk_add(self, socks5_dict_list, description=None): "password": password, "operational": False, "dnsport": entry.get("dnsport"), - "description": entry.get("description") + "description": entry.get("description"), + "private": entry.get("private"), } new_entry.update(GeoInfo.ipv4info(valid_entry.ip)) new.append(new_entry) diff --git a/socks5man/socks5.py b/socks5man/socks5.py index bb2814d..cee3102 100644 --- a/socks5man/socks5.py +++ b/socks5man/socks5.py @@ -53,13 +53,13 @@ def verify(self): return operational if response: - if ip == response: + if ip == response.decode("utf-8"): operational = True # If a private ip is used, the api response will not match with # the configured host or its ip. There was however a response, # therefore we still mark it as operational - elif is_reserved_ipv4(ip) and is_ipv4(response): + elif self.private or (is_reserved_ipv4(ip) and is_ipv4(response)): operational = True db.set_operational(self.id, operational) @@ -273,6 +273,16 @@ def description(self): return self.db_socks5.description return None + @property + def private(self): + """ + Boolean that tells if the server is private ip. + + :rtype: bool + """ + return self.db_socks5.private + + def __repr__(self): return "" % ( self.host, self.port, self.country, ( From 0edeac7c584ed939e249954b168e96c148c38aab Mon Sep 17 00:00:00 2001 From: DoomedRaven Date: Sun, 20 Oct 2019 17:12:57 +0200 Subject: [PATCH 25/62] fix unit tests --- socks5man/socks5.py | 2 +- tests/test_socks5.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/socks5man/socks5.py b/socks5man/socks5.py index cee3102..bb679a5 100644 --- a/socks5man/socks5.py +++ b/socks5man/socks5.py @@ -59,7 +59,7 @@ def verify(self): # If a private ip is used, the api response will not match with # the configured host or its ip. There was however a response, # therefore we still mark it as operational - elif self.private or (is_reserved_ipv4(ip) and is_ipv4(response)): + elif self.private or (is_reserved_ipv4(ip) and is_ipv4(response.decode("utf-8"))): operational = True db.set_operational(self.id, operational) diff --git a/tests/test_socks5.py b/tests/test_socks5.py index ead954f..7d27320 100644 --- a/tests/test_socks5.py +++ b/tests/test_socks5.py @@ -73,7 +73,7 @@ def test_attrs_invalid(self): @mock.patch("socks5man.socks5.get_over_socks5") def test_verify(self, mg): create_cwd(cwd()) - mg.return_value = "8.8.8.8" + mg.return_value = b"8.8.8.8" self.db.add_socks5( "8.8.8.8", 1337, "germany", "DE", city="Frankfurt", operational=False, username="doge", @@ -107,11 +107,11 @@ def test_verify_fail(self, mg): @mock.patch("socks5man.socks5.get_over_socks5") def test_verify_private(self, mg): create_cwd(cwd()) - mg.return_value = "8.8.8.8" + mg.return_value = b"8.8.8.8" self.db.add_socks5( "192.168.0.50", 1337, "germany", "DE", city="Frankfurt", operational=False, username="doge", - password="wow", description="Such wow, many socks5" + password="wow", description="Such wow, many socks5", ) db_socks5 = self.db.view_socks5(1) s = Socks5(db_socks5) @@ -122,7 +122,7 @@ def test_verify_private(self, mg): @mock.patch("socks5man.socks5.get_over_socks5") def test_verify_hostname(self, mg): create_cwd(cwd()) - mg.return_value = "93.184.216.34" + mg.return_value = b"93.184.216.34" self.db.add_socks5( "example.com", 1337, "germany", "DE", city="Frankfurt", operational=False, username="doge", From 12ed66903928354630c60c584222cf36338c5db6 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Sun, 20 Oct 2019 19:02:50 +0200 Subject: [PATCH 26/62] Update .travis.yml --- .travis.yml | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 194fd40..d454625 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,32 @@ language: python +group: travis_latest + +python: +- 3.7 +- 3.6 matrix: fast_finish: true include: - - python: 3.6 - - python: 3.7 - - os: osx - osx_image: xcode11 - language: shell + - os: linux + name: PEP8 MyPy Coverage + python: 3.7 + install: pip install -e . + after_success: + - coveralls + - os: osx + language: minimal + install: pip3 install -e . + - os: windows + language: minimal + before_install: + - choco install python3 + - export PATH="/c/Python37:/c/Python37/Scripts:$PATH" install: - - python setup.py install + - pip install -e . - pip install pytest>=3.6 mock "pytest-cov<2.6.0" codecov script: - py.test --cov=socks5man after_success: - - codecov \ No newline at end of file + - codecov From 0392f4d275dd6a595a08c309b7118fa61624115b Mon Sep 17 00:00:00 2001 From: doomedraven Date: Sun, 20 Oct 2019 19:03:08 +0200 Subject: [PATCH 27/62] test me hard From 3b42c15e397549d6d315f5a64238aad8b30d374f Mon Sep 17 00:00:00 2001 From: doomedraven Date: Sun, 20 Oct 2019 19:21:14 +0200 Subject: [PATCH 28/62] Update .travis.yml --- .travis.yml | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index d454625..1391bf0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,18 +15,35 @@ matrix: after_success: - coveralls - os: osx - language: minimal - install: pip3 install -e . + osx_image: xcode10 + language: generic + env: PYTHON=36 - os: windows language: minimal before_install: - choco install python3 - export PATH="/c/Python37:/c/Python37/Scripts:$PATH" +before_install: + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then + yes | sudo port install python$PYTHON; + yes | sudo port install py$PYTHON-pip; + sudo port select --set python3 python$PYTHON; + sudo port select --set pip pip$PYTHON; + pip install pyinstaller --user; + export PATH=$PATH:/Users/travis/Library/Python/$PYTHON/bin; + fi + + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then + python3 --version; + pip --version; + pyinstaller --version; + fi + install: - pip install -e . - pip install pytest>=3.6 mock "pytest-cov<2.6.0" codecov script: - - py.test --cov=socks5man + - pytest after_success: - codecov From e9f2af8d9cb176548adf6468e7c2ab5cefc6fc60 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Sun, 20 Oct 2019 19:25:11 +0200 Subject: [PATCH 29/62] Update .travis.yml --- .travis.yml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1391bf0..4092d0d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,22 +24,6 @@ matrix: - choco install python3 - export PATH="/c/Python37:/c/Python37/Scripts:$PATH" -before_install: - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then - yes | sudo port install python$PYTHON; - yes | sudo port install py$PYTHON-pip; - sudo port select --set python3 python$PYTHON; - sudo port select --set pip pip$PYTHON; - pip install pyinstaller --user; - export PATH=$PATH:/Users/travis/Library/Python/$PYTHON/bin; - fi - - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then - python3 --version; - pip --version; - pyinstaller --version; - fi - install: - pip install -e . - pip install pytest>=3.6 mock "pytest-cov<2.6.0" codecov From 9685d0e6017e77438004f749b0c0a1eb45ae8e27 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Sun, 20 Oct 2019 19:28:46 +0200 Subject: [PATCH 30/62] Update .travis.yml --- .travis.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4092d0d..83f46d9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,12 +8,6 @@ python: matrix: fast_finish: true include: - - os: linux - name: PEP8 MyPy Coverage - python: 3.7 - install: pip install -e . - after_success: - - coveralls - os: osx osx_image: xcode10 language: generic From 777ddabf431be771fe4546ca187ee6810a8a61ed Mon Sep 17 00:00:00 2001 From: doomedraven Date: Sun, 20 Oct 2019 19:31:26 +0200 Subject: [PATCH 31/62] Update .travis.yml --- .travis.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 83f46d9..add218b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,12 +6,11 @@ python: - 3.6 matrix: - fast_finish: true include: + - os: linux + python: 3.7 - os: osx - osx_image: xcode10 - language: generic - env: PYTHON=36 + language: minimal - os: windows language: minimal before_install: @@ -22,6 +21,6 @@ install: - pip install -e . - pip install pytest>=3.6 mock "pytest-cov<2.6.0" codecov script: - - pytest + - py.test --cov=socks5man after_success: - codecov From be81c9cc812c060b949960704e2e3f58abfc8043 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Sun, 20 Oct 2019 19:46:34 +0200 Subject: [PATCH 32/62] Update .travis.yml --- .travis.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index add218b..c250c98 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,16 +11,19 @@ matrix: python: 3.7 - os: osx language: minimal + install: pip3 install -e .[tests] - os: windows language: minimal before_install: - choco install python3 - export PATH="/c/Python37:/c/Python37/Scripts:$PATH" -install: - - pip install -e . + install: + pip install -e .[tests] + +script: + pytest -r a -v - pip install pytest>=3.6 mock "pytest-cov<2.6.0" codecov -script: - - py.test --cov=socks5man after_success: - codecov + From 8c7cf2b83c182644642f6ca7438c55c2fcfc68f0 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Sun, 20 Oct 2019 20:00:50 +0200 Subject: [PATCH 33/62] Update .travis.yml --- .travis.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index c250c98..f5316b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,9 +9,17 @@ matrix: include: - os: linux python: 3.7 - - os: osx - language: minimal - install: pip3 install -e .[tests] + - name: "Python 3.6.5 on macOS 10.13" + os: osx + osx_image: xcode9.4 # Python 3.6.5 running on macOS 10.13 + language: shell # 'language: python' is an error on Travis CI macOS + before_install: + - python3 --version + - pip3 install -U pip + - pip3 install -U pytest + - pip3 install codecov + script: python3 -m pytest + after_success: python 3 -m codecov - os: windows language: minimal before_install: From a316a692406453ef50c9360ae113d1a086cc7b8f Mon Sep 17 00:00:00 2001 From: doomedraven Date: Sun, 20 Oct 2019 20:25:54 +0200 Subject: [PATCH 34/62] Update .travis.yml --- .travis.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index f5316b4..844017d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,8 @@ matrix: include: - os: linux python: 3.7 + script: + - pip install -e .[tests] - name: "Python 3.6.5 on macOS 10.13" os: osx osx_image: xcode9.4 # Python 3.6.5 running on macOS 10.13 @@ -18,6 +20,7 @@ matrix: - pip3 install -U pip - pip3 install -U pytest - pip3 install codecov + - pip3 install -e .[tests] script: python3 -m pytest after_success: python 3 -m codecov - os: windows @@ -25,12 +28,12 @@ matrix: before_install: - choco install python3 - export PATH="/c/Python37:/c/Python37/Scripts:$PATH" - - install: - pip install -e .[tests] + - pip3 install -e .[tests] + install: + pip install -e .[tests] script: - pytest -r a -v + - pytest -r a -v - pip install pytest>=3.6 mock "pytest-cov<2.6.0" codecov after_success: - codecov From 1c3af427d634786e6cb4649b4b3fff752256efb2 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Sun, 20 Oct 2019 20:49:47 +0200 Subject: [PATCH 35/62] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 844017d..21ec523 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,7 @@ matrix: - pip3 install -U pip - pip3 install -U pytest - pip3 install codecov + install: - pip3 install -e .[tests] script: python3 -m pytest after_success: python 3 -m codecov @@ -28,7 +29,6 @@ matrix: before_install: - choco install python3 - export PATH="/c/Python37:/c/Python37/Scripts:$PATH" - - pip3 install -e .[tests] install: pip install -e .[tests] From a9fbc6dbae51163a8c538086c1a498a0b128b987 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Sun, 20 Oct 2019 20:53:16 +0200 Subject: [PATCH 36/62] Update .travis.yml --- .travis.yml | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 21ec523..38f3581 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,8 +9,6 @@ matrix: include: - os: linux python: 3.7 - script: - - pip install -e .[tests] - name: "Python 3.6.5 on macOS 10.13" os: osx osx_image: xcode9.4 # Python 3.6.5 running on macOS 10.13 @@ -20,8 +18,6 @@ matrix: - pip3 install -U pip - pip3 install -U pytest - pip3 install codecov - install: - - pip3 install -e .[tests] script: python3 -m pytest after_success: python 3 -m codecov - os: windows @@ -29,12 +25,11 @@ matrix: before_install: - choco install python3 - export PATH="/c/Python37:/c/Python37/Scripts:$PATH" - install: - pip install -e .[tests] -script: - - pytest -r a -v - - pip install pytest>=3.6 mock "pytest-cov<2.6.0" codecov +install: + - pip3 install -e . + - pip3 install pytest>=3.6 mock "pytest-cov<2.6.0" codecov +script: + - py.test --cov=socks5man after_success: - codecov - From c24137b0adc7d3a5dd3c12c047aa0ddd47981af3 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Sun, 20 Oct 2019 20:57:15 +0200 Subject: [PATCH 37/62] Update .travis.yml --- .travis.yml | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/.travis.yml b/.travis.yml index 38f3581..0398410 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,34 +1,21 @@ -language: python -group: travis_latest - -python: -- 3.7 -- 3.6 - matrix: + fast_finish: true include: - - os: linux - python: 3.7 - - name: "Python 3.6.5 on macOS 10.13" + - python: 3.6 + - python: 3.7 + - name: "Python 3.6.5 on macOS 10.13" os: osx - osx_image: xcode9.4 # Python 3.6.5 running on macOS 10.13 - language: shell # 'language: python' is an error on Travis CI macOS + osx_image: xcode11 + language: shell before_install: - python3 --version - pip3 install -U pip - pip3 install -U pytest - pip3 install codecov - script: python3 -m pytest - after_success: python 3 -m codecov - - os: windows - language: minimal - before_install: - - choco install python3 - - export PATH="/c/Python37:/c/Python37/Scripts:$PATH" install: - - pip3 install -e . - - pip3 install pytest>=3.6 mock "pytest-cov<2.6.0" codecov + - python setup.py install + - pip install pytest>=3.6 mock "pytest-cov<2.6.0" codecov script: - py.test --cov=socks5man after_success: From 413a4f744c909418e998576b26c47b71b5b9f543 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Sun, 20 Oct 2019 21:04:02 +0200 Subject: [PATCH 38/62] Update pythonpackage.yml --- .github/workflows/pythonpackage.yml | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/pythonpackage.yml diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml new file mode 100644 index 0000000..74da3d0 --- /dev/null +++ b/.github/workflows/pythonpackage.yml @@ -0,0 +1,34 @@ +name: Python package + +on: [push] + +jobs: + ubuntu: + name: Test on linux + runs-on: ubuntu-latest + strategy: + max-parallel: 4 + matrix: + python-version: [3.6, 3.7] + + steps: + - uses: actions/checkout@v1 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Lint with flake8 + run: | + pip install flake8 + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pip install pytest + pytest From dce11c365c9424c75d58d6abf64e9353803d7fc5 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Sun, 20 Oct 2019 21:07:08 +0200 Subject: [PATCH 39/62] Update pythonpackage.yml --- .github/workflows/pythonpackage.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 74da3d0..e116476 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -20,14 +20,8 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip + pip install pytest>=3.6 mock "pytest-cov<2.6.0" codecov pip install -r requirements.txt - - name: Lint with flake8 - run: | - pip install flake8 - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | pip install pytest From 5af2016074483be4c01a7cd6a5f86324f3f4d217 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Sun, 20 Oct 2019 21:12:10 +0200 Subject: [PATCH 40/62] Update pythonpackage.yml --- .github/workflows/pythonpackage.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index e116476..f729cf3 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -5,10 +5,11 @@ on: [push] jobs: ubuntu: name: Test on linux - runs-on: ubuntu-latest + runs-on: ${{ matrix.operating-system }} strategy: max-parallel: 4 matrix: + operating-system: [ubuntu-latest, windows-latest, macOS-latest] python-version: [3.6, 3.7] steps: From 921e467697a271c695aeb6474a131fa2891b732c Mon Sep 17 00:00:00 2001 From: doomedraven Date: Sun, 20 Oct 2019 21:24:11 +0200 Subject: [PATCH 41/62] Update pythonpackage.yml --- .github/workflows/pythonpackage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index f729cf3..a1c0ffd 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -21,7 +21,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install pytest>=3.6 mock "pytest-cov<2.6.0" codecov + pip install pytest>=3.6 mock "pytest-cov<2.6.0" codecov win_inet_pton pip install -r requirements.txt - name: Test with pytest run: | From a37f34cf2c5014ff88de390cbaf70d86af9b2db4 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Sun, 20 Oct 2019 21:35:58 +0200 Subject: [PATCH 42/62] Update pythonpackage.yml --- .github/workflows/pythonpackage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index a1c0ffd..f5c11b4 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -3,7 +3,7 @@ name: Python package on: [push] jobs: - ubuntu: + tester: name: Test on linux runs-on: ${{ matrix.operating-system }} strategy: From 401b446c866c93c16ff0dbb8d0f4f4aa8bcfb6b1 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Sun, 20 Oct 2019 21:36:09 +0200 Subject: [PATCH 43/62] Update pythonpackage.yml From 9918103bd6dbffb962a2a06bcfc2a4dc56cda0ed Mon Sep 17 00:00:00 2001 From: doomedraven Date: Sun, 20 Oct 2019 21:41:08 +0200 Subject: [PATCH 44/62] Delete pythonpackage.yml --- .github/workflows/pythonpackage.yml | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 .github/workflows/pythonpackage.yml diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml deleted file mode 100644 index f5c11b4..0000000 --- a/.github/workflows/pythonpackage.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Python package - -on: [push] - -jobs: - tester: - name: Test on linux - runs-on: ${{ matrix.operating-system }} - strategy: - max-parallel: 4 - matrix: - operating-system: [ubuntu-latest, windows-latest, macOS-latest] - python-version: [3.6, 3.7] - - steps: - - uses: actions/checkout@v1 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install pytest>=3.6 mock "pytest-cov<2.6.0" codecov win_inet_pton - pip install -r requirements.txt - - name: Test with pytest - run: | - pip install pytest - pytest From 56c1dd6853b3fef87583e7e5b25ab1385a4a62ab Mon Sep 17 00:00:00 2001 From: doomedraven Date: Sun, 20 Oct 2019 21:42:55 +0200 Subject: [PATCH 45/62] Create pythonpackage.yml --- .github/workflows/pythonpackage.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/pythonpackage.yml diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml new file mode 100644 index 0000000..9a9fe24 --- /dev/null +++ b/.github/workflows/pythonpackage.yml @@ -0,0 +1,29 @@ +name: Python package + +on: [push] + +jobs: + tester: + name: Test them all + runs-on: ${{ matrix.operating-system }} + strategy: + max-parallel: 4 + matrix: + operating-system: [ubuntu-latest, windows-latest, macOS-latest] + python-version: [3.6, 3.7] + + steps: + - uses: actions/checkout@v1 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest>=3.6 mock "pytest-cov<2.6.0" codecov win_inet_pton + pip install -r requirements.txt + - name: Test with pytest + run: | + pip install pytest + pytest From 8fd5de8988a579cc427a34118dbeb6a82b11a037 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Sun, 20 Oct 2019 21:43:08 +0200 Subject: [PATCH 46/62] Delete .travis.yml --- .travis.yml | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0398410..0000000 --- a/.travis.yml +++ /dev/null @@ -1,22 +0,0 @@ -matrix: - fast_finish: true - include: - - python: 3.6 - - python: 3.7 - - name: "Python 3.6.5 on macOS 10.13" - os: osx - osx_image: xcode11 - language: shell - before_install: - - python3 --version - - pip3 install -U pip - - pip3 install -U pytest - - pip3 install codecov - -install: - - python setup.py install - - pip install pytest>=3.6 mock "pytest-cov<2.6.0" codecov -script: - - py.test --cov=socks5man -after_success: - - codecov From a430cfb1c9cb052567e4cf8aba0ec732d20e7a24 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Sun, 20 Oct 2019 21:43:16 +0200 Subject: [PATCH 47/62] Delete appveyor.yml --- appveyor.yml | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index d65067f..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,20 +0,0 @@ -environment: - matrix: - - PYTHON: "C:\\Python36" - PYTHON_VERSION: 3.6 - - - PYTHON: "C:\\Python37" - PYTHON_VERSION: 3.7 - -install: - - "python.exe setup.py install" - - "pip.exe install -e ." - - "pip.exe install pytest mock pytest-cov codecov" - -build: off - -test_script: - - "pytest.exe --cov=socks5man" - -after_test: - - "codecov.exe" From 552ee34b52e77cf26dacc23465a358d46e4a2b2b Mon Sep 17 00:00:00 2001 From: doomedraven Date: Sun, 20 Oct 2019 22:32:19 +0200 Subject: [PATCH 48/62] Update pythonpackage.yml --- .github/workflows/pythonpackage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 9a9fe24..50761f1 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -1,4 +1,4 @@ -name: Python package +name: build on: [push] From f2f089e595a014451ad9cdd69ccaaf7678118d69 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Sun, 20 Oct 2019 22:33:06 +0200 Subject: [PATCH 49/62] swap badfges from travis to github actions --- README.md | 16 ++++++++++++++++ README.rst | 26 -------------------------- 2 files changed, 16 insertions(+), 26 deletions(-) create mode 100644 README.md delete mode 100644 README.rst diff --git a/README.md b/README.md new file mode 100644 index 0000000..d022e86 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +Socks5man is a Socks5 management tool and Python library. It +enables you to add socks5 servers, run a service that verifies if +they are operational, and request these servers in a round-robin fashion +by country, city, average connection time, and bandwidth, using the Python library. + +The library also allows for manual operationality, bandwidth, and connection time tests. +A local database is used to lookup country and city information for a host ip. + +The documentation can be found at: [https://socks5man.readthedocs.io](https://socks5man.readthedocs.io). + +This product includes GeoLite2 data created by MaxMind, available from [maxmind.com](maxmind.com). + +![](https://github.com/RicoVZ/socks5man/workflows/build/badge.svg) + +* [maxmind.com](http://www.maxmind.com) +* [https://socks5man.readthedocs.io](https://socks5man.readthedocs.io) diff --git a/README.rst b/README.rst deleted file mode 100644 index 6c5b8e5..0000000 --- a/README.rst +++ /dev/null @@ -1,26 +0,0 @@ -Socks5man is a Socks5 management tool and Python library. It -enables you to add socks5 servers, run a service that verifies if -they are operational, and request these servers in a round-robin fashion -by country, city, average connection time, and bandwidth, using the Python library. - -The library also allows for manual operationality, bandwidth, and connection time tests. -A local database is used to lookup country and city information for a host ip. - -The documentation can be found at: `https://socks5man.readthedocs.io`_. - -This product includes GeoLite2 data created by MaxMind, available from `maxmind.com`_. - -.. image:: https://api.travis-ci.org/RicoVZ/socks5man.svg?branch=master - :alt: Linux and OSX Build Status - :target: https://travis-ci.org/RicoVZ/socks5man - -.. image:: https://ci.appveyor.com/api/projects/status/le7o92n6t1glv4su?svg=true - :alt: Windows Build Status - :target: https://ci.appveyor.com/project/RicoVZ/socks5man - -.. image:: https://codecov.io/gh/ricovz/socks5man/branch/master/graph/badge.svg - :alt: Codecov Coverage Status - :target: https://codecov.io/gh/RicoVZ/socks5man - -.. _`maxmind.com`: http://www.maxmind.com -.. _`https://socks5man.readthedocs.io`: https://socks5man.readthedocs.io/ From ad0f33b18188e5aecb38de42ee8ceaa5a5cd7f5b Mon Sep 17 00:00:00 2001 From: doomedraven Date: Thu, 31 Oct 2019 07:58:38 +0100 Subject: [PATCH 50/62] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index bf82cf9..cda1169 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ ], license="GPLv3", description="SOCKS5 server management tool and library", - long_description=open("README.rst", "r").read(), + long_description=open("README.md", "r").read(), include_package_data=True, url="https://github.com/RicoVZ/socks5man", install_requires=[r.strip() for r in open("requirements.txt", "r").readlines()], From f5398b640ff5264f63aa1f94315afc070bc26b9e Mon Sep 17 00:00:00 2001 From: doomedraven Date: Tue, 2 Jun 2020 10:01:13 +0200 Subject: [PATCH 51/62] Update pythonpackage.yml Ubuntu 20.04 ubuntu-20.04 Ubuntu 18.04 ubuntu-latest or ubuntu-18.04 --- .github/workflows/pythonpackage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 50761f1..46dbdaa 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -9,7 +9,7 @@ jobs: strategy: max-parallel: 4 matrix: - operating-system: [ubuntu-latest, windows-latest, macOS-latest] + operating-system: [ubuntu-20.04, windows-latest, macOS-latest] python-version: [3.6, 3.7] steps: From f79974f67b41912eb61637a475e2b400af3e5698 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Tue, 2 Jun 2020 10:08:25 +0200 Subject: [PATCH 52/62] Update pythonpackage.yml --- .github/workflows/pythonpackage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 46dbdaa..6618cd7 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -10,7 +10,7 @@ jobs: max-parallel: 4 matrix: operating-system: [ubuntu-20.04, windows-latest, macOS-latest] - python-version: [3.6, 3.7] + python-version: [3.8] steps: - uses: actions/checkout@v1 From c53ccaa67816daaa6e40f6b3fd0cadd7a6a94e64 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Tue, 2 Jun 2020 10:10:16 +0200 Subject: [PATCH 53/62] Update pythonpackage.yml --- .github/workflows/pythonpackage.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 6618cd7..6756ec0 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -9,8 +9,8 @@ jobs: strategy: max-parallel: 4 matrix: - operating-system: [ubuntu-20.04, windows-latest, macOS-latest] - python-version: [3.8] + operating-system: [ubuntu-latest, windows-latest, macOS-latest] + python-version: [3.6, 3.8] steps: - uses: actions/checkout@v1 From 3f5193eb3f50469f3d1b095e5794667781981226 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Thu, 4 Jun 2020 13:06:08 +0200 Subject: [PATCH 54/62] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index cda1169..6e9a163 100644 --- a/setup.py +++ b/setup.py @@ -34,7 +34,7 @@ include_package_data=True, url="https://github.com/RicoVZ/socks5man", install_requires=[r.strip() for r in open("requirements.txt", "r").readlines()], - python_requires=">=3.6, <3.8", + python_requires=">=3.6, <3.9", extras_require={ ":sys_platform == 'win32'": [ "win-inet-pton==1.0.1", From d207af2b3cbfb1fdd35bb1e76018224e1dd3ff9d Mon Sep 17 00:00:00 2001 From: doomedraven Date: Mon, 15 Feb 2021 23:37:56 +0100 Subject: [PATCH 55/62] Update requirements.txt --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 1bec948..fd3d54f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ PySocks>=1.7 geoip2==2.9.0 SQLAlchemy>=1.3.3, <1.4 -click==6.6 +click alembic>=1.0.7, <1.1 From dd4c2cd9f2f9290ff0fb97fe44ef3dd6265d34c9 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Mon, 15 Feb 2021 23:38:00 +0100 Subject: [PATCH 56/62] Create requirements.txt From 3880eb0cd5cf2e8f849d2624e8257107814bcb86 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Thu, 3 Jun 2021 08:22:05 +0200 Subject: [PATCH 57/62] Update requirements.txt --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index fd3d54f..005cbc8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ PySocks>=1.7 geoip2==2.9.0 -SQLAlchemy>=1.3.3, <1.4 +SQLAlchemy>=1.3.3, <1.5 click alembic>=1.0.7, <1.1 From 9695020ea8a6484de3a352b2a437596d22f8a6ab Mon Sep 17 00:00:00 2001 From: doomedraven Date: Thu, 24 Jun 2021 11:43:23 +0200 Subject: [PATCH 58/62] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 6e9a163..c5a8227 100644 --- a/setup.py +++ b/setup.py @@ -34,7 +34,7 @@ include_package_data=True, url="https://github.com/RicoVZ/socks5man", install_requires=[r.strip() for r in open("requirements.txt", "r").readlines()], - python_requires=">=3.6, <3.9", + python_requires=">=3.6", extras_require={ ":sys_platform == 'win32'": [ "win-inet-pton==1.0.1", From 7b335d027297b67abdf28f38cc7d5d42c9d810b5 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Thu, 24 Jun 2021 15:30:28 +0200 Subject: [PATCH 59/62] Update pythonpackage.yml --- .github/workflows/pythonpackage.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 6756ec0..32dc125 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -9,8 +9,8 @@ jobs: strategy: max-parallel: 4 matrix: - operating-system: [ubuntu-latest, windows-latest, macOS-latest] - python-version: [3.6, 3.8] + operating-system: [ubuntu-latest] + python-version: [3.8, 3.9] steps: - uses: actions/checkout@v1 From 7d02d404013e29e3439e15638f1ef447a4f4a074 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Fri, 20 Jan 2023 22:03:07 +0100 Subject: [PATCH 60/62] Update pythonpackage.yml --- .github/workflows/pythonpackage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 32dc125..cc7d2b4 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -10,7 +10,7 @@ jobs: max-parallel: 4 matrix: operating-system: [ubuntu-latest] - python-version: [3.8, 3.9] + python-version: [3.8, 3.11] steps: - uses: actions/checkout@v1 From f4b34c4c99544fa6a8643412115581d10c3496b8 Mon Sep 17 00:00:00 2001 From: doomedraven Date: Thu, 9 Mar 2023 21:25:39 +0100 Subject: [PATCH 61/62] Update requirements.txt --- requirements.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 005cbc8..4286556 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ PySocks>=1.7 -geoip2==2.9.0 -SQLAlchemy>=1.3.3, <1.5 +geoip2>=2.9.0 +SQLAlchemy click -alembic>=1.0.7, <1.1 +alembic From 7526c0da3795e5e7e061fd031ce22cfc3d1a2a00 Mon Sep 17 00:00:00 2001 From: Federico Fantini Date: Fri, 10 Mar 2023 10:08:09 +0100 Subject: [PATCH 62/62] fixed #1 --- socks5man/database.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/socks5man/database.py b/socks5man/database.py index 75a70b3..afad8ca 100644 --- a/socks5man/database.py +++ b/socks5man/database.py @@ -5,7 +5,7 @@ from sqlalchemy import ( Column, Integer, String, DateTime, Boolean, Text, create_engine, - Float, and_, func + Float, and_, func, inspect ) from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.ext.declarative import declarative_base @@ -91,9 +91,7 @@ def connect(self, create=False): if create: if not os.path.exists(cwd("socks5man.db")): self._create() - elif not self.engine.dialect.has_table( - self.engine, AlembicVersion.__tablename__ - ): + elif not inspect(self.engine).has_table(AlembicVersion.__tablename__): AlembicVersion.__table__.create(self.engine) def _create(self):