Beispiel #1
0
    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
Beispiel #2
0
    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):

        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 !")
Beispiel #6
0
    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()
Beispiel #7
0
    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):
        
        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 !")  
Beispiel #9
0
class QDataStreamShift(unittest.TestCase):
    '''Test case for << and >> operators'''

    def setUp(self):
        self.ba = QByteArray()
        self.stream = QDataStream(self.ba, QIODevice.WriteOnly)
        self.read_stream = QDataStream(self.ba, QIODevice.ReadOnly)

    def testQCharValid(self):
        '''QDataStream <<>> QChar - valid'''
        self.stream.writeQChar(42)

        res = self.read_stream.readQChar()
        self.assertEqual(res, py3k.unichr(42))

    def testQCharNull(self):
        '''QDataStream <<>> QChar - null'''
        self.stream.writeQChar(None)

        res = self.read_stream.readQChar()
        self.assertEqual(res, py3k.unicode_('\x00'))

    def testQByteArrayValid(self):
        '''QDataStream <<>> QByteArray - valid'''
        self.stream << QByteArray("hello")

        res = QByteArray()

        self.read_stream >> res
        self.assertEqual(res, QByteArray("hello"))

    def testQByteArrayEmpty(self):
        '''QDataStream <<>> QByteArray - empty'''
        self.stream << QByteArray("")

        res = QByteArray()

        self.read_stream >> res
        self.assertEqual(res, QByteArray(""))
        self.assertTrue(res.isEmpty())
        self.assertFalse(res.isNull())

    def testQByteArrayNull(self):
        '''QDataStream <<>> QByteArray - null'''
        self.stream << QByteArray()

        res = QByteArray()

        self.read_stream >> res
        self.assertEqual(res, QByteArray())
        self.assertTrue(res.isEmpty())
        self.assertTrue(res.isNull())

    def testQStringValid(self):
        '''QDataStream <<>> QString - valid'''
        self.stream.writeQString('Ka-boom')

        res = self.read_stream.readQString()
        self.assertEqual(res, py3k.unicode_('Ka-boom'))

    def testQStringEmpty(self):
        '''QDataStream <<>> QString - empty'''
        self.stream.writeQString('')

        res = self.read_stream.readQString()
        self.assertEqual(res, py3k.unicode_(''))

    def testQStringNull(self):
        '''QDataStream <<>> QString - null'''
        self.stream.writeQString(None)

        res = self.read_stream.readQString()
        self.assertEqual(res, py3k.unicode_(''))

    def testQBitArrayNull(self):
        '''QDataStream <<>> QBitArray - null'''
        self.stream << QBitArray()

        res = QBitArray()

        self.read_stream >> res
        self.assertEqual(res, QBitArray())

    def testQBitArrayValid(self):
        '''QDataStream <<>> QBitArray - valid'''
        self.stream << create_bitarray('01010101')

        res = QBitArray()

        self.read_stream >> res
        self.assertEqual(res, create_bitarray('01010101'))

    def testQDateNull(self):
        '''QDataStream <<>> QDate - null'''
        self.stream << QDate()

        res = QDate()

        self.read_stream >> res
        self.assertEqual(res, QDate())
        self.assertFalse(res.isValid())
        self.assertTrue(res.isNull())

    def testQDateValid(self):
        '''QDataStream <<>> QDate - valid'''
        self.stream << QDate(2012, 12, 21)

        res = QDate()

        self.read_stream >> res
        self.assertEqual(res, QDate(2012, 12, 21))
        self.assertTrue(res.isValid())
        self.assertFalse(res.isNull())


    def testQTimeNull(self):
        '''QDataStream <<>> QTime - null'''
        self.stream << QTime()

        res = QTime()

        self.read_stream >> res
        self.assertEqual(res, QTime())
        self.assertFalse(res.isValid())
        self.assertTrue(res.isNull())

    def testQTimeValid(self):
        '''QDataStream <<>> QTime - valid'''
        self.stream << QTime(12, 12, 21)

        res = QTime()

        self.read_stream >> res
        self.assertEqual(res, QTime(12, 12, 21))
        self.assertTrue(res.isValid())
        self.assertFalse(res.isNull())

    def testQDateTimeNull(self):
        '''QDataStream <<>> QDateTime - null'''

        self.stream << QDateTime()

        res = QDateTime()

        self.read_stream >> res
        self.assertEqual(res, QDateTime())
        self.assertFalse(res.isValid())
        self.assertTrue(res.isNull())

    def testQDateTimeValid(self):
        '''QDataStream <<>> QDateTime - valid'''
        time = QTime(23, 23, 23)
        date = QDate(2009, 1, 1)

        self.stream << QDateTime(date, time)

        res = QDateTime()

        self.read_stream >> res
        self.assertEqual(res, QDateTime(date, time))
        self.assertTrue(res.isValid())
        self.assertFalse(res.isNull())