URI 模板
项目描述
uri模板
文档– GitHub – BitBucket – Travis-CI
处理URI 模板的简单 python 库。API看起来像
from uritemplate import URITemplate, expand
# NOTE: URI params must be strings not integers
gist_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
# or
print(expand(gist_uri, gist_id='123456'))
# also
t.expand({'gist_id': '123456'})
print(expand(gist_uri, {'gist_id': '123456'}))
上课可能有用的地方
import requests
class GitHubUser(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)
if response.status_code == 200:
self.__dict__.update(response.json())
加载包含此类的模块时,会评估GitHubUser.url,因此会创建一次模板。在 Python 中通常很难注意到,但对象创建会消耗大量时间 ,uritemplate 所依赖的re模块也会如此。构造一次对象应该可以减少代码运行的时间。
安装
pip install uritemplate.py
执照
修改后的 BSD许可证
变更日志 - uritemplate
2.0.0 - 2016-08-29
将 uritemplate.py 合并到 uritemplate
变更日志 - uritemplate.py
3.0.2 - 2015-08-30
修复元包要求。
3.0.1 - 2015-08-29
弃用 uritemplate。这个包现在是一个依赖于 uritemplate 的元包。
2.0.0 - 2016-08-20
将 uritemplate.py 重新许可为 Apache 2 和 BSD(参见 https://github.com/sigmavirus24/uritemplate/pull/23)
1.0.1 - 2016-08-18
修复一些小的包装问题。
1.0.0 - 2016-08-17
修复了 Python 2.6 和 2.7 上 urllib.quote 的 Unicode 值处理。
通过版本号确认公共稳定 API。
0.3.0 - 2013-10-22
添加#partial以部分扩展模板并返回 URITemplate的新实例。
0.2.0 - 2013-07-26
稍微重构一下库并添加更多测试。
如果直接从 uritemplate.template使用URIVariable ,则向后与 0.1.x 不兼容
0.1.1 - 2013-05-19
添加在当前 URI 中获取变量名称集的功能
如果没有给出值或默认值,只需返回一个空字符串
修复 sdist
0.1.0 - 2013-05-14
初始发行
项目详情
关
uritemplate.py -3.0.2.tar.gz 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | e0cdeb0f55ec18e1580974e8017cd188549aacc2aba664ae756adb390b9d45b4 |
|
| MD5 | ee63cccbba43851e18f902f86cba0688 |
|
| 布莱克2-256 | 1297e12695c7d7710143767022ce931061b4a6b5b19982b20ecf5d71cdde3da1 |
关
uritemplate.py -3.0.2-py2.py3-none-any.whl 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | a0c459569e80678c473175666e0d1b3af5bc9a13f84463ec74f808f3dd12ca47 |
|
| MD5 | c0402e82a52d636bc7a59049685e7d1c |
|
| 布莱克2-256 | 8bba6cbb9c3bf4f53997d8d1f69414fc7962f536ba43d283f0e32de68534f6a4 |