python 3库,用于构建gopher客户机和服务器
Pituophis的Python项目详细描述
皮托菲斯
python 3库,用于构建gopher客户端和服务器
pituophis目前需要九个模块:os、re、sockets、asyncio、ssl、mimetypes、glob和urllib,这是大多数python 3.7安装中的标准模块,natsort也需要。pituophis可以简单地作为如下模块加载:
importpituophis
客户机
pituophis可以通过Request.get()
和get()
函数从地鼠服务器(s/gopher tls和常规地鼠)获取文件和文本。
示例
以纯文本形式获取菜单和文件:
pituophis.get('gopher.floodgap.com').text()pituophis.get('gopher://gopher.floodgap.com/1/').text()pituophis.get('gopher://gopher.floodgap.com:70/0/gopher/proxy').text()pituophis.get(host='gopher.floodgap.com',port=70,path='/').text()pituophis.get(host='gopher.floodgap.com',port=70,path='/gopher/proxy').text()pituophis.get(host='khzae.net',port=105,path='/',tls=True).text()# TLS!pituophis.get('gophers://khzae.net:105/1/').text()# gophers:// URLs!
获取菜单,已分析:
menu=pituophis.get('gopher.floodgap.com').menu()forselectorinmenu:print(selector.type)print(selector.text)print(selector.path)print(selector.host)print(selector.port)
使用搜索服务:
pituophis.get('gopher://gopher.floodgap.com:70/7/v2/vs?toast').text()pituophis.get(host='gopher.floodgap.com',port=70,path='/v2/vs',query='toast').text()
下载二进制文件:
pituophis.get('gopher://gopher.floodgap.com:70/9/gopher/clients/win/hgopher2_3.zip').binarypituophis.get(host='gopher.floodgap.com',port=70,path='/gopher/clients/win/hgopher2_3.zip').binary
也可以直接创建和处理请求:
importpituophisreq=pituophis.Request()req.host='gopher.floodgap.com'# set to 127.0.0.1 by defaultreq.port=70# set to 70 as default, as per traditionreq.type='7'# set to 9 by default, purely for client usagereq.path='/v2/vs'# set to '/' by defaultreq.query='food'# set to '' (nothing) by defaultreq.tls=False# set to False by defaultprint('Getting',req.url())rsp=req.get()print(rsp.text())
它们也可以通过url创建:
importpituophisreq=pituophis.parse_url('gopher://gopher.floodgap.com/7/v2/vs?food')print('Getting',req.url())rsp=req.get()print(rsp.text())
服务器
默认处理程序
Pituophis现在允许您提供目录。提供地鼠地图、目录和文件是现成的。
自定义处理程序
pituophis还允许您为gopher请求编写自定义处理程序。