我发现自己一遍又一遍地重写泛型类。
cmyui的Python项目详细描述
一般cmyui的通用多用途库(及类似)
好东西
- 异步TCP服务器(解析ur头和参数以及多部分等)
- (A) 同步mysql包装器(fetch(all)、execute、iterall,如果有人关心这个问题,还需要更多吗?)在
- 完全2020年11月1日-ESU!带有超热上下文管理器的beatmap和replay解析器(OSAAPIV2包装器即将推出)
- 非常简单的日志设置与ansi/rgb颜色支持,可能会得到更多的控制未来
- 很多其他实用程序函数和类,主要是为了满足我的特定需要,但似乎非常通用
- 再来一次,如果有人愿意问的话?在
""" AsyncTCPServer (relatively for the project you're probably taking on if you care about this example) basic example"""importasyncioimportcmyuiasyncdefhandle_conn(conn:cmyui.AsyncConnection)->None:# see the AsyncConnection implementation for# details on it's use and methods/attributes.# i've provided a simple server example below.if'Host'notinconn.headers:awaitconn.send(400,b'Missing required headers.')returnifconn.cmd=='GET':ifconn.path=='/math/sum.php':if'x'notinconn.argsor'y'notinconn.args:awaitconn.send(400,b'Must supply x & y parameters.')returnx=conn.args['x']y=conn.args['y']ifnotx.isdecimal()ornoty.isdecimal():awaitconn.send(400,b'Must supply integral parameters.')returnawaitconn.send(200,f'Sum: {x+y}'.encode())returnelse:awaitconn.send(404,b'Handler not found.')returnelifconn.cmd=='POST':ifconn.path.startswith('/ss/')andconn.path.endswith('.png'):# POSTing with screenshot in multipart data as a file.if'screenshot'notinconn.files:awaitconn.send(400,b'Missing screenshot data.')returnss_id=conn.path[4:-4]ifnotss_id.isdecimal():awaitconn.send(400,b'Invalid screenshot id.')returnwithopen(f'ss/{ss_id}.png','wb')asf:f.write(conn.files['screenshot'])log(f'Saved screenshot {ss_id}.png',Ansi.LGREEN)returnelse:awaitconn.send(404,b'Handler not found.')returnelse:awaitconn.send(400,b'Handler not found.')returnasyncdefrun_server():loop=asyncio.get_event_loop()# support for both ipv4 and unix domain socketsaddr=('127.0.0.1',5001)# ipv4addr='/tmp/gulag.sock'# unix domainasyncwithcmyui.AsyncTCPServer(addr)asserv:asyncforconninserv.listen(max_conns=16):loop.create_task(handle_conn(conn))asyncio.run(run_server())"""More docs coming soon?™️"""
- 项目
标签: