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.adapters import from_iter
17from ijson.common import JSONError, IncompleteJSONError, ObjectBuilder
19from ijson.utils import coroutine, sendable_list
20from .version import __version__
23ALL_BACKENDS = ('yajl2_c', 'yajl2_cffi', 'yajl2', 'yajl', 'python')
24"""
25All supported backends, in descending order or speed. Not all might be available at
26runtime.
27"""
29def get_backend(backend):
30 """Import the backend named ``backend``"""
31 import importlib
32 return importlib.import_module('ijson.backends.' + backend)
34def _default_backend():
35 import os
36 if 'IJSON_BACKEND' in os.environ:
37 return get_backend(os.environ['IJSON_BACKEND'])
38 for backend in ALL_BACKENDS:
39 try:
40 return get_backend(backend)
41 except ImportError:
42 continue
43 raise ImportError('no backends available')
44backend = _default_backend()
45del _default_backend
47basic_parse = backend.basic_parse
48basic_parse_coro = backend.basic_parse_coro
49parse = backend.parse
50parse_coro = backend.parse_coro
51items = backend.items
52items_coro = backend.items_coro
53kvitems = backend.kvitems
54kvitems_coro = backend.kvitems_coro
55basic_parse_async = backend.basic_parse_async
56parse_async = backend.parse_async
57items_async = backend.items_async
58kvitems_async = backend.kvitems_async
59backend_name = backend.backend_name
60backend = backend.backend