def loadFile(self,fileName): ''' :param fileName: csv 文件名 :return: 有返回一个 table,没有返回 None ''' reader = csv.reader(KBEngine.open("data/"+fileName,"r+",'UTF-8')) table = [line for line in reader] if len(table) < 3: return None keys = table[0]; types = table[1]; #descs = table[2]; rows = {} for row in table[3:]: row_dic = {} for index, column in enumerate(row): key_str = keys[index] type_str = types[index] row_dic[key_str] = self.convert(type_str,column) rows[int(row[0])] = row_dic self.datas[fileName] = rows return self.datas.get(fileName,None)
def downLoadFile(self, exposed, fileName): """ :param exposed: :param fileName: download file name :return: """ fullFileName = KBEngine.open("data/" + fileName, "r+") self.client.streamFileToClient(fullFileName)
def onRespStaticRes(self, req, resp): filePath = '%s%s' % (self._resPath, req.url if req.url[-1] != '/' else ('%sindex.html' % req.url)) if KBEngine.hasRes(filePath): file = KBEngine.open(filePath, 'rb') resp.body = file.read() file.close() else: resp.body = b'File Not Found...' resp.end()
def onLogWrote(logData): """ KBEngine method. logger写入了一条日志后的回调, 有需要的用户可以在此处把日志写入到其它的地方(如数据库) @param logData: bytes """ path = 'mylog/mylog.log' f = KBEngine.open(path, 'ab') f.write(logData) f.close()
def load_whitelists(): try: import KBEngine import KBEDebug p = './scripts/data/whitelists.txt' if KBEngine.hasRes(p): fs = KBEngine.open(p, 'r') lines = fs.readlines() for line in lines: if line.strip() != '': whitelists.append(int(line.strip())) KBEDebug.DEBUG_MSG("whitelists: {}".format(whitelists)) except: pass
def onLogWrote(logData): """ KBEngine method. logger写入了一条日志后的回调, 有需要的用户可以在此处把日志写入到其它的地方(如数据库) 如果返回False,该条日志将不写入到磁盘文件。 如果返回字符串,该条日志将被替换为所返回的内容。 @param logData: bytes """ path = 'mylog.log' f = KBEngine.open(path, 'ab') f.write(logData) f.close() return True