一个用于交互式、基于页面的控制台应用程序的框架
almanac的Python项目详细描述
在
一个用于交互式、基于页面的控制台应用程序的框架 在
概要
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
- 项目
标签: