本文整理匯總了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')
示例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
示例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)