1#
2# Contributed by Rodrigo Tobar <rtobar@icrar.org>
3#
4# ICRAR - International Centre for Radio Astronomy Research
5# (c) UWA - The University of Western Australia, 2016
6# Copyright by UWA (in the framework of the ICRAR)
7#
8'''
9Wrapper for _yajl2 C extension module
10'''
11
12from ijson import common, compat, utils
13from . import _yajl2
14
15
16_get_buf_size = lambda kwargs: kwargs.pop('buf_size', 64 * 1024)
17
18@utils.coroutine
19def basic_parse_basecoro(target, **kwargs):
20 return _yajl2.basic_parse_basecoro(target.send, **kwargs)
21
22def basic_parse_gen(file, **kwargs):
23 f = compat.bytes_reader(file)
24 buf_size = _get_buf_size(kwargs)
25 return _yajl2.basic_parse(f, buf_size, **kwargs)
26
27def basic_parse_async(file, **kwargs):
28 buf_size = _get_buf_size(kwargs)
29 return _yajl2.basic_parse_async(file, buf_size, **kwargs)
30
31@utils.coroutine
32def parse_basecoro(target, **kwargs):
33 return _yajl2.parse_basecoro(target.send, **kwargs)
34
35def parse_gen(file, **kwargs):
36 f = compat.bytes_reader(file)
37 buf_size = _get_buf_size(kwargs)
38 return _yajl2.parse(f, buf_size, **kwargs)
39
40def parse_async(file, **kwargs):
41 buf_size = _get_buf_size(kwargs)
42 return _yajl2.parse_async(file, buf_size, **kwargs)
43
44@utils.coroutine
45def kvitems_basecoro(target, prefix, map_type=None, **kwargs):
46 return _yajl2.kvitems_basecoro(target.send, prefix, map_type, **kwargs)
47
48def kvitems_gen(file, prefix, map_type=None, **kwargs):
49 f = compat.bytes_reader(file)
50 buf_size = _get_buf_size(kwargs)
51 return _yajl2.kvitems(f, buf_size, prefix, map_type, **kwargs)
52
53def kvitems_async(file, prefix, map_type=None, **kwargs):
54 buf_size = _get_buf_size(kwargs)
55 return _yajl2.kvitems_async(file, buf_size, prefix, map_type, **kwargs)
56
57@utils.coroutine
58def items_basecoro(target, prefix, map_type=None, **kwargs):
59 return _yajl2.items_basecoro(target.send, prefix, map_type, **kwargs)
60
61def items_gen(file, prefix, map_type=None, **kwargs):
62 f = compat.bytes_reader(file)
63 buf_size = _get_buf_size(kwargs)
64 return _yajl2.items(f, buf_size, prefix, map_type, **kwargs)
65
66def items_async(file, prefix, map_type=None, **kwargs):
67 buf_size = _get_buf_size(kwargs)
68 return _yajl2.items_async(file, buf_size, prefix, map_type, **kwargs)
69
70common.enrich_backend(globals())