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


Python PrivateKey.get_api方法代码示例

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


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

示例1: test_admin_creates_keys

# 需要导入模块: from models.private_key import PrivateKey [as 别名]
# 或者: from models.private_key.PrivateKey import get_api [as 别名]
    def test_admin_creates_keys(self):
        self.be_admin_user()

        get_response = self.testapp.get('/admin')
        self.assertEqual(get_response.status_int, 200)
        form = get_response.forms["private-key"]
        self.assertEqual(form.method, 'POST')

        form['oauth_key'] = 'oauth'
        form['api_key'] = 'api'
        post_response = form.submit()

        self.assertEqual(post_response.status_int, 302)
        self.assertEqual(post_response.headers['Location'],
                         'http://localhost:80/admin#tab-private-keys')
        self.assertEqual(PrivateKey.get_oauth(), 'oauth')
        self.assertEqual(PrivateKey.get_api(), 'api')
开发者ID:a14n,项目名称:pub-dartlang,代码行数:19,代码来源:test_private_keys.py

示例2: _query_search

# 需要导入模块: from models.private_key import PrivateKey [as 别名]
# 或者: from models.private_key.PrivateKey import get_api [as 别名]
    def _query_search(self, query, page):
        """Call the Custom Search API with the given query and get the given
        page of results.

        Return a tuple. The first element is the list of search results for the
        requested page. Each result is a map that can be passed to the search
        result template. The second element is the total count of search
        results. The count will always be the total count of all results
        starting from the beginning, regardless of the page being requested.

        For each search result, this looks up the actual package in the data
        store and returns its live metadata. If the URL cannot be parsed or
        the package cannot be found in the datastore, it is not included in the
        results.

        Arguments:
          query: The search query to perform.
          page: The page of results to return. If out of bounds, returns an
            empty collection of results.
        """
        global _search_service

        if page < 1 or page > MAX_RESULTS / RESULTS_PER_PAGE:
            handlers.http_error(400, "Page \"%d\" is out of bounds." % page)

        start = (page - 1) * RESULTS_PER_PAGE + 1

        results = []
        if _mock_resource:
            resource = _mock_resource
        else:
            if not _search_service:
                _search_service = build("customsearch", "v1",
                                        developerKey=PrivateKey.get_api())
            resource = _search_service.cse().list(q=query, cx=CUSTOM_SEARCH_ID,
                num=RESULTS_PER_PAGE, start=start).execute()

        if "items" in resource:
            for item in resource["items"]:
                result = self._get_result(item)
                if result: results.append(result)

        count = int(resource["searchInformation"]["totalResults"])
        return results, count
开发者ID:a14n,项目名称:pub-dartlang,代码行数:46,代码来源:search.py

示例3: requires_api_key

# 需要导入模块: from models.private_key import PrivateKey [as 别名]
# 或者: from models.private_key.PrivateKey import get_api [as 别名]
def requires_api_key(fn, *args, **kwargs):
    """A decorator for actions that require a Google API key to be set."""
    if PrivateKey.get_api() is None:
        http_error(500, 'No private Google API key set.')
    return fn(*args, **kwargs)
开发者ID:dart-lang,项目名称:pub-dartlang,代码行数:7,代码来源:__init__.py


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