Esempio n. 1
0
def main():
    ctx = zmq.Context(1)
    s = ctx.socket(zmq.SUB)
    s.connect(ENDPOINT)
    s.setsockopt(zmq.SUBSCRIBE, "")
    while 1:
        msg = s.recv()
        print repr(msg)
        print msgpack.unpacks(msg)
Esempio n. 2
0
def testPackUTF32():
    test_data = [
        "", "abcd", ("defgh",), "Русский текст",
        ]
    for td in test_data:
        re = unpacks(packs(td, encoding='utf-32'), encoding='utf-32')
        assert_equal(re, td)
Esempio n. 3
0
    def _test_request(self,
                      operation=MSGTYPE_REQUEST,
                      method="echo",
                      value="",
                      expected_result="",
                      expected_error=None):
        index = MsgpackTestCase.request_index
        MsgpackTestCase.request_index += 1

        message = (operation, index, method, (value, ))
        packed_message = self.packer.pack(message)

        response = (MSGTYPE_RESPONSE, index, expected_error, expected_result)
        packed_response = self.packer.pack(response)

        self.proto.dataReceived(packed_message)
        return_value = self.transport.value()

        self.assertEqual(return_value, packed_response)

        unpacked_response = msgpack.unpacks(return_value)
        (msgType, msgid, methodName, params) = unpacked_response

        self.assertEqual(msgType, MSGTYPE_RESPONSE)
        self.assertEqual(msgid, index)
        self.assertEqual(methodName, None)
        self.assertEqual(params, expected_result)
Esempio n. 4
0
def testPackUnicode():
    test_data = [
        u"", u"abcd", (u"defgh",), u"Русский текст",
        ]
    for td in test_data:
        re = unpacks(packs(td, encoding='utf-8'), encoding='utf-8')
        assert_equal(re, td)
Esempio n. 5
0
	def _unpack(self, v) :
		"""
		generic unpacker; understands None=None (no unpacking lookup failure)
		"""
		if v is None :
			return None
		else :
			return msgpack.unpacks(v)
def _check(obj):
    # NOTE:
    # msgpack.packs(obj) nad msgpack_pure.packs(obj) are not necessarily
    # match because there are some possible variations which type to use
    # for integer values (i.e. uint8/int16 for 0xFF).
    obj = _list_to_tuple(obj)
    
    assert msgpack_pure.unpacks(msgpack.packs(obj)) == obj
    assert msgpack.unpacks(msgpack_pure.packs(obj)) == obj
    assert msgpack_pure.unpacks(msgpack_pure.packs(obj)) == obj
Esempio n. 7
0
def testPackUnicode():
    test_data = [
        u"",
        u"abcd",
        (u"defgh", ),
        u"Русский текст",
    ]
    for td in test_data:
        re = unpacks(packs(td, encoding='utf-8'), encoding='utf-8')
        assert_equal(re, td)
Esempio n. 8
0
def testPackUTF32():
    try:
        test_data = [
            u"", u"abcd", (u"defgh",), u"Русский текст",
            ]
        for td in test_data:
            re = unpacks(packs(td, encoding='utf-32'), encoding='utf-32')
            assert_equal(re, td)
    except LookupError:
        raise SkipTest
Esempio n. 9
0
def testPackUTF32():
    test_data = [
        "",
        "abcd",
        ("defgh", ),
        "Русский текст",
    ]
    for td in test_data:
        print(packs(td, encoding='utf-32'))
        re = unpacks(packs(td, encoding='utf-32'), encoding='utf-32')
        assert_equal(re, td)
Esempio n. 10
0
def testPackUnicode():
    test_data = [
        "", "abcd", ("defgh",), "Русский текст",
        ]
    for td in test_data:
        re = unpacks(packs(td, encoding='utf-8'), encoding='utf-8')
        assert_equal(re, td)
        packer = Packer(encoding='utf-8')
        data = packer.pack(td)
        re = Unpacker(BytesIO(data), encoding='utf-8').unpack()
        assert_equal(re, td)
Esempio n. 11
0
def testPackUTF32():
    try:
        test_data = [
            u"",
            u"abcd",
            (u"defgh", ),
            u"Русский текст",
        ]
        for td in test_data:
            re = unpacks(packs(td, encoding='utf-32'), encoding='utf-32')
            assert_equal(re, td)
    except LookupError:
        raise SkipTest
Esempio n. 12
0
    def _test_request(self, operation=MSGTYPE_REQUEST, method="echo", value="", expected_result="", expected_error=None):
        index = MsgpackTestCase.request_index
        MsgpackTestCase.request_index += 1

        message         = (operation, index, method, (value,))
        packed_message  = self.packer.pack(message)

        response        = (MSGTYPE_RESPONSE, index, expected_error, expected_result)
        packed_response = self.packer.pack(response)

        self.proto.dataReceived(packed_message)
        return_value = self.transport.value()

        self.assertEqual(return_value, packed_response)

        unpacked_response = msgpack.unpacks(return_value)
        (msgType, msgid, methodName, params) = unpacked_response

        self.assertEqual(msgType, MSGTYPE_RESPONSE)
        self.assertEqual(msgid, index)
        self.assertEqual(methodName, None)
        self.assertEqual(params, expected_result)
Esempio n. 13
0
    def run(self):
        while True:
            # grab the next message
            message = self.queue.get(block=True)

            # we have a message to send, the heart beat
            # can take a break
            self.lastSentData = time.time()

            # msgpack it
            message = packs(message)

            # send the message
            success = self.transport.send(message)

            # tell the queue we are done
            self.queue.task_done()

            if (success):
                self.log("Message sent")
                self.dump(unpacks(message, use_list=True))
            else:
                self.error("Sending metrics to Graphdat failed")
