当前位置: 首页>>代码示例>>Python>>正文


Python URITemplate.expand方法代码示例

本文整理汇总了Python中uritemplate.URITemplate.expand方法的典型用法代码示例。如果您正苦于以下问题:Python URITemplate.expand方法的具体用法?Python URITemplate.expand怎么用?Python URITemplate.expand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在uritemplate.URITemplate的用法示例。


在下文中一共展示了URITemplate.expand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_default_value

# 需要导入模块: from uritemplate import URITemplate [as 别名]
# 或者: from uritemplate.URITemplate import expand [as 别名]
 def test_default_value(self):
     uri = 'https://api.github.com/user{/user=sigmavirus24}'
     t = URITemplate(uri)
     self.assertEqual(t.expand(),
                      'https://api.github.com/user/sigmavirus24')
     self.assertEqual(t.expand(user='lukasa'),
                      'https://api.github.com/user/lukasa')
开发者ID:sigmavirus24,项目名称:uritemplate,代码行数:9,代码来源:test_uritemplate.py

示例2: test_no_variables_in_uri

# 需要导入模块: from uritemplate import URITemplate [as 别名]
# 或者: from uritemplate.URITemplate import expand [as 别名]
 def test_no_variables_in_uri(self):
     """
     This test ensures that if there are no variables present, the
     template evaluates to itself.
     """
     uri = 'https://api.github.com/users'
     t = URITemplate(uri)
     self.assertEqual(t.expand(), uri)
     self.assertEqual(t.expand(users='foo'), uri)
开发者ID:sigmavirus24,项目名称:uritemplate,代码行数:11,代码来源:test_uritemplate.py

示例3: test_expand

# 需要导入模块: from uritemplate import URITemplate [as 别名]
# 或者: from uritemplate.URITemplate import expand [as 别名]
    def test_expand(self):
        """
        This test ensures that expansion works as expected.
        """
        # Single
        t = URITemplate("https://api.github.com/users{/user}")
        expanded = "https://api.github.com/users/sigmavirus24"
        self.assertEqual(t.expand(user="sigmavirus24"), expanded)
        v = t.variables[0]
        self.assertEqual(v.expand({"user": None}), {"/user": ""})

        # Multiple
        t = URITemplate("https://api.github.com/users{/user}{/repo}")
        expanded = "https://api.github.com/users/sigmavirus24/github3.py"
        self.assertEqual(t.expand({"repo": "github3.py"}, user="sigmavirus24"), expanded)
开发者ID:pyspi-mirror,项目名称:uritemplate,代码行数:17,代码来源:test_uritemplate.py

示例4: test_expand

# 需要导入模块: from uritemplate import URITemplate [as 别名]
# 或者: from uritemplate.URITemplate import expand [as 别名]
    def test_expand(self):
        """
        This test ensures that expansion works as expected.
        """
        # Single
        t = URITemplate('https://api.github.com/users{/user}')
        expanded = 'https://api.github.com/users/sigmavirus24'
        self.assertEqual(t.expand(user='sigmavirus24'), expanded)
        v = t.variables[0]
        self.assertEqual(v.expand({'user': None}), {'/user': ''})

        # Multiple
        t = URITemplate('https://api.github.com/users{/user}{/repo}')
        expanded = 'https://api.github.com/users/sigmavirus24/github3.py'
        self.assertEqual(
            t.expand({'repo': 'github3.py'}, user='sigmavirus24'),
            expanded
        )
开发者ID:sigmavirus24,项目名称:uritemplate,代码行数:20,代码来源:test_uritemplate.py

示例5: PriceURL

