本文整理汇总了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)