URI跟URI模板

uritemplate的Python项目详细描述


uritemplate

DocumentationGitHubBitBucketTravis-CI

处理URI Templates的简单python库。api看起来像

fromuritemplateimportURITemplate,expand# NOTE: URI params must be strings not integersgist_uri='https://api.github.com/users/sigmavirus24/gists{/gist_id}'t=URITemplate(gist_uri)print(t.expand(gist_id='123456'))# => https://api.github.com/users/sigmavirus24/gists/123456# orprint(expand(gist_uri,gist_id='123456'))# alsot.expand({'gist_id':'123456'})print(expand(gist_uri,{'gist_id':'123456'}))

如果有一个类可能有用

importrequestsclassGitHubUser(object):url=URITemplate('https://api.github.com/user{/login}')def__init__(self,name):self.api_url=url.expand(login=name)response=requests.get(self.api_url)ifresponse.status_code==200:self.__dict__.update(response.json())

加载包含该类的模块时,GitHubUser.url是 已求值,因此模板只创建一次。通常很难注意到 python,但是对象创建会耗费大量时间,而且 reuritemplate所依赖的模块。构造对象一次应该 减少代码运行所需的时间。

安装

pip install uritemplate.py

许可证

改良bsd license

更改日志-uritemplate

2.0.0-2016-08-29

  • 将uritemplate.py合并到uritemplate中

changelog-uritemplate.py

2.0.0-2016年8月20日

1.0.1-2016年8月18日

  • 解决一些小包装问题。

1.0.0-2016年8月17日

  • 修复了在python 2.6和2.7上对urllib.quote的unicode值的处理。
  • 通过版本号确认公共稳定API。

0.3.0-2013年10月22日

  • 添加#partial以部分展开模板并返回 URITemplate

0.2.0-2013年7月26日

  • 对库进行一些重构并添加更多测试。
  • 如果直接使用URIVariable,则向后与0.1.x不兼容 uritemplate.template

0.1.1-2013年5月19日

  • 添加在当前uri中获取变量名集的功能
  • 如果没有给定值或默认值,只需返回一个空字符串
  • 修复sdist

0.1.0-2013年5月14日

  • 初始版本

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

推荐PyPI第三方库


热门话题
JAVAutil。整数java的扫描器键盘输入   java通知运行后立即崩溃   java如何在一个只能由类修改而不能由其实例修改的类中生成静态变量?   数据库Java字段猜测   返回值周围的java括号为什么?   java Android更新通讯录中的联系人   一个消费者正在读取数据   java是否可以通过编程方式为蓝牙配对设置pin?   java Spring引导和buildResponseEntity()   java为什么序列化可以在没有实现可序列化的情况下工作   Java同步无助于相互排斥   twitter Java Twitter4J未在推文下显示源标签   为什么Javasocket不支持中断处理?