Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/ijson-3.2.0.post0-py3.8-linux-x86_64.egg/ijson/backends/yajl.py: 13%
30 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:10 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:10 +0000
1'''
2Wrapper for YAJL C library version 1.x.
3'''
5from ctypes import Structure, c_uint, byref
7from ijson import common, utils
8from ijson.backends import _yajl2_ctypes_common
11yajl = _yajl2_ctypes_common.get_yajl(1)
13class Config(Structure):
14 _fields_ = [
15 ("allowComments", c_uint),
16 ("checkUTF8", c_uint)
17 ]
20@utils.coroutine
21def basic_parse_basecoro(target, allow_comments=False, multiple_values=False,
22 use_float=False):
23 '''
24 Iterator yielding unprefixed events.
26 Parameters:
28 - f: a readable file-like object with JSON input
29 - allow_comments: tells parser to allow comments in JSON input
30 - check_utf8: if True, parser will cause an error if input is invalid utf-8
31 - buf_size: a size of an input buffer
32 '''
33 if multiple_values:
34 raise ValueError("yajl backend doesn't support multiple_values")
35 callbacks = _yajl2_ctypes_common.make_callbaks(target.send, use_float, 1)
36 config = Config(allow_comments, True)
37 handle = yajl.yajl_alloc(byref(callbacks), byref(config), None, None)
38 try:
39 while True:
40 try:
41 buffer = (yield)
42 except GeneratorExit:
43 buffer = b''
44 if buffer:
45 result = yajl.yajl_parse(handle, buffer, len(buffer))
46 else:
47 result = yajl.yajl_parse_complete(handle)
48 if result == _yajl2_ctypes_common.YAJL_ERROR:
49 error = _yajl2_ctypes_common.yajl_get_error(yajl, handle, buffer)
50 raise common.JSONError(error)
51 elif not buffer:
52 if result == _yajl2_ctypes_common.YAJL_INSUFFICIENT_DATA:
53 raise common.IncompleteJSONError('Incomplete JSON data')
54 break
55 finally:
56 yajl.yajl_free(handle)
59common.enrich_backend(globals())