URI模板
项目描述
uritemplate
文档 – GitHub – BitBucket – Travis-CI
一个简单的Python库,用于处理URI模板。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.py以支持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 |
|
BLAKE2b-256 | 1297e12695c7d7710143767022ce931061b4a6b5b19982b20ecf5d71cdde3da1 |
关闭
uritemplate.py-3.0.2-py2.py3-none-any.whl的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | a0c459569e80678c473175666e0d1b3af5bc9a13f84463ec74f808f3dd12ca47 |
|
MD5 | c0402e82a52d636bc7a59049685e7d1c |
|
BLAKE2b-256 | 8bba6cbb9c3bf4f53997d8d1f69414fc7962f536ba43d283f0e32de68534f6a4 |