本文整理汇总了Python中election.Election.reset_key方法的典型用法代码示例。如果您正苦于以下问题:Python Election.reset_key方法的具体用法?Python Election.reset_key怎么用?Python Election.reset_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类election.Election
的用法示例。
在下文中一共展示了Election.reset_key方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from election import Election [as 别名]
# 或者: from election.Election import reset_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):
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from election import Election [as 别名]
# 或者: from election.Election import reset_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)
#.........这里部分代码省略.........
示例3: __init__
# 需要导入模块: from election import Election [as 别名]
# 或者: from election.Election import reset_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)