Browse Source

refactor: python package of ProxyBuilder

master
Dnomd343 3 years ago
parent
commit
8da30de6be
  1. 6
      ProxyBuilder/__init__.py
  2. 3
      ProxyBuilder/__main__.py
  3. 4
      ProxyBuilder/builder.py
  4. 12
      demo.py

6
ProxyBuilder/__init__.py

@ -1,6 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
from ProxyBuilder.main import build from ProxyBuilder.builder import *
from ProxyBuilder.main import check
from ProxyBuilder.main import destroy __all__ = [ 'build', 'check', 'destroy' ]

3
ProxyBuilder/__main__.py

@ -0,0 +1,3 @@
import ProxyBuilder.builder
ProxyBuilder.builder.test()

4
ProxyBuilder/main.py → ProxyBuilder/builder.py

@ -7,6 +7,7 @@ import ctypes
import random import random
import socket import socket
import subprocess import subprocess
from ProxyBuilder import Shadowsocks from ProxyBuilder import Shadowsocks
from ProxyBuilder import ShadowsocksR from ProxyBuilder import ShadowsocksR
@ -129,3 +130,6 @@ def destroy(taskInfo): # 结束客户端并清理
try: try:
os.remove(taskInfo['file']) # 删除配置文件 os.remove(taskInfo['file']) # 删除配置文件
except: pass except: pass
def test():
print("ProxyBuilder test")

12
demo.py

@ -1,7 +1,7 @@
import time import time
import socket import socket
import requests import requests
import ProxyBuilder import ProxyBuilder as Builder
def checkSocksPort(port): def checkSocksPort(port):
try: try:
@ -40,11 +40,14 @@ testInfo = {
} }
print("start") print("start")
print(dir(Builder))
print(testInfo) print(testInfo)
task = ProxyBuilder.build(testInfo, '/tmp/ProxyC') task = Builder.build(testInfo, '/tmp/ProxyC')
print(task) print(task)
time.sleep(1) time.sleep(1)
if ProxyBuilder.check(task) == False: if Builder.check(task) == False:
print("error exit") print("error exit")
else: else:
print("test with gstatic") print("test with gstatic")
@ -55,6 +58,5 @@ else:
print("ok") print("ok")
else: else:
print("error") print("error")
ProxyBuilder.destroy(task) Builder.destroy(task)
print("stop") print("stop")
Loading…
Cancel
Save