本文整理汇总了Python中uritemplate.URITemplate方法的典型用法代码示例。如果您正苦于以下问题:Python uritemplate.URITemplate方法的具体用法?Python uritemplate.URITemplate怎么用?Python uritemplate.URITemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类uritemplate
的用法示例。
在下文中一共展示了uritemplate.URITemplate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import uritemplate [as 别名]
# 或者: from uritemplate import URITemplate [as 别名]
def __init__(self, team, session=None):
super(Team, self).__init__(team, session)
self._api = team.get('url', '')
#: This team's name.
self.name = team.get('name')
#: Unique ID of the team.
self.id = team.get('id')
#: Permission leve of the group
self.permission = team.get('permission')
#: Number of members in this team.
self.members_count = team.get('members_count')
members = team.get('members_url')
#: Members URL Template. Expands with ``member``
self.members_urlt = URITemplate(members) if members else None
#: Number of repos owned by this team.
self.repos_count = team.get('repos_count')
#: Repositories url (not a template)
self.repositories_url = team.get('repositories_url')
示例2: feeds
# 需要导入模块: import uritemplate [as 别名]
# 或者: from uritemplate import URITemplate [as 别名]
def feeds(self):
"""List GitHub's timeline resources in Atom format.
:returns: dictionary parsed to include URITemplates
"""
url = self._build_url('feeds')
json = self._json(self._get(url), 200)
del json['ETag']
del json['Last-Modified']
urls = [
'timeline_url', 'user_url', 'current_user_public_url',
'current_user_url', 'current_user_actor_url',
'current_user_organization_url',
]
for url in urls:
json[url] = URITemplate(json[url])
links = json.get('_links', {})
for d in links.values():
d['href'] = URITemplate(d['href'])
return json
示例3: expand
# 需要导入模块: import uritemplate [as 别名]
# 或者: from uritemplate import URITemplate [as 别名]
def expand(self, var_dict=None, **kwargs):
"""Expand the template with the given parameters.
:param dict var_dict: Optional dictionary with variables and values
:param kwargs: Alternative way to pass arguments
:returns: str
Example::
t = URITemplate('https://api.github.com{/end}')
t.expand({'end': 'users'})
t.expand(end='gists')
.. note:: Passing values by both parts, may override values in
``var_dict``. For example::
expand('https://{var}', {'var': 'val1'}, var='val2')
``val2`` will be used instead of ``val1``.
"""
return self._expand(_merge(var_dict, kwargs), False)
示例4: partial
# 需要导入模块: import uritemplate [as 别名]
# 或者: from uritemplate import URITemplate [as 别名]
def partial(self, var_dict=None, **kwargs):
"""Partially expand the template with the given parameters.
If all of the parameters for the template are not given, return a
partially expanded template.
:param dict var_dict: Optional dictionary with variables and values
:param kwargs: Alternative way to pass arguments
:returns: :class:`URITemplate`
Example::
t = URITemplate('https://api.github.com{/end}')
t.partial() # => URITemplate('https://api.github.com{/end}')
"""
return URITemplate(self._expand(_merge(var_dict, kwargs), True))
示例5: create
# 需要导入模块: import uritemplate [as 别名]
# 或者: from uritemplate import URITemplate [as 别名]
def create(self, name=None, description=None):
"""Creates a new, empty dataset.
Parameters
----------
name : str, optional
The name of the dataset.
description : str, optional
The description of the dataset.
Returns
-------
request.Response
The response contains the properties of a new dataset as a JSON object.
"""
uri = URITemplate(self.baseuri + '/{owner}').expand(
owner=self.username)
return self.session.post(uri, json=self._attribs(name, description))
示例6: read_dataset
# 需要导入模块: import uritemplate [as 别名]
# 或者: from uritemplate import URITemplate [as 别名]
def read_dataset(self, dataset):
"""Retrieves (reads) a single dataset.
Parameters
----------
dataset : str
The dataset id.
Returns
-------
request.Response
The response contains the properties of the retrieved dataset as a JSON object.
"""
uri = URITemplate(self.baseuri + '/{owner}/{id}').expand(
owner=self.username, id=dataset)
return self.session.get(uri)
示例7: update_dataset
# 需要导入模块: import uritemplate [as 别名]
# 或者: from uritemplate import URITemplate [as 别名]
def update_dataset(self, dataset, name=None, description=None):
"""Updates a single dataset.
Parameters
----------
dataset : str
The dataset id.
name : str, optional
The name of the dataset.
description : str, optional
The description of the dataset.
Returns
-------
request.Response
The response contains the properties of the updated dataset as a JSON object.
"""
uri = URITemplate(self.baseuri + '/{owner}/{id}').expand(
owner=self.username, id=dataset)
return self.session.patch(uri, json=self._attribs(name, description))
示例8: read_feature
# 需要导入模块: import uritemplate [as 别名]
# 或者: from uritemplate import URITemplate [as 别名]
def read_feature(self, dataset, fid):
"""Retrieves (reads) a feature in a dataset.
Parameters
----------
dataset : str
The dataset id.
fid : str
The feature id.
Returns
-------
request.Response
The response contains a GeoJSON representation of the feature.
"""
uri = URITemplate(
self.baseuri + '/{owner}/{did}/features/{fid}').expand(
owner=self.username, did=dataset, fid=fid)
return self.session.get(uri)
示例9: delete_feature
# 需要导入模块: import uritemplate [as 别名]
# 或者: from uritemplate import URITemplate [as 别名]
def delete_feature(self, dataset, fid):
"""Removes a feature from a dataset.
Parameters
----------
dataset : str
The dataset id.
fid : str
The feature id.
Returns
-------
HTTP status code.
"""
uri = URITemplate(
self.baseuri + '/{owner}/{did}/features/{fid}').expand(
owner=self.username, did=dataset, fid=fid)
return self.session.delete(uri)
示例10: tile
# 需要导入模块: import uritemplate [as 别名]
# 或者: from uritemplate import URITemplate [as 别名]
def tile(self, username, style_id, z, x, y, tile_size=512, retina=False):
"/styles/v1/{username}/{style_id}/tiles/{tileSize}/{z}/{x}/{y}{@2x}"
if tile_size not in (256, 512):
raise errors.ImageSizeError('tile_size must be 256 or 512 pixels')
pth = '/{username}/{style_id}/tiles/{tile_size}/{z}/{x}/{y}'
values = dict(username=username, style_id=style_id,
tile_size=tile_size, z=z, x=x, y=y)
uri = URITemplate(self.baseuri + pth).expand(**values)
if retina:
uri += '@2x'
res = self.session.get(uri)
self.handle_http_error(res)
return res
示例11: match
# 需要导入模块: import uritemplate [as 别名]
# 或者: from uritemplate import URITemplate [as 别名]
def match(self, feature, gps_precision=None, profile='mapbox.driving'):
"""Match features to OpenStreetMap data."""
profile = self._validate_profile(profile)
feature = self._validate_feature(feature)
geojson_line_feature = json.dumps(feature)
uri = URITemplate(self.baseuri + '/{profile}.json').expand(
profile=profile)
params = None
if gps_precision:
params = {'gps_precision': gps_precision}
res = self.session.post(uri, data=geojson_line_feature, params=params,
headers={'Content-Type': 'application/json'})
self.handle_http_error(res)
def geojson():
return res.json()
res.geojson = geojson
return res
示例12: __init__
# 需要导入模块: import uritemplate [as 别名]
# 或者: from uritemplate import URITemplate [as 别名]
def __init__(self, release, session=None):
super(Release, self).__init__(release, session)
self._api = release.get('url')
#: List of :class:`Asset <Asset>` objects for this release
self.assets = [Asset(i, self) for i in release.get('assets', [])]
#: URL for uploaded assets
self.assets_url = release.get('assets_url')
#: Body of the release (the description)
self.body = release.get('body')
#: Date the release was created
self.created_at = self._strptime(release.get('created_at'))
#: Boolean whether value is True or False
self.draft = release.get('draft')
#: HTML URL of the release
self.html_url = release.get('html_url')
#: GitHub id
self.id = release.get('id')
#: Name given to the release
self.name = release.get('name')
#; Boolean whether release is a prerelease
self.prerelease = release.get('prerelease')
#: Date the release was published
self.published_at = self._strptime(release.get('published_at'))
#: Name of the tag
self.tag_name = release.get('tag_name')
#: "Commit" that this release targets
self.target_commitish = release.get('target_commitish')
upload_url = release.get('upload_url')
#: URITemplate to upload an asset with
self.upload_urlt = URITemplate(upload_url) if upload_url else None
示例13: variables
# 需要导入模块: import uritemplate [as 别名]
# 或者: from uritemplate import URITemplate [as 别名]
def variables(uri):
try:
return uritemplate.URITemplate(uri).variable_names
except TypeError:
return set()
示例14: __init__
# 需要导入模块: import uritemplate [as 别名]
# 或者: from uritemplate import URITemplate [as 别名]
def __init__(self, uri):
self._uri = uritemplate.URITemplate(uri or "")
示例15: __init__
# 需要导入模块: import uritemplate [as 别名]
# 或者: from uritemplate import URITemplate [as 别名]
def __init__(self, parent, name, description, request_method, uri_template,
parameters, attributes):
assert parameters is None or isinstance(parameters, Parameters)
assert attributes is None or isinstance(attributes, Attributes)
super(ApiSection, self).__init__(parent, name, description)
self._request_method = request_method
self._uri_template = URITemplate(uri_template) \
if uri_template else None
self._parameters = parameters
self._attributes = attributes