# 需要导入模块: from uritemplate import URITemplate [as 别名]
# 或者: from uritemplate.URITemplate import expand [as 别名]
class PriceURL:
    """ PriceURl implements an easily readible, funcational, and modifiable URL for retreiving prices
    :param item_type:
    :param item_number:
    :param  =color_id:
    
    Usage:
        url_template = PriceURL()
        uri = url_template.expand(item_type=itemtypeID, item_number=itemID, color_id=itemColorID)
        'https://www.bricklink.com/catalogPG.asp?P=3004&colorID=8'
    """

    url = ('https://www.bricklink.com/catalogPG.asp?'
           '{item_type} = {item_number} &'
           'colorID = {color_id}'
           )

    def __init__(self):
        self.raw_url = PriceURL.url.replace(" ", "")  # Spaces improved readability
        self.url_template = URITemplate(self.raw_url)

    def expand(self, itemtypeID, itemID, itemColorID):
        self.url = self.url_template.expand(item_type=itemtypeID, item_number=itemID, color_id=itemColorID)
        return self.url
开发者ID:Geekly,项目名称:pybcm,代码行数:26,代码来源:elementreader.py

示例6: test_no_mutate

# 需要导入模块: from uritemplate import URITemplate [as 别名]
# 或者: from uritemplate.URITemplate import expand [as 别名]
 def test_no_mutate(self):
     args = {}
     t = URITemplate('')
     t.expand(args, key=1)
     self.assertEqual(args, {})
开发者ID:sigmavirus24,项目名称:uritemplate,代码行数:7,代码来源:test_uritemplate.py

示例7: _test_

# 需要导入模块: from uritemplate import URITemplate [as 别名]
# 或者: from uritemplate.URITemplate import expand [as 别名]
 def _test_(self):
     for k, v in d.items():
         t = URITemplate(k)
         self.assertEqual(t.expand(v['expansion']), v['expected'])
开发者ID:sigmavirus24,项目名称:uritemplate,代码行数:6,代码来源:test_uritemplate.py

示例8: __get_url

# 需要导入模块: from uritemplate import URITemplate [as 别名]
# 或者: from uritemplate.URITemplate import expand [as 别名]
	def __get_url(self, path, id):
		rootUrl = self.hal.get_root_url()
		template = URITemplate(rootUrl + path);

		return template.expand(id= str(id) if id is not None else "")
开发者ID:viagogo,项目名称:gogokit.py,代码行数:7,代码来源:clients.py

示例9: test_default_value

# 需要导入模块: from uritemplate import URITemplate [as 别名]
# 或者: from uritemplate.URITemplate import expand [as 别名]
 def test_default_value(self):
     uri = "https://api.github.com/user{/user=sigmavirus24}"
     t = URITemplate(uri)
     self.assertEqual(t.expand(), "https://api.github.com/user/sigmavirus24")
     self.assertEqual(t.expand(user="lukasa"), "https://api.github.com/user/lukasa")
开发者ID:pyspi-mirror,项目名称:uritemplate,代码行数:7,代码来源:test_uritemplate.py

示例10: User

# 需要导入模块: from uritemplate import URITemplate [as 别名]
# 或者: from uritemplate.URITemplate import expand [as 别名]

