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 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 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 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()