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 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
class QDataStreamWrite(unittest.TestCase): '''Test case for QDatastream write* functions''' def setUp(self): self.ba = QByteArray() self.read = QDataStream(self.ba, QIODevice.ReadOnly) self.write = QDataStream(self.ba, QIODevice.WriteOnly) def testWriteUInt8(self): '''QDataStream.writeUInt8 (accepting str of size 1)''' x = 0xFF self.write.writeUInt8(x) y = self.read.readUInt8() self.assertEqual(x, y) self.assertRaises(TypeError, self.write.writeUInt8, 'aaaaa') def testWriteInt8(self): '''QDataStream.writeInt8 (accepting str of size 1)''' x = 65 self.write.writeInt8(chr(x)) y = self.read.readInt8() self.assertEqual(x, y) self.assertRaises(TypeError, self.write.writeInt8, 'aaaaa') def testWriteUInt8Int(self): '''QDataStream.writeUInt8 (accepting integer)''' x = 0xFF self.write.writeUInt8(x) y = self.read.readUInt8() self.assertEqual(x, y) def testWriteInt8Int(self): '''QDataStream.writeInt8 (accepting integer)''' x = 65 self.write.writeInt8(x) y = self.read.readInt8() self.assertEqual(x, y) def testWriteUInt16(self): '''QDataStream.writeUInt16''' x = 0x4423 self.write.writeUInt16(x) y = int(self.read.readUInt16()) self.assertEqual(x, y) def testWriteUInt32(self): '''QDataStream.writeUInt32''' x = 0xdeadbeef self.write.writeUInt32(x) y = int(self.read.readUInt32()) self.assertEqual(x, y)
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 !")