示例#1
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)
示例#2
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)
示例#3
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)
示例#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)
示例#5
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
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
示例#7
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)
示例#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
示例#9
0
    def handle(self):
        unpacker = Unpacker()

        while 1:
            data = self.request.recv(4096)
            if len(data) == 0:
                break
            unpacker.feed(data)
            for msg in unpacker:
                print msg
                assert len(msg) == 4
                assert msg[0] == 0
                assert msg[2] == "echo"
                sdata = packs((1, msg[1], None, msg[-1]))
                self.request.sendall(sdata)
示例#10
0
    def handle(self):
        unpacker = Unpacker()

        while 1:
            data = self.request.recv(4096)
            if len(data) == 0:
                break
            unpacker.feed(data)
            for msg in unpacker:
                print msg
                assert len(msg) == 4
                assert msg[0] == 0
                assert msg[2] == "echo"
                sdata = packs((1, msg[1], None, msg[-1]))
                self.request.sendall(sdata)
示例#11
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")
示例#12
0
def testDecodeBinary():
    re = unpacks(packs(u"abc"), encoding=None)
    assert_equal(re, "abc")
示例#13
0
def testIgnoreErrorsPack():
    re = unpacks(
            packs(u"abcФФФdef", encoding='ascii', unicode_errors='ignore'),
            encoding='utf-8')
    assert_equal(re, u"abcdef")
示例#14
0
def testStrictUnicodeUnpack():
    unpacks(packs('abc\xeddef'), encoding='utf-8')
示例#15
0
	def _cupack(self, k, v) :
		"""
		sets a value at a specific key location using cas, after packing it
		"""
		return self.client.cas(k, msgpack.packs(v))
示例#16
0
def test_array_hook():
    packed = packs([1, 2, 3])
    unpacked = unpacks(packed, list_hook=_arr_to_str)
    eq_(unpacked, '123')
示例#17
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)
示例#18
0
 def _send_msg(self, msg):
     msg = packs(msg)
     transport = self._get_transport()
     transport.try_send(msg)
示例#19
0
def testStrictUnicodePack():
    packs(u"abc\xeddef", encoding='ascii', unicode_errors='strict')
示例#20
0
def testStrictUnicodeUnpack():
    unpacks(packs('abc\xeddef'), encoding='utf-8')
示例#21
0
def check(data):
    re = unpacks(packs(data))
    assert_equal(re, data)
示例#22
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)
示例#23
0
文件: hammer.py 项目: hiidef/logd
def sendmsg(sock, to):
    id = uuid4().hex
    msg = {"id": id, "msg": "sending %s" % id}
    msgb = msgpack.packs(msg)
    return sock.sendto(msgb, to)
示例#24
0
 def _send_response(self, msgid, error, result):
     print "Sending response: %r", ((msgid, error, result))
     msg = packs((1, msgid, error, result))
     self.request.sendall(msg)
示例#25
0
def testIgnoreErrorsPack():
    re = unpacks(packs(u"abcФФФdef", encoding='ascii',
                       unicode_errors='ignore'),
                 encoding='utf-8')
    assert_equal(re, u"abcdef")
示例#26
0
文件: test_obj.py 项目: rep/msgpack
def test_decode_hook():
	cup = ComplexUnpacker()
	packed = packs([3, {b'__complex__': True, b'real': 1, b'imag': 2}])
	cup.feed(packed)
	unpacked = cup.unpack()
	eq_(unpacked[1], 1+2j)
示例#27
0
def testNoEncoding():
    packs(u"abc", encoding=None)
示例#28
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})
示例#29
0
def testDecodeBinary():
    re = unpacks(packs(u"abc"), encoding=None)
    assert_equal(re, "abc")
示例#30
0
def test_bad_hook():
    packed = packs([3, 1 + 2j], default=lambda o: o)
    unpacked = unpacks(packed)
示例#31
0
def match(obj, buf):
    assert_equal(packs(obj), buf)
    assert_equal(unpacks(buf), obj)
示例#32
0
def test_unicode():
    assert_equal('foobar', unpacks(packs(u'foobar')))
示例#33
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})
示例#34
0
def testIgnoreUnicodeErrors():
    re = unpacks(packs('abc\xeddef'),
        encoding='ascii', unicode_errors='ignore')
    assert_equal(re, "abcdef")
示例#35
0
def test_bad_hook():
    packed = packs([3, 1 + 2j], default=lambda o: o)
    unpacked = unpacks(packed)
示例#36
0
def testStrictUnicodePack():
    packs(u"abc\xeddef", encoding='ascii', unicode_errors='strict')
示例#37
0
文件: test_obj.py 项目: Matzo/msgpack
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})
示例#38
0
def testNoEncoding():
    packs(u"abc", encoding=None)
示例#39
0
 def _send_msg(self, msg):
     msg = packs(msg)
     transport = self._get_transport()
     transport.try_send(msg)
示例#40
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)
示例#41
0
文件: test_obj.py 项目: rep/msgpack
def test_array_hook():
	packed = packs([1,2,3])
	cup = ArrayStrUnpacker()
	cup.feed(packed)
	unpacked = cup.unpack()
	eq_(unpacked, b'123')
示例#42
0
文件: test_obj.py 项目: Matzo/msgpack
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)
示例#43
0
def match(obj, buf):
    assert_equal(packs(obj), buf)
    assert_equal(unpacks(buf), obj)
示例#44
0
def check(data):
    re = unpacks(packs(data))
    assert_equal(re, data)
示例#45
0
文件: log.py 项目: hiidef/logd
 def _send(self, msg, name, level=10):
     msg = {'msg': msg, 'name': name, 'id': 1, 'path': self.path,
         'time': time.time(), 'level': level}
     txtmsg = msgpack.packs(msg)
     self.logd.sendto(txtmsg, (self.host, self.port))
示例#46
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)
示例#47
0
def testIgnoreUnicodeErrors():
    re = unpacks(packs('abc\xeddef'),
                 encoding='ascii',
                 unicode_errors='ignore')
    assert_equal(re, "abcdef")
示例#48
0
def test_array_hook():
    packed = packs([1, 2, 3])
    unpacked = unpacks(packed, list_hook=_arr_to_str)
    eq_(unpacked, "123")
示例#49
0
def test_unicode():
    assert_equal('foobar', unpacks(packs(u'foobar')))