本文整理汇总了Python中amo.utils.Token类的典型用法代码示例。如果您正苦于以下问题:Python Token类的具体用法?Python Token怎么用?Python Token使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Token类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: redirect
def redirect(request, viewer, key):
new = Token(data=[viewer.file.id, key])
new.save()
url = '%s%s?token=%s' % (settings.STATIC_URL,
reverse('files.serve', args=[viewer, key]),
new.token)
return http.HttpResponseRedirect(url)
示例2: redirect
def redirect(request, viewer, key):
new = Token(data=[viewer.file.id, key])
new.save()
url = urljoin(settings.STATIC_URL,
reverse('mkt.files.serve', args=[viewer, key]))
url = urlparams(url, token=new.token)
return http.HttpResponseRedirect(url)
示例3: wrapper
def wrapper(request, file_id, key, *args, **kw):
viewer = FileViewer(get_object_or_404(File, pk=file_id))
token = request.GET.get('token')
if not token:
log.error('Denying access to %s, no token.' % viewer.file.id)
raise PermissionDenied
if not Token.valid(token, [viewer.file.id, key]):
log.error('Denying access to %s, token invalid.' % viewer.file.id)
raise PermissionDenied
return func(request, viewer, key, *args, **kw)
示例4: wrapper
def wrapper(request, file_id, key, *args, **kw):
viewer = FileViewer(get_object_or_404(File, pk=file_id))
token = request.GET.get('token')
if not token:
log.error('Denying access to %s, no token.' % viewer.file.id)
return http.HttpResponseForbidden()
if not Token.valid(token, [viewer.file.id, key]):
log.error('Denying access to %s, token invalid.' % viewer.file.id)
return http.HttpResponseForbidden()
return func(request, viewer, key, *args, **kw)
示例5: wrapper
def wrapper(request, file_id, key, *args, **kw):
viewer = FileViewer(get_object_or_404(File, pk=file_id), is_webapp=kwargs.get("is_webapp", False))
token = request.GET.get("token")
if not token:
log.error("Denying access to %s, no token." % viewer.file.id)
raise PermissionDenied
if not Token.valid(token, [viewer.file.id, key]):
log.error("Denying access to %s, token invalid." % viewer.file.id)
raise PermissionDenied
return func(request, viewer, key, *args, **kw)
示例6: test_token_well_formed
def test_token_well_formed(self):
new = Token("some badly formed token")
assert not new.well_formed()
示例7: test_token_bad_ip_invalid
def test_token_bad_ip_invalid(self):
new = Token(data="127.0.0.1")
new.save()
assert not Token.pop(new.token, "255.255.255.0")
assert Token.pop(new.token, "127.0.0.1")
示例8: test_token_no_ip_invalid
def test_token_no_ip_invalid(self):
new = Token()
assert not Token.valid(new.token, "255.255.255.0")
示例9: test_token_ip
def test_token_ip(self):
new = Token(data="127.0.0.1")
new.save()
assert Token.valid(new.token, "127.0.0.1")
示例10: test_token_fails
def test_token_fails(self):
assert not Token.pop("some-random-token")
示例11: test_token_valid
def test_token_valid(self):
new = Token()
new.save()
assert Token.valid(new.token)
示例12: test_token_pop
def test_token_pop(self):
new = Token()
new.save()
assert Token.pop(new.token)
assert not Token.pop(new.token)