本文整理汇总了Python中globaleaks.utils.token.Token.serialize_token方法的典型用法代码示例。如果您正苦于以下问题:Python Token.serialize_token方法的具体用法?Python Token.serialize_token怎么用?Python Token.serialize_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类globaleaks.utils.token.Token
的用法示例。
在下文中一共展示了Token.serialize_token方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from globaleaks.utils.token import Token [as 别名]
# 或者: from globaleaks.utils.token.Token import serialize_token [as 别名]
def post(self):
"""
Request: SubmissionDesc
Response: SubmissionDesc
Errors: ContextIdNotFound, InvalidInputFormat, SubmissionFailFields
This creates an empty submission for the requested context,
and returns submissionStatus with empty fields and a Submission Unique String,
This is the unique token used during the submission procedure.
header session_id is used as authentication secret for the next interaction.
expire after the time set by Admin (Context dependent setting)
--- has to became:
Request: empty
Response: SubmissionDesc + Token
Errors: None
This create a Token, require to complete the submission later
"""
request = self.validate_message(self.request.body, requests.SubmissionDesc)
token = Token('submission', request['context_id'])
token.set_difficulty(Alarm().get_token_difficulty())
token_answer = token.serialize_token()
token_answer.update({'id': token_answer['token_id']})
token_answer.update({'context_id': request['context_id']})
token_answer.update({'human_captcha_answer': 0})
self.set_status(201) # Created
self.finish(token_answer)
示例2: post
# 需要导入模块: from globaleaks.utils.token import Token [as 别名]
# 或者: from globaleaks.utils.token.Token import serialize_token [as 别名]
def post(self):
"""
Request: None
Response: SubmissionDesc (Token)
Errors: ContextIdNotFound, InvalidInputFormat, SubmissionValidationFailure
This API create a Token, a temporary memory only object able to keep
track of the submission. If the system is under stress, complete the
submission will require some actions to be performed before the
submission can be concluded (e.g. hashcash and captchas).
"""
if not GLSettings.memory_copy.accept_submissions:
raise errors.SubmissionDisabled
request = self.validate_message(self.request.body, requests.SubmissionDesc)
token = Token('submission', request['context_id'])
token.set_difficulty(Alarm().get_token_difficulty())
token_answer = token.serialize_token()
token_answer.update({'id': token_answer['token_id']})
token_answer.update({'context_id': request['context_id']})
token_answer.update({'receivers': []})
token_answer.update({'answers': {}})
token_answer.update({'human_captcha_answer': 0})
token_answer.update({'graph_captcha_answer': ""})
token_answer.update({'proof_of_work': 0})
self.set_status(201) # Created
self.finish(token_answer)
示例3: test_token_obj_zero_stress
# 需要导入模块: from globaleaks.utils.token import Token [as 别名]
# 或者: from globaleaks.utils.token.Token import serialize_token [as 别名]
def test_token_obj_zero_stress(self):
# This is at the beginning
anomaly.EventTrackQueue.reset()
# Token submission
st = Token('submission', context_id="ignored")
st.set_difficulty(TestToken.shared_alarm_obj.get_token_difficulty())
for indicator in TestToken.stress_indicator:
self.assertFalse(getattr(st, indicator), indicator)
st_dict = st.serialize_token()
self.assertEqual(st_dict['remaining_allowed_attempts'], Token.MAXIMUM_ATTEMPTS_PER_TOKEN)
示例4: test_token_obj_level1_stress
# 需要导入模块: from globaleaks.utils.token import Token [as 别名]
# 或者: from globaleaks.utils.token.Token import serialize_token [as 别名]
def test_token_obj_level1_stress(self):
mock_high_difficulty = {"human_captcha": True, "graph_captcha": True, "proof_of_work": True}
# Token submission
st = Token("submission", context_id="ignored")
st.set_difficulty(mock_high_difficulty)
st_dict = st.serialize_token()
if st.graph_captcha:
self.assertTrue(st.graph_captcha.has_key("answer"))
self.assertTrue(isinstance(st.graph_captcha["answer"], list))
if st.human_captcha:
self.assertTrue(st.human_captcha.has_key("answer"))
self.assertTrue(isinstance(st.human_captcha["answer"], unicode))
self.assertEqual(st_dict["remaining_allowed_attempts"], Token.MAXIMUM_ATTEMPTS_PER_TOKEN)
示例5: test_token_obj_level1_stress
# 需要导入模块: from globaleaks.utils.token import Token [as 别名]
# 或者: from globaleaks.utils.token.Token import serialize_token [as 别名]
def test_token_obj_level1_stress(self):
mock_high_difficulty = {
'human_captcha': True,
'graph_captcha': True,
'proof_of_work': True,
}
# Token submission
st = Token('submission', context_id='ignored')
st.set_difficulty(mock_high_difficulty)
st_dict = st.serialize_token()
if st.graph_captcha:
self.assertTrue(st.graph_captcha.has_key('answer'))
self.assertTrue(isinstance(st.graph_captcha['answer'], list))
if st.human_captcha:
self.assertTrue(st.human_captcha.has_key('answer'))
self.assertTrue(isinstance(st.human_captcha['answer'], unicode))
self.assertEqual(st_dict['remaining_allowed_attempts'], Token.MAXIMUM_ATTEMPTS_PER_TOKEN)