本文整理汇总了Python中election.Election.ensure_key方法的典型用法代码示例。如果您正苦于以下问题:Python Election.ensure_key方法的具体用法?Python Election.ensure_key怎么用?Python Election.ensure_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类election.Election
的用法示例。
在下文中一共展示了Election.ensure_key方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from election import Election [as 别名]
# 或者: from election.Election import ensure_key [as 别名]
class SessionContext:
def __init__(self, sessid):
if not sessid:
raise ValueError("Missing sessid")
self.__key = [evcommon.IDSPOOL, sessid]
self.__reg = Election().get_root_reg()
def store_session(self, cert):
self.__reg.ensure_key(self.__key)
self.__reg.create_value(self.__key, "cert", cert)
self.__reg.create_integer_value(self.__key, "start", int(time.time()))
def check_session(self, cert):
if not self.__reg.check(self.__key):
return evcommon.EVOTE_ERROR, evmessage.EV_ERRORS.SEANSS_PUUDUB
start = self.__reg.read_integer_value(self.__key, "start").value
length = Election().get_session_length() * 60
if start + length < int(time.time()):
return evcommon.EVOTE_ERROR, evmessage.EV_ERRORS.SEANSS_PUUDUB
if self.__reg.read_value(self.__key, "cert").value != cert:
evlog.log_error('Sertifikaat muutus')
return evcommon.EVOTE_CERT_ERROR, evmessage.EV_ERRORS.TEHNILINE_VIGA
return evcommon.EVOTE_OK, None
def kill(self):
self.__reg.ensure_no_key(self.__key)
示例2: main_function
# 需要导入模块: from election import Election [as 别名]
# 或者: from election.Election import ensure_key [as 别名]
def main_function():
if len(sys.argv) != 3:
usage()
el_id = sys.argv[1]
_if = sys.argv[2]
if not check_file(_if):
print "Faili " + _if + " ei eksisteeri"
sys.exit(1)
if not ksum.has(_if):
print "Faili " + ksum.filename(_if) + " ei eksisteeri"
sys.exit(1)
if not ksum.check(_if):
print "Kontrollsumma ei klapi"
sys.exit(1)
reg = Election().get_sub_reg(el_id)
reg.ensure_key(['hlr', 'input'])
dst = reg.path(['hlr', 'input', 'votes'])
os.system("cp " + _if + " " + dst)
os.system("cp " + ksum.filename(_if) + " " + ksum.filename(dst))
Election().config_hlr_input_elid_done(el_id)
示例3: main_function
# 需要导入模块: from election import Election [as 别名]
# 或者: from election.Election import ensure_key [as 别名]
def main_function():
if len(sys.argv) != 3:
usage()
el_id = sys.argv[1]
_if = sys.argv[2]
if not ksum.check(_if, True):
print "Kontrollsumma ei klapi"
sys.exit(1)
reg = Election().get_sub_reg(el_id)
reg.ensure_key(['hlr', 'input'])
dst = reg.path(['hlr', 'input', 'votes'])
shutil.copy(_if, dst)
ksum.store(dst)
Election().config_hlr_input_elid_done(el_id)
示例4: issue_vote_id
# 需要导入模块: from election import Election [as 别名]
# 或者: from election.Election import ensure_key [as 别名]
def issue_vote_id(self):
vote_id = self.__create_vote_key()
rreg = Election().get_root_reg()
key = htscommon.get_verification_key(vote_id)
rreg.create_string_value(key, "voter", self.signercode)
rreg.create_integer_value(key, "timestamp", int(time.time()))
rreg.create_integer_value(key, "count", \
Election().get_verification_count())
# Store the election IDs and include a backreference in the
# corresponding questions' subregistries.
elids = ""
for elid in [quest[0] for quest in self.questions]:
elids += elid + "\t"
sreg = Election().get_sub_reg(elid)
skey = htscommon.get_user_key(self.signercode)
sreg.ensure_key(skey)
sreg.create_string_value(skey, \
htscommon.VOTE_VERIFICATION_ID_FILENAME, vote_id)
rreg.create_string_value(key, "elids", elids)
return vote_id
示例5: __init__
# 需要导入模块: from election import Election [as 别名]
# 或者: from election.Election import ensure_key [as 别名]
class MobileIDContext:
phoneno = None
lang = None
challenge = None
midsess = None
origvote = None
votefiles = {}
__sessid = None
__reg = None
def __init__(self, sessid):
if sessid == None:
raise Exception('Puuduv sessiooniidentifikaator')
self.__sessid = sessid
self.__reg = Election().get_root_reg()
self.lang = 'EST'
def sessid(self):
return self.__sessid
def kill(self):
self.__reg.ensure_no_key([evcommon.MIDSPOOL, self.__sessid])
def set_phone(self, phone):
self.phoneno = phone
def set_origvote(self, hv):
self.origvote = hv
def get_origvote(self):
self.origvote = self.__reg.read_value(\
[evcommon.MIDSPOOL, self.__sessid], \
'origvote').value
return self.origvote
def add_votefile(self, filename, data):
self.votefiles[filename] = data
def get_votefiles(self):
for key in self.__reg.list_keys([evcommon.MIDSPOOL, self.__sessid, \
'votefiles']):
self.votefiles[key] = self.__reg.read_value(\
[evcommon.MIDSPOOL, self.__sessid, 'votefiles'], key).value
return self.votefiles
def generate_challenge(self):
self.challenge = binascii.b2a_hex(os.urandom(10))
def verify_challenge(self, signature):
return challenge_ok(self.certificate(), self.mychallenge(), \
self.ourchallenge(), signature)
def mychallenge(self):
return self.__reg.read_value(\
[evcommon.MIDSPOOL, self.__sessid], \
'mychallenge').value
def ourchallenge(self):
return self.__reg.read_value(\
[evcommon.MIDSPOOL, self.__sessid], \
'ourchallenge').value
def certificate(self):
return self.__reg.read_value(\
[evcommon.MIDSPOOL, self.__sessid], \
'cert').value
def set_auth_succ(self):
self.__reg.ensure_key([evcommon.MIDSPOOL, self.__sessid, 'authsucc'])
def auth_succ(self):
return self.__reg.check(\
[evcommon.MIDSPOOL, self.__sessid, 'authsucc'])
def save_post_auth(self, rsp):
self.__reg.reset_key([evcommon.MIDSPOOL, self.__sessid])
self.__reg.create_value([evcommon.MIDSPOOL, self.__sessid], \
'cert', rsp._CertificateData)
self.__reg.create_value([evcommon.MIDSPOOL, self.__sessid], \
'phone', self.phoneno)
self.__reg.create_value([evcommon.MIDSPOOL, self.__sessid], \
'midsess', rsp._Sesscode)
self.__reg.create_value([evcommon.MIDSPOOL, self.__sessid], \
'mychallenge', self.challenge)
self.__reg.create_value([evcommon.MIDSPOOL, self.__sessid], \
'ourchallenge', rsp._Challenge)
def load_pre_sign(self):
self.phoneno = self.__reg.read_value(\
[evcommon.MIDSPOOL, self.__sessid], 'phone').value
def save_post_sign(self, midsess):
self.__reg.create_value([evcommon.MIDSPOOL, self.__sessid], \
'midsess', midsess)
#.........这里部分代码省略.........
示例6: __init__
# 需要导入模块: from election import Election [as 别名]
# 或者: from election.Election import ensure_key [as 别名]
class Rights:
def __init__(self, elid):
self.reg = Election().get_sub_reg(elid, ['common', 'rights'])
def descr(self, code):
"""
Tagastab tegelase kohta käiva kirjelduse
"""
if not formatutil.is_isikukood(code):
raise Exception('Vigane isikukood')
if self.reg.check([code, 'description']):
return self.reg.read_string_value([code], 'description').value
else:
return 'Andmed puuduvad'
def listall(self):
"""
Tagastab kõik volitused
"""
lst = self.reg.list_keys()
ret = ''
for ele in lst:
ret = ret + '\n' + self.listuser(ele)
return ret.strip()
def _create_user(self, code):
""" Loome kasutaja, kui teda veel pole
"""
if not formatutil.is_isikukood(code):
raise Exception('Vigane isikukood')
self.reg.ensure_key([code, 'rights'])
def add(self, code, right):
"""
Lisab uue volituse
"""
new_right = right.upper()
if not _proper_right(new_right):
raise Exception('Vigane volitus')
self._create_user(code)
if not self.has(code, new_right):
self.reg.create_value([code, 'rights'], new_right, '')
return True
return False
def adddesc(self, code, desc):
"""
Lisab kasutajale kirjelduse
"""
self._create_user(code)
self.reg.create_value([code], 'description', desc)
return True
def remove(self, code, right):
"""
Võtab kasutajalt volituse
"""
if not formatutil.is_isikukood(code):
raise Exception('Vigane isikukood')
new_right = right.upper()
if not _proper_right(new_right):
raise Exception('Vigane volitus')
if self.has(code, new_right):
self.reg.delete_value([code, 'rights'], new_right)
return True
return False
def remuser(self, code):
"""
Eemaldab ühe kasutaja volituste failist
"""
if not formatutil.is_isikukood(code):
raise Exception('Vigane isikukood')
return self.reg.ensure_no_key([code])
def remall(self):
"""
Eemaldab kõik volitused
"""
self.reg.reset_key([''])
return True
def has(self, code, right):
"""
Kas koodil on vastav volitus
"""
if not formatutil.is_isikukood(code):
#.........这里部分代码省略.........
示例7: __init__
# 需要导入模块: from election import Election [as 别名]
# 或者: from election.Election import ensure_key [as 别名]
class MobileIDContext:
phoneno = None
lang = None
challenge = None
midsess = None
origvote = None
votefiles = {}
__sessid = None
__reg = None
def __init__(self, sessid):
if sessid is None:
raise Exception("Puuduv sessiooniidentifikaator")
self.__sessid = sessid
self.__reg = Election().get_root_reg()
self.lang = "EST"
def sessid(self):
return self.__sessid
def kill(self):
self.__reg.ensure_no_key([evcommon.MIDSPOOL, self.__sessid])
def set_phone(self, phone):
self.phoneno = phone
def set_origvote(self, hv):
self.origvote = hv
def get_origvote(self):
self.origvote = self.__reg.read_value([evcommon.MIDSPOOL, self.__sessid], "origvote").value
return self.origvote
def add_votefile(self, filename, data):
self.votefiles[filename] = data
def get_votefiles(self):
for key in self.__reg.list_keys([evcommon.MIDSPOOL, self.__sessid, "votefiles"]):
self.votefiles[key] = self.__reg.read_value([evcommon.MIDSPOOL, self.__sessid, "votefiles"], key).value
return self.votefiles
def generate_challenge(self):
self.challenge = binascii.b2a_hex(os.urandom(10))
def verify_challenge(self, signature):
return challenge_ok(self.certificate(), self.mychallenge(), self.ourchallenge(), signature)
def mychallenge(self):
return self.__reg.read_value([evcommon.MIDSPOOL, self.__sessid], "mychallenge").value
def ourchallenge(self):
return self.__reg.read_value([evcommon.MIDSPOOL, self.__sessid], "ourchallenge").value
def certificate(self):
return self.__reg.read_value([evcommon.MIDSPOOL, self.__sessid], "cert").value
def set_auth_succ(self):
self.__reg.ensure_key([evcommon.MIDSPOOL, self.__sessid, "authsucc"])
def auth_succ(self):
return self.__reg.check([evcommon.MIDSPOOL, self.__sessid, "authsucc"])
def check_session(self):
if not self.__reg.check([evcommon.MIDSPOOL, self.__sessid]):
return False
start = self.__reg.read_integer_value([evcommon.MIDSPOOL, self.__sessid], "start").value
length = Election().get_session_length() * 60
return start + length >= int(time.time()) and self.auth_succ()
def save_post_auth(self, rsp):
self.__reg.reset_key([evcommon.MIDSPOOL, self.__sessid])
self.__reg.create_value([evcommon.MIDSPOOL, self.__sessid], "cert", rsp._CertificateData)
self.__reg.create_value([evcommon.MIDSPOOL, self.__sessid], "phone", self.phoneno)
self.__reg.create_value([evcommon.MIDSPOOL, self.__sessid], "midsess", rsp._Sesscode)
self.__reg.create_value([evcommon.MIDSPOOL, self.__sessid], "mychallenge", self.challenge)
self.__reg.create_value([evcommon.MIDSPOOL, self.__sessid], "ourchallenge", rsp._Challenge)
self.__reg.create_integer_value([evcommon.MIDSPOOL, self.__sessid], "start", int(time.time()))
def load_pre_sign(self):
self.phoneno = self.__reg.read_value([evcommon.MIDSPOOL, self.__sessid], "phone").value
def save_post_sign(self, midsess):
self.__reg.create_value([evcommon.MIDSPOOL, self.__sessid], "midsess", midsess)
self.__reg.create_value([evcommon.MIDSPOOL, self.__sessid], "origvote", self.origvote)
self.__reg.ensure_key([evcommon.MIDSPOOL, self.__sessid, "votefiles"])
for el in self.votefiles:
self.__reg.create_value([evcommon.MIDSPOOL, self.__sessid, "votefiles"], el, self.votefiles[el])
def load_pre_poll(self):
self.midsess = int(self.__reg.read_value([evcommon.MIDSPOOL, self.__sessid], "midsess").value)