Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/ijson/__init__.py: 89%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1'''
2Iterative JSON parser.
4Main API:
6- ``ijson.parse``: iterator returning parsing events with the object tree context,
7 see ``ijson.common.parse`` for docs.
9- ``ijson.items``: iterator returning Python objects found under a specified prefix,
10 see ``ijson.common.items`` for docs.
12Top-level ``ijson`` module exposes method from the pure Python backend. There's
13also two other backends using the C library yajl in ``ijson.backends`` that have
14the same API and are faster under CPython.
15'''
16from ijson.common import JSONError, IncompleteJSONError, ObjectBuilder
18from ijson.utils import coroutine, sendable_list
19from .version import __version__
22ALL_BACKENDS = ('yajl2_c', 'yajl2_cffi', 'yajl2', 'yajl', 'python')
23"""
24All supported backends, in descending order or speed. Not all might be available at
25runtime.
26"""
28def get_backend(backend):
29 """Import the backend named ``backend``"""
30 import importlib
31 return importlib.import_module('ijson.backends.' + backend)
33def _default_backend():
34 import os
35 if 'IJSON_BACKEND' in os.environ:
36 return get_backend(os.environ['IJSON_BACKEND'])
37 for backend in ALL_BACKENDS:
38 try:
39 return get_backend(backend)
40 except ImportError:
41 continue
42 raise ImportError('no backends available')
43backend = _default_backend()
44del _default_backend
46basic_parse = backend.basic_parse
47basic_parse_coro = backend.basic_parse_coro
48parse = backend.parse
49parse_coro = backend.parse_coro
50items = backend.items
51items_coro = backend.items_coro
52kvitems = backend.kvitems
53kvitems_coro = backend.kvitems_coro
54basic_parse_async = backend.basic_parse_async
55parse_async = backend.parse_async
56items_async = backend.items_async
57kvitems_async = backend.kvitems_async
58backend_name = backend.backend_name
59backend = backend.backend