#.........这里部分代码省略.........
        :param str address: (required), email address to delete
        :returns: bool
        """
        return self.delete_email_addresses([address])

    @requires_auth
    def delete_email_addresses(self, addresses=[]):
        """Delete the email addresses in ``addresses`` from the
        authenticated user's account.

        :param list addresses: (optional), email addresses to be removed
        :returns: bool
        """
        url = self._build_url('user', 'emails')
        return self._boolean(self._delete(url, data=dumps(addresses)),
                             204, 404)

    def is_assignee_on(self, login, repository):
        """Checks if this user can be assigned to issues on login/repository.

        :returns: :class:`bool`
        """
        url = self._build_url('repos', login, repository, 'assignees',
                              self.login)
        return self._boolean(self._get(url), 204, 404)

    def is_following(self, login):
        """Checks if this user is following ``login``.

        :param str login: (required)
        :returns: bool

        """
        url = self.following_urlt.expand(other_user=login)
        return self._boolean(self._get(url), 204, 404)

    def iter_events(self, public=False, number=-1, etag=None):
        """Iterate over events performed by this user.

        :param bool public: (optional), only list public events for the
            authenticated user
        :param int number: (optional), number of events to return. Default: -1
            returns all available events.
        :param str etag: (optional), ETag from a previous request to the same
            endpoint
        :returns: list of :class:`Event <github3.events.Event>`\ s
        """
        path = ['events']
        if public:
            path.append('public')
        url = self._build_url(*path, base_url=self._api)
        return self._iter(int(number), url, Event, etag=etag)

    def iter_followers(self, number=-1, etag=None):
        """Iterate over the followers of this user.

        :param int number: (optional), number of followers to return. Default:
            -1 returns all available
        :param str etag: (optional), ETag from a previous request to the same
            endpoint
        :returns: generator of :class:`User <User>`\ s
        """
        url = self._build_url('followers', base_url=self._api)
        return self._iter(int(number), url, User, etag=etag)

    def iter_following(self, number=-1, etag=None):
开发者ID:esacteksab,项目名称:github3.py,代码行数:70,代码来源:users.py

示例11: Release

# 需要导入模块: from uritemplate import URITemplate [as 别名]
# 或者: from uritemplate.URITemplate import expand [as 别名]
class Release(models.GitHubCore):
    """Representation of a GitHub release.

    It holds the information GitHub returns about a release from a
    :class:`Repository <github3.repos.repo.Repository>`.

    Please see GitHub's `Releases Documentation`_ for more information.

    This object has the following attributes:

    .. attribute:: original_assets

        A list of :class:`~github3.repos.release.Asset` objects representing
        the assets uploaded for this relesae.

    .. attribute:: assets_url

        The URL to retrieve the assets from the API.

    .. attribute:: author

        A :class:`~github3.users.ShortUser` representing the creator of this
        release.

    .. attribute:: body

        The description of this release as written by the release creator.

    .. attribute:: created_at

        A :class:`~datetime.datetime` object representing the date and time
        when this release was created.

    .. attribute:: draft

        A boolean attribute describing whether this release is a draft.

    .. attribute:: html_url

        The URL to view this release in a browser.

    .. attribute:: id

        The unique identifier of this release.

    .. attribute:: name

        The name given to this release by the :attr:`author`.

    .. attribute:: prerelease

        A boolean attribute indicating whether the release is a pre-release.

    .. attribute:: published_at

        A :class:`~datetime.datetime` object representing the date and time
        when this release was publisehd.

    .. attribute:: tag_name

        The name of the tag associated with this release.

    .. attribute:: tarball_url

        The URL to retrieve a GitHub generated tarball for this release from
        the API.

    .. attribute:: target_commitish

        The reference (usually a commit) that is targetted by this release.

    .. attribute:: upload_urlt

        A :class:`~uritemplate.URITemplate` object that expands to form the
        URL to upload assets to.

    .. attribute:: zipball_url

        The URL to retrieve a GitHub generated zipball for this release from
        the API.

    .. _Releases Documentation:
        https://developer.github.com/v3/repos/releases/
    """

    def _update_attributes(self, release):
        self._api = self.url = release["url"]
        self.original_assets = [Asset(i, self) for i in release["assets"]]
        self.assets_url = release["assets_url"]
        self.author = users.ShortUser(release["author"], self)
        self.body = release["body"]
        self.created_at = self._strptime(release["created_at"])
        self.draft = release["draft"]
        self.html_url = release["html_url"]
        self.id = release["id"]
        self.name = release["name"]
        self.prerelease = release["prerelease"]
        self.published_at = self._strptime(release["published_at"])
        self.tag_name = release["tag_name"]
        self.tarball_url = release["tarball_url"]
#.........这里部分代码省略.........
开发者ID:sigmavirus24,项目名称:github3.py,代码行数:103,代码来源:release.py

示例12: User

# 需要导入模块: from uritemplate import URITemplate [as 别名]
# 或者: from uritemplate.URITemplate import expand [as 别名]

#.........这里部分代码省略.........
        return self.delete_email_addresses([address])

    @requires_auth
    def delete_email_addresses(self, addresses=[]):
        """Delete the email addresses in ``addresses`` from the
        authenticated user's account.

        :param list addresses: (optional), email addresses to be removed
        :returns: bool
        """
        url = self._build_url('user', 'emails')
        return self._boolean(self._delete(url, data=dumps(addresses)),
                             204, 404)

    def is_assignee_on(self, username, repository):
        """Check if this user can be assigned to issues on username/repository.

        :param str username: owner's username of the repository
        :param str repository: name of the repository
        :returns: True if the use can be assigned, False otherwise
        :rtype: :class:`bool`
        """
        url = self._build_url('repos', username, repository, 'assignees',
                              self.login)
        return self._boolean(self._get(url), 204, 404)

    def is_following(self, username):
        """Checks if this user is following ``username``.

        :param str username: (required)
        :returns: bool

        """
        url = self.following_urlt.expand(other_user=username)
        return self._boolean(self._get(url), 204, 404)

    def events(self, public=False, number=-1, etag=None):
        """Iterate over events performed by this user.

        :param bool public: (optional), only list public events for the
            authenticated user
        :param int number: (optional), number of events to return. Default: -1
            returns all available events.
        :param str etag: (optional), ETag from a previous request to the same
            endpoint
        :returns: generator of :class:`Event <github3.events.Event>`\ s
        """
        path = ['events']
        if public:
            path.append('public')
        url = self._build_url(*path, base_url=self._api)
        return self._iter(int(number), url, Event, etag=etag)

    def followers(self, number=-1, etag=None):
        """Iterate over the followers of this user.

        :param int number: (optional), number of followers to return. Default:
            -1 returns all available
        :param str etag: (optional), ETag from a previous request to the same
            endpoint
        :returns: generator of :class:`User <User>`\ s
        """
        url = self._build_url('followers', base_url=self._api)
        return self._iter(int(number), url, User, etag=etag)

    def following(self, number=-1, etag=None):
开发者ID:simonvpe,项目名称:trj,代码行数:70,代码来源:users.py

示例13: Release

# 需要导入模块: from uritemplate import URITemplate [as 别名]
# 或者: from uritemplate.URITemplate import expand [as 别名]

#.........这里部分代码省略.........
        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

    def _repr(self):
        return '<Release [{0}]>'.format(self.name)

    @requires_auth
    def delete(self):
        """Users with push access to the repository can delete a release.

        :returns: True if successful; False if not successful
        """
        url = self._api
        return self._boolean(
            self._delete(url, headers=Release.CUSTOM_HEADERS),
            204,
            404
        )

    @requires_auth
    def edit(self, tag_name=None, target_commitish=None, name=None, body=None,
             draft=None, prerelease=None):
        """Users with push access to the repository can edit a release.

        If the edit is successful, this object will update itself.

        :param str tag_name: (optional), Name of the tag to use
        :param str target_commitish: (optional), The "commitish" value that
            determines where the Git tag is created from. Defaults to the
            repository's default branch.
        :param str name: (optional), Name of the release
        :param str body: (optional), Description of the release
        :param boolean draft: (optional), True => Release is a draft
        :param boolean prerelease: (optional), True => Release is a prerelease
        :returns: True if successful; False if not successful
        """
        url = self._api
        data = {
            'tag_name': tag_name,
            'target_commitish': target_commitish,
            'name': name,
            'body': body,
            'draft': draft,
            'prerelease': prerelease,
        }
        self._remove_none(data)

        r = self._session.patch(
            url, data=json.dumps(data), headers=Release.CUSTOM_HEADERS
        )

        successful = self._boolean(r, 200, 404)
        if successful:
            # If the edit was successful, let's update the object.
            self.__init__(r.json(), self)

        return successful

    def iter_assets(self, number=-1, etag=None):
        """Iterate over the assets available for this release.

        :param int number: (optional), Number of assets to return
        :param str etag: (optional), last ETag header sent
        :returns: generator of :class:`Asset <Asset>` objects
        """
        url = self._build_url('assets', base_url=self._api)
        return self._iter(number, url, Asset, etag=etag)

    @requires_auth
    def upload_asset(self, content_type, name, asset):
        """Upload an asset to this release.

        All parameters are required.

        :param str content_type: The content type of the asset. Wikipedia has
            a list of common media types
        :param str name: The name of the file
        :param asset: The file or bytes object to upload.
        :returns: :class:`Asset <Asset>`
        """
        headers = Release.CUSTOM_HEADERS.copy()
        headers.update({'Content-Type': content_type})
        url = self.upload_urlt.expand({'name': name})
        r = self._post(url, data=asset, json=False, headers=headers,
                       verify=False)
        if r.status_code in (201, 202):
            return Asset(r.json(), self)
        raise GitHubError(r)
开发者ID:AndreasBackx,项目名称:github3.py,代码行数:104,代码来源:release.py

示例14: _User

# 需要导入模块: from uritemplate import URITemplate [as 别名]
# 或者: from uritemplate.URITemplate import expand [as 别名]
class _User(models.GitHubCore):
    """The :class:`User <User>` object.

    This handles and structures information in the `User section`_.

    Two user instances can be checked like so::

        u1 == u2
        u1 != u2

    And is equivalent to::

        u1.id == u2.id
        u1.id != u2.id

    .. _User section:
        http://developer.github.com/v3/users/
    """

    class_name = "_User"

    def _update_attributes(self, user):
        self.avatar_url = user["avatar_url"]
        self.events_urlt = URITemplate(user["events_url"])
        self.followers_url = user["followers_url"]
        self.following_urlt = URITemplate(user["following_url"])
        self.gists_urlt = URITemplate(user["gists_url"])
        self.gravatar_id = user["gravatar_id"]
        self.html_url = user["html_url"]
        self.id = user["id"]
        self.login = user["login"]
        self.organizations_url = user["organizations_url"]
        self.received_events_url = user["received_events_url"]
        self.repos_url = user["repos_url"]
        self.site_admin = user.get("site_admin")
        self.starred_urlt = URITemplate(user["starred_url"])
        self.subscriptions_url = user["subscriptions_url"]
        self.type = user["type"]
        self.url = self._api = user["url"]
        self._uniq = self.id

    def __str__(self):
        return self.login

    def _repr(self):
        full_name = ""
        name = getattr(self, "name", None)
        if name is not None:
            full_name = ":{}".format(name)
        return "<{s.class_name} [{s.login}{full_name}]>".format(
            s=self, full_name=full_name
        )

    def is_assignee_on(self, username, repository):
        """Check if this user can be assigned to issues on username/repository.

        :param str username: owner's username of the repository
        :param str repository: name of the repository
        :returns: True if the use can be assigned, False otherwise
        :rtype: :class:`bool`
        """
        url = self._build_url(
            "repos", username, repository, "assignees", self.login
        )
        return self._boolean(self._get(url), 204, 404)

    def is_following(self, username):
        """Check if this user is following ``username``.

        :param str username: (required)
        :returns: bool

        """
        url = self.following_urlt.expand(other_user=username)
        return self._boolean(self._get(url), 204, 404)

    def events(self, public=False, number=-1, etag=None):
        r"""Iterate over events performed by this user.

        :param bool public: (optional), only list public events for the
            authenticated user
        :param int number: (optional), number of events to return. Default: -1
            returns all available events.
        :param str etag: (optional), ETag from a previous request to the same
            endpoint
        :returns: generator of :class:`Event <github3.events.Event>`\ s
        """
        path = ["events"]
        if public:
            path.append("public")
        url = self._build_url(*path, base_url=self._api)
        return self._iter(int(number), url, Event, etag=etag)

    def followers(self, number=-1, etag=None):
        r"""Iterate over the followers of this user.

        :param int number: (optional), number of followers to return. Default:
            -1 returns all available
        :param str etag: (optional), ETag from a previous request to the same
            endpoint
