示例#1
0
 def get_record(self, ip):
     ret_record = None
     for record in self.__config__:
         if record['ip'] == ip:
             crypto = pwd_crypt()
             password = crypto.decrypt(record['password'])
             ret_record = copy(record)
             ret_record['password'] = password
     return ret_record
示例#2
0
 def __next__(self):
     if self.__config__ == None:
         raise StopIteration
     elif self.__current__ < len(self.__config__):
         cur_record = copy(self.__config__[self.__current__])
         self.__current__ += 1
         crypto = pwd_crypt()
         password = crypto.decrypt(cur_record['password'])
         cur_record['password'] = password
         return cur_record
     else:
         raise StopIteration
示例#3
0
 def add_record(self, ip, port, user, password):
     # 先查找是否有对应的ip,如果有的话则不做任何处理
     for record in self.__config__:
         if record['ip'] == ip:
             return
     crypto = pwd_crypt()
     obj = {
         "ip": ip,
         "port": port,
         "user": user,
         "password": crypto.encrypt(password)
     }
     self.__config__.append(obj)
     self.__sync__()
示例#4
0
 def add_record(self, ip, port, user, password, name=None):
     # 先查找是否有对应的ip,如果有的话则不做任何处理
     if self._get_writable_record(ip) != None:
         return
     crypto = pwd_crypt()
     obj = {
         "ip": ip,
         "port": port,
         "user": user,
         "password": crypto.encrypt(password)
     }
     if name != None:
         obj['name'] = name
     self._config.append(obj)
     self._sync()
示例#5
0
 def read(self, key):
     obj = self._config[key]
     encrypto = pwd_crypt()
     if obj['type'] == 'string':
         return str(encrypto.decrypt(obj['value']))
     elif obj['type'] == 'float':
         return float(encrypto.decrypt(obj['value']))
     elif obj['type'] == 'int':
         return int(encrypto.decrypt(obj['value']))
     elif obj['type'] == 'bool':
         real_value = encrypto.decrypt(obj['value'])
         if 'True' == real_value:
             return True
         elif 'False' == real_value:
             return False
     elif obj['type'] == 'long':
         return long(encrypto.decrypt(obj['value']))
示例#6
0
    def modify_record(self, ip, port=None, user=None, password=None):
        # 检查是否有对应的ip,如果没有则抛出错误
        if password != None:
            crypto = pwd_crypt()
            password = crypto.encrypt(password)
        a_record = 0
        for record in self.__config__:
            if record['ip'] == ip:
                # 找到了对应的记录
                a_record = 1
                for key in record:
                    # 如果记录中的这个参数在上下文中并且数据不是None, 则把与参数同名的上下文变量的值赋值给参数
                    if key in locals() and locals()[key] != None:
                        record[key] = locals()[key]
                self.__sync__()
                return

        if a_record == 0:
            raise self.ErrorNotFind
示例#7
0
 def write(self, key, value):
     obj = {}
     if type(value) == type('1.2'):
         # string
         obj['type'] = 'string'
     elif type(value) == type(1.2):
         # float
         obj['type'] = 'float'
     elif type(value) == type(1):
         # int
         obj['type'] = 'int'
     elif type(value) == type(True):
         # bool
         obj['type'] = 'bool'
     else:
         raise self.ErrorTypeNotSupport
     encrypto = pwd_crypt()
     obj['value'] = encrypto.encrypt(str(value))
     self._config[key] = obj
     self._sync_file()