From 8da30de6bea5422a72b8c26f28580f28169966bb Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Tue, 8 Feb 2022 18:27:14 +0800 Subject: [PATCH] refactor: python package of ProxyBuilder --- ProxyBuilder/ShadowsocksR.py | 2 +- ProxyBuilder/__init__.py | 6 +++--- ProxyBuilder/__main__.py | 3 +++ ProxyBuilder/{main.py => builder.py} | 4 ++++ demo.py | 12 +++++++----- 5 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 ProxyBuilder/__main__.py rename ProxyBuilder/{main.py => builder.py} (98%) diff --git a/ProxyBuilder/ShadowsocksR.py b/ProxyBuilder/ShadowsocksR.py index 617790d..c80f991 100644 --- a/ProxyBuilder/ShadowsocksR.py +++ b/ProxyBuilder/ShadowsocksR.py @@ -91,4 +91,4 @@ def load(proxyInfo, socksPort, configFile): # ShadowsocksR配置载入 'protocol_param': proxyInfo['protocolParam'], 'obfs': proxyInfo['obfs'], 'obfs_param': proxyInfo['obfsParam'] - }) \ No newline at end of file + }) diff --git a/ProxyBuilder/__init__.py b/ProxyBuilder/__init__.py index 2693b17..6c4b282 100644 --- a/ProxyBuilder/__init__.py +++ b/ProxyBuilder/__init__.py @@ -1,6 +1,6 @@ #!/usr/bin/python # -*- coding:utf-8 -*- -from ProxyBuilder.main import build -from ProxyBuilder.main import check -from ProxyBuilder.main import destroy +from ProxyBuilder.builder import * + +__all__ = [ 'build', 'check', 'destroy' ] diff --git a/ProxyBuilder/__main__.py b/ProxyBuilder/__main__.py new file mode 100644 index 0000000..b49f65e --- /dev/null +++ b/ProxyBuilder/__main__.py @@ -0,0 +1,3 @@ +import ProxyBuilder.builder + +ProxyBuilder.builder.test() diff --git a/ProxyBuilder/main.py b/ProxyBuilder/builder.py similarity index 98% rename from ProxyBuilder/main.py rename to ProxyBuilder/builder.py index 18409fd..b200563 100644 --- a/ProxyBuilder/main.py +++ b/ProxyBuilder/builder.py @@ -7,6 +7,7 @@ import ctypes import random import socket import subprocess + from ProxyBuilder import Shadowsocks from ProxyBuilder import ShadowsocksR @@ -129,3 +130,6 @@ def destroy(taskInfo): # 结束客户端并清理 try: os.remove(taskInfo['file']) # 删除配置文件 except: pass + +def test(): + print("ProxyBuilder test") diff --git a/demo.py b/demo.py index 28d0d59..5e81a39 100644 --- a/demo.py +++ b/demo.py @@ -1,7 +1,7 @@ import time import socket import requests -import ProxyBuilder +import ProxyBuilder as Builder def checkSocksPort(port): try: @@ -40,11 +40,14 @@ testInfo = { } print("start") + +print(dir(Builder)) + print(testInfo) -task = ProxyBuilder.build(testInfo, '/tmp/ProxyC') +task = Builder.build(testInfo, '/tmp/ProxyC') print(task) time.sleep(1) -if ProxyBuilder.check(task) == False: +if Builder.check(task) == False: print("error exit") else: print("test with gstatic") @@ -55,6 +58,5 @@ else: print("ok") else: print("error") - ProxyBuilder.destroy(task) + Builder.destroy(task) print("stop") - \ No newline at end of file