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 !")