def recv_file(self, data, start, end): sdata = '__-*&-@->@n!~_' edata = '^%&@' fName = ms.find_mid_text(data, sdata, edata) edata = '__@' fse = ms.find_mid_text(data, fName + '^%&@', edata) if (fse == 'f'): ft = self.recv_file_f(data, end) self.files[fName] = ft[1] self.filef[fName] = ft[0] if self.function1 is not None: self.frame[fName] = self.function1(self.container, fName) elif fse == 's': ftfs = self.filef[fName] ft = self.recv_file_s(ftfs, data, end, fName) self.filef[fName] = ft if self.function2 is not None: self.function2(self.frame[fName], self.flsize[fName] + length, self.files[fName]) else: self.alert_message(fName) fil = self.filef[fName] self.recv_file_e(fil, fName) if self.function2 is not None: self.function2(self.frame[fName], self.flsize[fName] + length, self.files[fName], True)
def recv_file_f(self, data, end): #Clear location = self.location t = time.time() t = ms.replaceBy_String(str(t), '.') hinte = '^%&@f__@&*s_' hints = '@->@n!~_' hint = '*&@->' + end size = ms.find_mid_text(data, hinte, hint) fName = ms.find_mid_text(data, hints, hinte) file = location + t + '_' + fName print(file) f = open(file, 'wb') self.file_status[file] = True self.flsize[fName] = 0 size = int(size) mb = self.get_mb(size) if (mb > 5): self.chunk = 1024 * 1024 else: self.chunk = 1024 data = "File :" + fName + " Size :" + str(size) self.alert_message(data) return [f, size]
def fun(): data='' d='' while True: scond=ms.check_word(data,Recv.end) scond=str(scond) if(scond!='False'): if (Recv.start in data): fdata=ms.find_mid_text(data,Recv.start,Recv.end) fdata=dec(fdata) fdata=ad.deAssValue(fdata,start='@!$%~(*&~$',end='%~#*!%$~#@') self.seprateData(fdata) data=ms.get_rhs_data(data,Recv.end) try: d=self.s.recv(self.chunk).decode() except: self.saveAllFiles() if self.errorFunction is not None: if self.errorFunctionArg is not None: self.errorFunction(self.errorFunctionArg) else: self.errorFunction() break cond=ms.check_word(d,Recv.end) scond=str(cond) if scond=='False': data=data+d else: temp=d[:cond] data=data+temp+Recv.end rest=d[cond+len(Recv.end):] if(Recv.start in data): fdata=ms.find_mid_text(data,Recv.start,Recv.end) fdata=dec(fdata) fdata=ad.deAssValue(fdata,start='@!$%~(*&~$',end='%~#*!%$~#@') self.seprateData(fdata) data=rest
def onLBGet(self, data): if True: fdata = ms.find_mid_text(data, Recv.start, Recv.end) fdata = dec(fdata) fdata = ad.deAssValue(fdata, start='@!$%~(*&~$', end='%~#*!%$~#@') self.seprateData(fdata)
def get(self): data='' while True: scond=ms.check_word(data,Recv.end) scond=str(scond) if(scond!='False'): if (Recv.start in data): fdata=ms.find_mid_text(data,Recv.start,Recv.end) fdata=dec(fdata) fdata=ad.deAssValue(fdata) self.seprateData(fdata) data=ms.get_rhs_data(data,Recv.end) try: d=self.s.recv(self.chunk).decode() except: self.saveAllFiles() print("It is Error in connection") self.s.close() cond=ms.check_word(d,Recv.end) scond=str(cond) if scond=='False': data=data+d else: temp=d[:cond] data=data+temp+Recv.end rest=d[cond+len(Recv.end):] if(Recv.start in data): fdata=ms.find_mid_text(data,Recv.start,Recv.end) fdata=dec(fdata) fdata=ad.deAssValue(fdata) self.seprateData(fdata) data=rest
def recv_message(self, msg, start, end): #Clear msg = ms.find_mid_text(msg, start, end) msg = fernet.decrypt(msg.encode()).decode() if msg == '-----': pass else: self.count_mess = self.count_mess + 1 self.tmessage[self.count_mess] = msg
def recv_file_s(self, file, data, end, fName): #Clear startd = '^%&@s__@%*&->' rdata = ms.find_mid_text(data, startd, end) rdata = bytes(rdata, 'utf-8') rdata = fernet.decrypt(rdata) length = len(rdata) self.flsize[fName] = self.flsize[fName] + length file.write(rdata) return file
def recv_file(self, data, start, end): sdata = '__-*&-@->@n!~_' edata = '^%&@' fName = ms.find_mid_text(data, sdata, edata) edata = '__@' fse = ms.find_mid_text(data, fName + '^%&@', edata) if (fse == 'f'): ft = self.recv_file_f(data, end) self.files[fName] = ft[1] self.filef[fName] = ft[0] elif fse == 's': ftfs = self.filef[fName] ft = self.recv_file_s(ftfs, data, end, fName) self.filef[fName] = ft else: self.alert_message(fName) fil = self.filef[fName] self.recv_file_e(fil, fName)
def identify_data(self, data): #Clear start = '<-@-$$##-' end = '-##$$__' try: txt = ms.find_mid_text(data, start, end) except: print('--------------------------------------------------------=') print(data) sys.exit(0) if (txt == 'M'): return 's' else: return 'f'