python 3库,用于构建gopher客户机和服务器

Pituophis的Python项目详细描述


皮托菲斯

Documentation StatusPyPI versionPyPI license

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现在允许您提供目录。提供地鼠地图、目录和文件是现成的。

server_def

自定义处理程序

pituophis还允许您为gopher请求编写自定义处理程序。

server

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Spring框架服务单元测试   在Java中遍历hashmaps的hashmap以检索字符串值   如何使用CodeQL检查Java注释是否具有特定属性?   java为什么在Spring Boot中访问此资源而不是登录弹出窗口需要始终获得完全身份验证   处理将多集计数转换为列表的过程   java另一个线性布局,没有出现按钮   eclipse Java映像加载未显示在jar中   java Junit类无法加载基本测试类ApplicationContext   java如何在main中使用my getvalues()方法打印列表   java Sonar,S128:切换案例应该以无条件的“中断”语句结束,而不是继续   java从socket读取字符串错误连接重置错误   java使用新数据刷新任意图表饼图   java通过异步运行lambda访问方法参数   java错误的结果一旦我处理try and catch