This repository was archived by the owner on Jan 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathconfig.py
More file actions
43 lines (36 loc) · 1.4 KB
/
config.py
File metadata and controls
43 lines (36 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
__author__ = 'amir'
import ConfigParser
import hashlib
class Configuration(object):
def __init__(self):
self.config = ConfigParser.ConfigParser()
self.config.read("conf.ini")
def write(self, section, attr, value):
cfgfile = open("conf.ini",'w')
self.config.set(section,attr,value)
self.config.write(cfgfile)
cfgfile.close()
def get(self, section):
dict1 = {}
options = self.config.options(section)
for option in options:
try:
dict1[option] = self.config.get(section, option)
if dict1[option] == -1:
print ("skip: %s" % option)
except:
print("exception on %s!" % option)
dict1[option] = None
return dict1
def boolean(self, section, attr):
return self.config.getboolean(section, attr)
def is_exist(self, category, option):
return self.config.has_option(category, option)
def encrypt(self, data):
obj = AES.new(self.get('Encryption')['Key'], AES.MODE_CBC, self.get('Encryption')['iv'])
return obj.encrypt(data)
def decrypt(self, data):
obj = AES.new(self.get('Encryption')['Key'], AES.MODE_CBC, self.get('Encryption')['iv'])
return obj.decrypt(data)
def hash(self, str):
return hashlib.sha224(str).hexdigest()