def preparePacket(self, action, *args, **kwargs): reply = QByteArray() stream = QDataStream(reply, QIODevice.WriteOnly) stream.setVersion(QDataStream.Qt_4_2) stream.writeUInt32(0) stream.writeQString(action) for arg in args: if type(arg) is LongType: stream.writeQString(str(arg)) elif type(arg) is IntType: stream.writeInt(arg) elif isinstance(arg, basestring): stream.writeQString(arg) elif type(arg) is StringType: stream.writeQString(arg) elif type(arg) is FloatType: stream.writeFloat(arg) elif type(arg) is ListType: stream.writeQString(str(arg)) stream.device().seek(0) stream.writeUInt32(reply.size() - 4) return reply
def readDatas(self): if self.socket is not None: if self.socket.isValid(): ins = QDataStream(self.socket) ins.setVersion(QDataStream.Qt_4_2) loop = 0 while not ins.atEnd(): QCoreApplication.processEvents() loop += 1 if loop > 1000: break if self.socket is not None: if self.socket.isValid(): if self.blockSize == 0: if self.socket.isValid(): if self.socket.bytesAvailable() < 4: return self.blockSize = ins.readUInt32() else: return if self.socket.isValid(): if self.socket.bytesAvailable() < self.blockSize: bytesReceived = str(self.socket.bytesAvailable()) return bytesReceived = str(self.socket.bytesAvailable()) else: return action = ins.readQString() self.handleAction(action, ins) self.blockSize = 0 else: return else: return return
def preparePacket(self, action, *args, **kwargs) : reply = QByteArray() stream = QDataStream(reply, QIODevice.WriteOnly) stream.setVersion(QDataStream.Qt_4_2) stream.writeUInt32(0) stream.writeQString(action) for arg in args : if type(arg) is LongType : stream.writeQString(str(arg)) elif type(arg) is IntType: stream.writeInt(arg) elif isinstance(arg, basestring): stream.writeQString(arg) elif type(arg) is StringType : stream.writeQString(arg) elif type(arg) is FloatType: stream.writeFloat(arg) elif type(arg) is ListType: stream.writeQString(str(arg)) stream.device().seek(0) stream.writeUInt32(reply.size() - 4) return reply
def readDatas(self): if self.socket != None : if self.socket.isValid() : ins = QDataStream(self.socket) ins.setVersion(QDataStream.Qt_4_2) loop = 0 while ins.atEnd() == False : QCoreApplication.processEvents() loop = loop + 1 if self.socket != None : if self.socket.isValid() : if self.blockSize == 0: if self.socket.isValid() : if self.socket.bytesAvailable() < 4: return self.blockSize = ins.readUInt32() else : return if self.socket.isValid() : if self.socket.bytesAvailable() < self.blockSize: bytesReceived = str(self.socket.bytesAvailable()) return bytesReceived = str(self.socket.bytesAvailable()) else : return action = ins.readQString() self.handleAction(action, ins) self.blockSize = 0 else : return else : return return
def sendReply(self, action, *args, **kwargs): try: if hasattr(self, "socket"): reply = QByteArray() stream = QDataStream(reply, QIODevice.WriteOnly) stream.setVersion(QDataStream.Qt_4_2) stream.writeUInt32(0) stream.writeQString(action) for arg in args: if isinstance(arg, int): stream.writeInt(int(arg)) elif isinstance(arg, str): stream.writeQString(arg) elif isinstance(arg, list): stream.writeQString(str(arg)) #stream << action << options stream.device().seek(0) stream.writeUInt32(reply.size() - 4) self.socket.write(reply) # else : # # no socket !? # self.quit() except: self.log.exception("Something awful happened when sending reply !")
def sendReply(self, action, *args, **kwargs): try: if hasattr(self, "socket"): reply = QByteArray() stream = QDataStream(reply, QIODevice.WriteOnly) stream.setVersion(QDataStream.Qt_4_2) stream.writeUInt32(0) stream.writeQString(action) for arg in args: if type(arg) is LongType: stream.writeQString(str(arg)) if type(arg) is IntType: stream.writeInt(int(arg)) elif type(arg) is StringType: stream.writeQString(arg) elif isinstance(arg, basestring): stream.writeQString(arg) elif type(arg) is FloatType: stream.writeFloat(arg) elif type(arg) is ListType: stream.writeQString(str(arg)) elif type(arg) is QFile: arg.open(QIODevice.ReadOnly) fileDatas = QByteArray(arg.readAll()) stream.writeInt32(fileDatas.size()) stream.writeRawData(fileDatas.data()) arg.close() # stream << action << options stream.device().seek(0) stream.writeUInt32(reply.size() - 4) self.socket.write(reply) # else : # # no socket !? # self.quit() except: self.log.exception("Something awful happened when sending reply !")
def sendReply(self, action, *args, **kwargs): try: if hasattr(self, "socket"): reply = QByteArray() stream = QDataStream(reply, QIODevice.WriteOnly) stream.setVersion(QDataStream.Qt_4_2) stream.writeUInt32(0) stream.writeQString(action) for arg in args: if type(arg) is LongType: stream.writeQString(str(arg)) if type(arg) is IntType: stream.writeInt(int(arg)) elif type(arg) is StringType: stream.writeQString(arg) elif isinstance(arg, basestring): stream.writeQString(arg) elif type(arg) is FloatType: stream.writeFloat(arg) elif type(arg) is ListType: stream.writeQString(str(arg)) elif type(arg) is QFile: arg.open(QIODevice.ReadOnly) fileDatas = QByteArray(arg.readAll()) stream.writeInt32(fileDatas.size()) stream.writeRawData(fileDatas.data()) arg.close() #stream << action << options stream.device().seek(0) stream.writeUInt32(reply.size() - 4) self.socket.write(reply) # else : # # no socket !? # self.quit() except: self.log.exception("Something awful happened when sending reply !")
def readDatas(self): try: self.log.debug("receiving data") if self.socket.bytesAvailable() == 0: return ins = QDataStream(self.socket) ins.setVersion(QDataStream.Qt_4_2) while ins.atEnd() == False: if self.blockSize == 0: if self.socket.bytesAvailable() < 4: return self.blockSize = ins.readUInt32() if self.socket.bytesAvailable() < self.blockSize: return action = ins.readQString() self.log.info(action) self.handleAction(action, ins) self.blockSize = 0 except: self.log.exception("Something awful happened in a gw thread !")
def readDatas(self): try : self.log.debug("receiving data") if self.socket.bytesAvailable() == 0 : return ins = QDataStream(self.socket) ins.setVersion(QDataStream.Qt_4_2) while ins.atEnd() == False : if self.blockSize == 0: if self.socket.bytesAvailable() < 4: return self.blockSize = ins.readUInt32() if self.socket.bytesAvailable() < self.blockSize: return action = ins.readQString() self.log.info(action) self.handleAction(action, ins) self.blockSize = 0 except : self.log.exception("Something awful happened in a gw thread !")
def sendReply(self, action, *args, **kwargs) : if self in self.parent.recorders : reply = QByteArray() stream = QDataStream(reply, QIODevice.WriteOnly) stream.setVersion(QDataStream.Qt_4_2) stream.writeUInt32(0) stream.writeQString(action) for arg in args : if type(arg) is LongType : stream.writeQString(str(arg)) elif type(arg) is IntType: stream.writeInt(arg) elif isinstance(arg, basestring): stream.writeQString(arg) elif type(arg) is StringType : stream.writeQString(arg) elif type(arg) is FloatType: stream.writeFloat(arg) elif type(arg) is ListType: stream.writeQString(str(arg)) stream.device().seek(0) stream.writeUInt32(reply.size() - 4) if self.socket.isValid() and self.socket.state() == 3 : if self.socket.write(reply) == -1 : self.log.debug("error socket write") self.socket.abort() else : self.log.debug("send reply - incorrect socket to write") self.socket.abort()
def sendReply(self, action, *args, **kwargs): if self in self.parent.recorders: reply = QByteArray() stream = QDataStream(reply, QIODevice.WriteOnly) stream.setVersion(QDataStream.Qt_4_2) stream.writeUInt32(0) stream.writeQString(action) for arg in args: if type(arg) is LongType: stream.writeQString(str(arg)) elif type(arg) is IntType: stream.writeInt(arg) elif isinstance(arg, basestring): stream.writeQString(arg) elif type(arg) is StringType: stream.writeQString(arg) elif type(arg) is FloatType: stream.writeFloat(arg) elif type(arg) is ListType: stream.writeQString(str(arg)) stream.device().seek(0) stream.writeUInt32(reply.size() - 4) if self.socket.isValid() and self.socket.state() == 3: if self.socket.write(reply) == -1: self.log.debug("error socket write") self.socket.abort() else: self.log.debug("send reply - incorrect socket to write") self.socket.abort()