示例#1
0
 def ubjloadb(raw, *args, **kwargs):
     try:
         raw = BytesIO(raw)
     except TypeError:  # pylint: disable=bare-except
         # Invalid raw input testing
         raise
     return ubjload(raw, *args, **kwargs)
示例#2
0
文件: test.py 项目: hoenn/py-ubjson
    def test_fp(self):
        obj = {"a": 123, "b": 456}
        output = BytesIO()
        ubjdump({"a": 123, "b": 456}, output)
        output.seek(0)
        self.assertEqual(ubjload(output), obj)

        # items which fit into extension decoder-internal read buffer (BUFFER_FP_SIZE in decoder.c)
        obj2 = ['fishy' * 64] * 10
        output = BytesIO()
        ubjdump(obj, output)
        output.seek(0)
        self.assertEqual(ubjload(output), obj)

        # larger than extension read buffer
        obj2 = ['fishy' * 512] * 10
        output.seek(0)
        ubjdump(obj2, output)
        output.seek(0)
        self.assertEqual(ubjload(output), obj2)
示例#3
0
    def test_invalid_fp_load(self):
        with self.assertRaises(AttributeError):
            ubjload(1)

        class Dummy(object):
            read = 1

        class Dummy2(object):
            @staticmethod
            def read(length):
                raise ValueError('invalid - %d' % length)

        with self.assertRaises(TypeError):
            ubjload(Dummy)

        with self.assertRaises(ValueError):
            ubjload(Dummy2)
示例#4
0
 def ubjload(fp, *args, **kwargs):
     return ubjload(fp, *args, **kwargs)
示例#5
0
 def ubjloadb(raw, *args, **kwargs):
     return ubjload(BytesIO(raw), *args, **kwargs)