#.........这里部分代码省略.........
开发者ID:sigmavirus24,项目名称:github3.py,代码行数:103,代码来源:users.py

示例15: Release

# 需要导入模块: from uritemplate import URITemplate [as 别名]
# 或者: from uritemplate.URITemplate import expand [as 别名]

#.........这里部分代码省略.........
            return True
        return False

    def asset(self, asset_id):
        """Retrieve the asset from this release with ``asset_id``.

        :param int asset_id: ID of the Asset to retrieve
        :returns: :class:`~github3.repos.release.Asset`
        """
        json = None
        if int(asset_id) > 0:
            i = self._api.rfind('/')
            url = self._build_url('assets', str(asset_id),
                                  base_url=self._api[:i])
            json = self._json(self._get(url), 200)
        return self._instance_or_null(Asset, json)

    def assets(self, number=-1, etag=None):
        """Iterate over the assets available for this release.

        :param int number: (optional), Number of assets to return
        :param str etag: (optional), last ETag header sent
        :returns: generator of :class:`Asset <Asset>` objects
        """
        url = self._build_url('assets', base_url=self._api)
        return self._iter(number, url, Asset, etag=etag)

    @requires_auth
    def delete(self):
        """Users with push access to the repository can delete a release.

        :returns: True if successful; False if not successful
        """
        url = self._api
        return self._boolean(
            self._delete(url, headers=Release.CUSTOM_HEADERS),
            204,
            404
        )

    @requires_auth
    def edit(self, tag_name=None, target_commitish=None, name=None, body=None,
             draft=None, prerelease=None):
        """Users with push access to the repository can edit a release.

        If the edit is successful, this object will update itself.

        :param str tag_name: (optional), Name of the tag to use
        :param str target_commitish: (optional), The "commitish" value that
            determines where the Git tag is created from. Defaults to the
            repository's default branch.
        :param str name: (optional), Name of the release
        :param str body: (optional), Description of the release
        :param boolean draft: (optional), True => Release is a draft
        :param boolean prerelease: (optional), True => Release is a prerelease
        :returns: True if successful; False if not successful
        """
        url = self._api
        data = {
            'tag_name': tag_name,
            'target_commitish': target_commitish,
            'name': name,
            'body': body,
            'draft': draft,
            'prerelease': prerelease,
        }
        self._remove_none(data)

        r = self.session.patch(
            url, data=json.dumps(data), headers=Release.CUSTOM_HEADERS
        )

        successful = self._boolean(r, 200, 404)
        if successful:
            # If the edit was successful, let's update the object.
            self._update_attributes(r.json())

        return successful

    @requires_auth
    def upload_asset(self, content_type, name, asset, label=None):
        """Upload an asset to this release.

        All parameters are required.

        :param str content_type: The content type of the asset. Wikipedia has
            a list of common media types
        :param str name: The name of the file
        :param asset: The file or bytes object to upload.
        :param label: (optional), An alternate short description of the asset.
        :returns: :class:`Asset <Asset>`
        """
        headers = {'Content-Type': content_type}
        params = {'name': name, 'label': label}
        self._remove_none(params)
        url = self.upload_urlt.expand(params)
        r = self._post(url, data=asset, json=False, headers=headers)
        if r.status_code in (201, 202):
            return Asset(r.json(), self)
        raise error_for(r)
开发者ID:ArRolin,项目名称:gitsome,代码行数:104,代码来源:release.py


注:本文中的uritemplate.URITemplate.expand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。