示例#1
0
    def __writeamf__(self, output):
        flag_attrs = []
        uuid_attrs = []
        byte = 0

        for flag in self.SMALL_ATTRIBUTE_FLAGS:
            value = self.encodeSmallAttribute(self.SMALL_ATTRIBUTES[flag])

            if value:
                byte |= flag
                flag_attrs.append(value)

        flags = byte
        byte = 0

        for flag in self.SMALL_UUID_FLAGS:
            attr = self.SMALL_UUIDS[flag]
            value = getattr(self, attr)

            if not value:
                continue

            byte |= flag
            uuid_attrs.append(amf3.ByteArray(value.bytes))

        del attr

        if not byte:
            output.writeUnsignedByte(flags)
        else:
            output.writeUnsignedByte(flags | SMALL_FLAG_MORE)
            output.writeUnsignedByte(byte)

        [output.writeObject(attr) for attr in flag_attrs]
        [output.writeObject(attr) for attr in uuid_attrs]
示例#2
0
    def test_context(self):
        b = amf3.ByteArray()
        c = b.context

        obj = {'foo': 'bar'}

        c.addObject(obj)

        b.writeObject(obj)

        self.assertEqual(b.getvalue(), '\n\x0b\x01\x07foo\x06\x07bar\x01')
示例#3
0
    def test_read_context(self):
        """
        @see: #695
        """
        obj = {'foo': 'bar'}
        b = amf3.ByteArray()

        b.stream.write('\n\x0b\x01\x07foo\x06\x07bar\x01\n\x00')
        b.stream.seek(0)

        self.assertEqual(obj, b.readObject())
        self.assertRaises(pyamf.ReferenceError, b.readObject)
示例#4
0
    def test_compressed(self):
        """
        ByteArrays can be compressed. Test the C{compressed} attribute for
        validity.
        """
        try:
            import zlib
        except ImportError:
            self.skipTest('zlib is missing')

        ba = amf3.ByteArray()

        self.assertFalse(ba.compressed)

        z = zlib.compress('b' * 100)
        ba = amf3.ByteArray(z)

        self.assertTrue(ba.compressed)

        z = zlib.compress('\x00' * 100)
        ba = amf3.ByteArray(z)

        self.assertTrue(ba.compressed)
示例#5
0
    def test_write_context(self):
        """
        @see: #695
        """
        obj = {'foo': 'bar'}
        b = amf3.ByteArray()

        b.writeObject(obj)

        bytes = b.getvalue()
        b.stream.truncate()

        b.writeObject(obj)
        self.assertEqual(b.getvalue(), bytes)
示例#6
0
 def test_byte_array(self):
     self.assertDecoded(amf3.ByteArray('hello'), '\x0c\x0bhello')