本文整理匯總了Python中models.private_key.PrivateKey.get方法的典型用法代碼示例。如果您正苦於以下問題:Python PrivateKey.get方法的具體用法?Python PrivateKey.get怎麽用?Python PrivateKey.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.private_key.PrivateKey
的用法示例。
在下文中一共展示了PrivateKey.get方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: new
# 需要導入模塊: from models.private_key import PrivateKey [as 別名]
# 或者: from models.private_key.PrivateKey import get [as 別名]
def new(self, package_id, format="html", **kwargs):
"""Retrieve the form for uploading a package version.
If the user isn't logged in, this presents a login screen. If they are
logged in but don't have admin priviliges or don't own the package, this
redirects to /packages/.
This accepts arbitrary keyword arguments to support OAuth.
"""
is_json = format == "json"
user = handlers.get_current_user()
package = handlers.request().maybe_package
if not user:
if is_json:
handlers.http_error(403, "OAuth authentication failed.")
else:
raise cherrypy.HTTPRedirect(users.create_login_url(cherrypy.url()))
elif package and user not in package.uploaders:
message = "You aren't an uploader for package '%s'." % package.name
if is_json:
handlers.http_error(403, message)
else:
handlers.flash(message)
raise cherrypy.HTTPRedirect("/packages/%s" % package.name)
elif not handlers.is_current_user_admin():
message = "Currently only admins may create packages."
if is_json:
handlers.http_error(403, message)
else:
handlers.flash(message)
raise cherrypy.HTTPRedirect("/packages")
elif PrivateKey.get() is None:
if is_json:
handlers.http_error(500, "No private key set.")
else:
raise cherrypy.HTTPRedirect("/admin#tab-private-key")
id = str(uuid4())
redirect_url = handlers.request().url(action="create", id=id)
upload = cloud_storage.Upload(
"tmp/" + id, acl="project-private", size_range=(0, Package.MAX_SIZE), success_redirect=redirect_url
)
# If the package hasn't been validated and moved out of tmp in five
# minutes, delete it. This could happen if the user uploads the package
# to cloud storage, but closes the browser before "create" is run.
deferred.defer(self._remove_tmp_package, id, _countdown=5 * 60)
if is_json:
return upload.to_json()
if package is not None:
title = "Upload a new version of %s" % package.name
else:
title = "Upload a new package"
return handlers.render(
"packages/versions/new", form=upload.to_form(), package=package, layout={"title": title}
)
示例2: new_dartdoc
# 需要導入模塊: from models.private_key import PrivateKey [as 別名]
# 或者: from models.private_key.PrivateKey import get [as 別名]
def new_dartdoc(self, package_id, id, format):
"""Retrieve the form for uploading dartdoc for this package version."""
if PrivateKey.get() is None:
handlers.http_error(500, 'No private key set.')
version = handlers.request().package_version(id)
upload = cloud_storage.Upload(version.dartdoc_storage_path,
acl='public-read',
size_range=(0, Package.MAX_SIZE))
return upload.to_json()
示例3: test_admin_creates_key
# 需要導入模塊: from models.private_key import PrivateKey [as 別名]
# 或者: from models.private_key.PrivateKey import get [as 別名]
def test_admin_creates_key(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['key'] = 'key'
post_response = form.submit()
self.assertEqual(post_response.status_int, 302)
self.assertEqual(post_response.headers['Location'],
'http://localhost:80/admin#tab-private-key')
self.assertEqual(PrivateKey.get(), 'key')
示例4: admin
# 需要導入模塊: from models.private_key import PrivateKey [as 別名]
# 或者: from models.private_key.PrivateKey import get [as 別名]
def admin(self):
"""Retrieve a page for performing administrative tasks."""
if not users.get_current_user():
raise cherrypy.HTTPRedirect(users.create_login_url(cherrypy.url()))
elif not users.is_current_user_admin():
raise handlers.http_error(403)
reload_status = PackageVersion.get_reload_status()
if reload_status is not None:
reload_status['percentage'] = '%d%%' % (
100.0 * reload_status['count'] / reload_status['total'])
return handlers.render('admin',
reload_status=reload_status,
private_key_set=PrivateKey.get() is not None,
production=handlers.is_production(),
layout={'title': 'Admin Console'})
示例5: new
# 需要導入模塊: from models.private_key import PrivateKey [as 別名]
# 或者: from models.private_key.PrivateKey import get [as 別名]
def new(self, package_id, format='json', **kwargs):
"""Retrieve the form for uploading a package version.
This accepts arbitrary keyword arguments to support OAuth.
"""
if PrivateKey.get() is None:
handlers.http_error(500, 'No private key set.')
id = str(uuid4())
redirect_url = handlers.request().url(action="create", id=id)
upload = cloud_storage.Upload("tmp/" + id, acl="project-private",
size_range=(0, Package.MAX_SIZE),
success_redirect=redirect_url)
# If the package hasn't been validated and moved out of tmp in five
# minutes, delete it. This could happen if the user uploads the package
# to cloud storage, but closes the browser before "create" is run.
deferred.defer(self._remove_tmp_package, id, _countdown=5*60)
return upload.to_json()
示例6: requires_private_key
# 需要導入模塊: from models.private_key import PrivateKey [as 別名]
# 或者: from models.private_key.PrivateKey import get [as 別名]
def requires_private_key(fn, *args, **kwargs):
"""A decorator for actions that require a private key to be set."""
if PrivateKey.get() is None: http_error(500, 'No private key set.')
return fn(*args, **kwargs)