本文整理汇总了Python中simpleubjson.compat.b函数的典型用法代码示例。如果您正苦于以下问题:Python b函数的具体用法?Python b怎么用?Python b使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了b函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_decode_nested_unsized_values
def test_decode_nested_unsized_values(self):
data = self.decode(b('a\xffa\xffB\x2aEo\xffs\x03fooB\x2aEE'))
self.assertTrue(isinstance(data, GeneratorType))
item = data.next()
self.assertTrue(isinstance(item, list))
self.assertEqual(item, [42])
item = data.next()
self.assertTrue(isinstance(item, list))
self.assertEqual(item, [(b('foo'), 42)])
示例2: test_allow_emit_noop_for_objects
def test_allow_emit_noop_for_objects(self):
data = self.decode(b('{NSi\x03fooNSi\x03barN}'),
allow_noop=True)
self.assertTrue(isinstance(data, GeneratorType))
data = list(data)
N = simpleubjson.NOOP
self.assertEqual(data, [(N, N), ('foo', 'bar'), (N, N)])
self.assertEqual(dict(data), {'foo': 'bar', N: N})
data = self.decode(b('[i\x00Ni\x01Ni\x02Ni\x03Ni\x04]'),
allow_noop=True)
N = simpleubjson.NOOP
self.assertEqual(list(data), [0, N, 1, N, 2, N, 3, N, 4])
示例3: test_custom_default_handler
def test_custom_default_handler(self):
sentinel = object()
def dummy(value):
assert value is sentinel
return [b('sentinel')]
data = self.encode(sentinel, default=dummy)
self.assertEqual(data, b('[Si\x08sentinel]'))
示例4: test_decode_nested_unsized_values
def test_decode_nested_unsized_values(self):
data = self.decode(b('[[i\x2a]{Si\x03fooi\x2a}]'))
self.assertTrue(isinstance(data, GeneratorType))
for item in data:
break
else:
self.fail('next item expected')
self.assertTrue(isinstance(item, list))
self.assertEqual(item, [42])
for item in data:
break
else:
self.fail('next item expected')
self.assertTrue(isinstance(item, list))
self.assertEqual(item, [('foo', 42)])
示例5: test_decode_object
def test_decode_object(self):
data = dict(self.decode(b('{Si\x03fooSi\x03barSi\x03barSi\x03baz}')))
self.assertEqual(data, {'foo': 'bar', 'bar': 'baz'})
示例6: test_decode_unsized_array
def test_decode_unsized_array(self):
data = self.decode(b('[i\x01i\x02i\x03]'))
self.assertTrue(isinstance(data, GeneratorType))
self.assertEqual(list(data), [1, 2, 3])
示例7: test_encode_frozenset
def test_encode_frozenset(self):
data = self.encode(frozenset(['foo', 'foo', 'foo']))
self.assertEqual(data, b('[Si\x03foo]'))
示例8: test_write_encoded_data_to_stream
def test_write_encoded_data_to_stream(self):
stream = StringIO()
self.encode((i for i in range(5)), stream)
self.assertEqual(stream.getvalue(),
b('[i\x00i\x01i\x02i\x03i\x04]'))
示例9: test_fail_decode_non_string_object_keys
def test_fail_decode_non_string_object_keys(self):
self.assertRaises(ValueError,
list,
self.decode(b('{i\x03Si\x03bar}')))
示例10: test_decode_object_with_nested_unsized_objects
def test_decode_object_with_nested_unsized_objects(self):
source = b('{Si\x03bar[i\x2a]Si\x03baz{NNNSi\x03fooi\x2a}}')
data = dict(self.decode(source))
self.assertEqual(data, {'baz': [('foo', 42)], 'bar': [42]})
示例11: test_encode_dict_iterkeys
def test_encode_dict_iterkeys(self):
data = {'foo': 'bar'}
data = self.encode(getattr(data, 'iterkeys', data.keys)())
self.assertEqual(data, b('[Si\x03foo]'))
示例12: test_encode_xrange
def test_encode_xrange(self):
data = self.encode(xrange(4))
self.assertEqual(data, b('[i\x00i\x01i\x02i\x03]'))
示例13: dummy
def dummy(stream, markers, tag):
assert tag == '%'
return markers['s'], ('s', 3, b('foo'))
示例14: test_decode_unsized_array_with_noops
def test_decode_unsized_array_with_noops(self):
data = self.decode(b('[Ni\x01NNNi\x02NNNNNNNNNNNNNi\x03]'))
self.assertTrue(isinstance(data, GeneratorType))
self.assertEqual(list(data), [1, 2, 3])
示例15: test_decode_unsized_object
def test_decode_unsized_object(self):
data = self.decode(b('{Si\x03fooSi\x03barSi\x03barSi\x03baz}'))
self.assertTrue(isinstance(data, GeneratorType))
self.assertEqual(dict(data), {'foo': 'bar', 'bar': 'baz'})