Python针对特定服务定制的代理工具V2.0----------(__init__.py与Run.py)

来源:互联网 发布:mac需要安装flash插件 编辑:程序博客网 时间:2024/06/05 20:06

__init__.py:是为了把Lib文件打包成一个包,这个文件可以为空,也可以添加要导出的包。在这个项目中,在该文件中添加了如下信息:

from proxyHandler import proxyHandlerfrom server import Serverimport zipdeal
如果没有这个文件,Run.py文件就不能调用Lib文件中的方法。

Run.py:在控制台输入代理服务IP与端口号,调用Server方法创建代理服务

#coding=utf8from Lib import Server'''创建一个函数用来运。该版本存在一个无法把gzip的数据正常输出。这是待修改完善的方法。'''def run():    #设置代理服务IP和端口    host=raw_input("Enter the IP:")    port=raw_input("Enter the port:")    #调用Server方法创建代理服务    Server(host,int(port))    if __name__=='__main__':    run()
运行结果图如下:


运行在控制台出现乱码,是从压缩文件中读取文件中没有进行处理,所以出现下个问题。在版本2.1中会解决。

针对截图中出现的mainFrame.py文件是基于Tkinter包的简单设计界面,粗略代码如下,后期会进行优化整合:

#coding=utf8from Tkinter import *mainFrame=Tk()'''设置代理服务输入框界面'''hotfrm=Frame(mainFrame)IPlable=Label(hotfrm,text="hostIP:")IPlable.pack(side=LEFT,fill=X)IPentry=Entry(hotfrm)IPentry.pack(side=LEFT,fill=X)portlable=Label(hotfrm,text="port:")portlable.pack(side=LEFT,fill=X)portentry=Entry(hotfrm)portentry.pack(side=LEFT,fill=X)hotfrm.pack()'''设置抓包数据json输出窗口'''showOut=Frame(mainFrame)OutLable=Label(showOut,text=u"实际JSON")OutLable.pack(side=LEFT,fill=X)JsonText=Text(showOut)JsonText.pack(side=LEFT,fill=Y)showOut.pack(side=LEFT,fill=Y)'''设置实际json输出窗口'''expectOut=Frame(mainFrame)jsonLable=Label(expectOut,text=u"期望JSON")jsonLable.pack(side=RIGHT,fill=X)expJsonText=Text(expectOut)expJsonText.pack(side=RIGHT,fill=Y)expectOut.pack(side=RIGHT,fill=Y)mainFrame.mainloop()
运行结果图如下所示:



0 0
原创粉丝点击