Esempio n. 14
0
def test_encode_hook():
    packed = packs([3, 1 + 2j], default=_encode_complex)
    unpacked = unpacks(packed)
    eq_(unpacked[1], {"__complex__": True, "real": 1, "imag": 2})
Esempio n. 15
0
def check(src, should):
    assert_equal(unpacks(src), should)
Esempio n. 16
0
def test_encode_hook():
    packed = packs([3, 1+2j], default=_encode_complex)
    unpacked = unpacks(packed)
    eq_(unpacked[1], {b'__complex__': True, b'real': 1, b'imag': 2})
Esempio n. 17
0
def testIgnoreErrorsPack():
    re = unpacks(
            packs(u"abcФФФdef", encoding='ascii', unicode_errors='ignore'),
            encoding='utf-8')
    assert_equal(re, u"abcdef")
Esempio n. 18
0
def testIgnoreUnicodeErrors():
    re = unpacks(packs('abc\xeddef'),
        encoding='ascii', unicode_errors='ignore')
    assert_equal(re, "abcdef")
Esempio n. 19
0
def test_unicode():
    assert_equal('foobar', unpacks(packs(u'foobar')))
Esempio n. 20
0
def test_bad_hook():
    packed = packs([3, 1 + 2j], default=lambda o: o)
    unpacked = unpacks(packed)
Esempio n. 21
0
def testDecodeBinary():
    re = unpacks(packs(u"abc"), encoding=None)
    assert_equal(re, "abc")
Esempio n. 22
0
def testIgnoreErrorsPack():
    re = unpacks(packs(u"abcФФФdef", encoding='ascii',
                       unicode_errors='ignore'),
                 encoding='utf-8')
    assert_equal(re, u"abcdef")
Esempio n. 23
0
def testStrictUnicodeUnpack():
    unpacks(packs('abc\xeddef'), encoding='utf-8')
Esempio n. 24
0
def check(data):
    re = unpacks(packs(data))
    assert_equal(re, data)
Esempio n. 25
0
def check(length, obj):
    v = packs(obj)
    assert_equal(len(v), length, "%r length should be %r but get %r" % (obj, length, len(v)))
    assert_equal(unpacks(v), obj)
def _check_decode(bytes):
    packed = struct.pack("B" * len(bytes), *bytes)
    assert msgpack.unpacks(packed) == msgpack_pure.unpacks(packed)
Esempio n. 27
0
def test_encode_hook():
	cp = ComplexPacker()
	packed = cp.pack([3, 1+2j])
	unpacked = unpacks(packed)
	eq_(unpacked[1], {b'__complex__': True, b'real': 1, b'imag': 2})
Esempio n. 28
0
def test_decode_hook():
    packed = packs([3, {'__complex__': True, 'real': 1, 'imag': 2}])
    unpacked = unpacks(packed, object_hook=_decode_complex)
    eq_(unpacked[1], 1 + 2j)
Esempio n. 29
0
def match(obj, buf):
    assert_equal(packs(obj), buf)
    assert_equal(unpacks(buf), obj)
Esempio n. 30
0
def test_array_hook():
    packed = packs([1, 2, 3])
    unpacked = unpacks(packed, list_hook=_arr_to_str)
    eq_(unpacked, '123')
Esempio n. 31
0
def test_bad_hook():
    packed = packs([3, 1 + 2j], default=lambda o: o)
    unpacked = unpacks(packed)
Esempio n. 32
0
 def unpack(self, payload):
     return msgpack.unpacks(payload, use_list=True)
Esempio n. 33
0
def test_unicode():
    assert_equal('foobar', unpacks(packs(u'foobar')))
Esempio n. 34
0
def testStrictUnicodeUnpack():
    unpacks(packs('abc\xeddef'), encoding='utf-8')
Esempio n. 35
0
def check(length, obj):
    v = packs(obj)
    assert_equal(len(v), length,
                 "%r length should be %r but get %r" % (obj, length, len(v)))
    assert_equal(unpacks(v), obj)
Esempio n. 36
0
def testDecodeBinary():
    re = unpacks(packs(u"abc"), encoding=None)
    assert_equal(re, "abc")
Esempio n. 37
0
def match(obj, buf):
    assert_equal(packs(obj), buf)
    assert_equal(unpacks(buf), obj)
Esempio n. 38
0
def test_decode_hook():
    packed = packs([3, {b'__complex__': True, b'real': 1, b'imag': 2}])
    unpacked = unpacks(packed, object_hook=_decode_complex)
    eq_(unpacked[1], 1+2j)
Esempio n. 39
0
def check(src, should):
    assert_equal(unpacks(src), should)
Esempio n. 40
0
def check(data):
    re = unpacks(packs(data))
    assert_equal(re, data)
Esempio n. 41
0
def test_encode_hook():
    packed = packs([3, 1 + 2j], default=_encode_complex)
    unpacked = unpacks(packed)
    eq_(unpacked[1], {'__complex__': True, 'real': 1, 'imag': 2})
Esempio n. 42
0
def test_decode_hook():
    packed = packs([3, {"__complex__": True, "real": 1, "imag": 2}])
    unpacked = unpacks(packed, object_hook=_decode_complex)
    eq_(unpacked[1], 1 + 2j)
Esempio n. 43
0
def test_bad_hook():
	cp = Packer()
	packed = cp.pack([3, 1+2j])
	unpacked = unpacks(packed)
Esempio n. 44
0
def test_array_hook():
    packed = packs([1, 2, 3])
    unpacked = unpacks(packed, list_hook=_arr_to_str)
    eq_(unpacked, "123")
Esempio n. 45
0
def testIgnoreUnicodeErrors():
    re = unpacks(packs('abc\xeddef'),
                 encoding='ascii',
                 unicode_errors='ignore')
    assert_equal(re, "abcdef")