一个用于交互式、基于页面的控制台应用程序的框架

almanac的Python项目详细描述


almanac logo

一个用于交互式、基于页面的控制台应用程序的框架

linux build statuswindows build statuspypipython version


概要

almanac框架旨在充当一个直观的界面,用于启动交互式、基于页面的控制台应用程序。可以把它看作是Python Prompt Toolkit和{a6}之上的Python元编程层。在

示例

almanac转换为:

"""Welcome to a simple interactive HTTP client.The current URL to request is the application's current path. Directories will becreated as you cd into them."""importaiohttpimportasynciofromalmanacimporthighlight_for_mimetype,make_standard_app,PagePathapp=make_standard_app()@app.on_init()asyncdefruns_at_start_up():app.io.raw(__doc__)app.bag.session=aiohttp.ClientSession()app.io.info('Session opened!')@app.on_exit()asyncdefruns_at_shut_down():awaitapp.bag.session.close()app.io.info('Session closed!')@app.prompt_text()defcustom_prompt():stripped_path=str(app.page_navigator.current_page.path).lstrip('/')returnf'{stripped_path}> '@app.hook.before('cd')asyncdefcd_hook_before(path:PagePath):ifpathnotinapp.page_navigator:app.page_navigator.add_directory_page(path)@app.hook.exception(aiohttp.ClientError)asyncdefhandle_aiohttp_errors(exc:aiohttp.ClientError):app.io.error(f'{exc.__class__.__name__}: {str(exc)}')@app.cmd.register()@app.arg.method(choices=['GET','POST','PUT'],description='HTTP verb for request.')@app.arg.proto(choices=['http','https'],description='Protocol for request.')asyncdefrequest(method:str,*,proto:str='https',**params:str):"""Send an HTTP or HTTPS request."""path=str(app.current_path).lstrip('/')url=f'{proto}://{path}'app.io.info(f'Sending {method} request to {url}...')resp=awaitapp.bag.session.request(method,url,params=params)asyncwithresp:text=awaitresp.text()highlighted_text=highlight_for_mimetype(text,resp.content_type)app.io.info(f'Status {resp.status} response from {resp.url}')app.io.info('Here\'s the content:')app.io.ansi(highlighted_text)if__name__=='__main__':asyncio.run(app.prompt())

在这方面:

安装

您可以从PyPI下载最新的打包版本:

^{pr2}$

或者,您可以从版本控制中获取最新版本:

pip install https://github.com/welchbj/almanac/archive/master.tar.gz

许可证

根据LICENSE.txt文件,此存储库的原始内容在MIT License下授权。在

一些解析逻辑是从python-nubia项目借用的,并在该项目的BSD License下获得许可。有关详细信息,请参阅^{}中的注释。在

发展

开发依赖项可以安装在:

pip install -r deps/dev-requirements.txt

要运行测试,请使用:

python tasks.py test

要对代码执行lint和type检查,请使用:

flake8 .
mypy .

当需要停止发布时,请使用:

python setup.py bdist_wheel sdist
twine check dist/*.whl dist/*.gz
twine upload dist/*.whl dist/*.gz

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

推荐PyPI第三方库


热门话题
java结合两个Date实例使用Joda创建datetime   带有POI和FileOutputStream的java Swing应用程序性能问题   Java中是否存在类似于Python的异常?   Java中有界通配符的泛型   使用字符和子字符串的java不同输出   在Java中获取LDAP模式   java自定义类在自身上生成ClassNotFoundException   java连接到从internet到通过LAN连接到internet的系统的serversocket   java如何通过maven在jaxws中使用jaxb插件?   java Kerberos如何获取主体或客户端名称?   java应用服务器中是否有JDBC的单点登录解决方案?   java是存储矩阵值以便以后访问的更好方法   Java等级计算器。开始这门课我需要一些帮助   未找到Android“libc++\u shared.so”中的java OpenCV实现   当我使用web配置部署描述符时使用java。xml。它显示了错误   java为什么我的ArrayList的add方法冲突,如何编辑我的自定义add方法   java创建一个以集合为键的映射?   java如何将用户输入到数字三角形中   为什么Java在读取LinkedHashMap时会自动从字符串转换为整数   类动态创建和读取java类