本文整理汇总了Python中index.Index.add_data方法的典型用法代码示例。如果您正苦于以下问题:Python Index.add_data方法的具体用法?Python Index.add_data怎么用?Python Index.add_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类index.Index
的用法示例。
在下文中一共展示了Index.add_data方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from index import Index [as 别名]
# 或者: from index.Index import add_data [as 别名]
class imap:
commands = {
"help" : "for help :)",
"exit" : "To exit ;)",
"add_account" : "...",
"list_account" : "...",
"del_account" : "...",
"stat" : "...",
"list" : "...",
"show" : "...",
"save" : "...",
"delete" : "...",
}
def __init__(self):
self.db = Index()
self.get_mdp()
def help(self):
for i in self.commands:
print(i,":",self.commands[i])
def get_mdp(self):
if os.path.exists(config.keypath) is False:
self.mdp = sha256(getpass("Global Password : ").encode()).digest()
hash = sha512(self.mdp).digest()
with open(config.keypath,'wb') as f:
f.write(hash)
else:
self.mdp = sha256(getpass().encode()).digest()
with open(config.keypath, 'rb') as f:
hash = f.read()
if hash != sha512(self.mdp).digest():
raise Exception("[!] Bad password !")
def change_mdp(self):
pass
def loop(self):
while True:
try:
buffer = input('\n> ')
if buffer == "exit":
return
elif buffer in self.commands:
eval("self.%s()" % buffer)
else:
print("Command not found")
except Exception as e:
print(e)
def list_account(self):
accounts = self.db.get_all()
print("Accounts : ")
if accounts == []:
print(">> None")
else:
for i in accounts:
id = i[0]
name = i[1]
host = i[2]
port = int(i[3])
login = i[4]
print("%s) %s : %[email protected]%s:%d" % (id, name, login, host, port))
def get_account(self, num):
account = self.db.get_data_by_id(num)
id = account[0]
name = account[1]
host = account[2]
port = int(account[3])
login = account[4]
pwd = b64decode(account[5].encode())
iv = pwd[:16]
pwd = pwd[16:]
ctx = serpent_cbc(self.mdp, iv)
pwd = ctx.decrypt(pwd)
pwdlen = unpack('H', pwd[:2])[0]
pwd = pwd[2:2+pwdlen].decode()
return {"id":id, "name":name, "host":host, "port":port, "login":login, "pwd":pwd}
def add_account(self):
name = input("Account name : ")
host = input("Host : ")
port = int(input("Port : "))
login = input("Login : ")
iv = os.urandom(16)
ctx = serpent_cbc(self.mdp, iv)
mdp = getpass().encode()
pwd = ctx.encrypt(pack('H', len(mdp))+mdp)
pwd = iv+pwd
self.db.add_data(name, host, port, login, pwd)
print("[+] Account add.")
def del_account(self):
id = int(input('id : '))
self.db.rm_data(id)
print("[+] Account deleted.")
def stat(self):
#.........这里部分代码省略.........