Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/ijson-3.2.0.post0-py3.8-linux-x86_64.egg/ijson/__init__.py: 88%

32 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:10 +0000

1''' 

2Iterative JSON parser. 

3 

4Main API: 

5 

6- ``ijson.parse``: iterator returning parsing events with the object tree context, 

7 see ``ijson.common.parse`` for docs. 

8 

9- ``ijson.items``: iterator returning Python objects found under a specified prefix, 

10 see ``ijson.common.items`` for docs. 

11 

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, compat 

17 

18from ijson.utils import coroutine, sendable_list 

19from .version import __version__ 

20 

21def get_backend(backend): 

22 """Import the backend named ``backend``""" 

23 import importlib 

24 return importlib.import_module('ijson.backends.' + backend) 

25 

26def _default_backend(): 

27 import os 

28 if 'IJSON_BACKEND' in os.environ: 

29 return get_backend(os.environ['IJSON_BACKEND']) 

30 for backend in ('yajl2_c', 'yajl2_cffi', 'yajl2', 'yajl', 'python'): 

31 try: 

32 return get_backend(backend) 

33 except ImportError: 

34 continue 

35 raise ImportError('no backends available') 

36backend = _default_backend() 

37del _default_backend 

38 

39basic_parse = backend.basic_parse 

40basic_parse_coro = backend.basic_parse_coro 

41parse = backend.parse 

42parse_coro = backend.parse_coro 

43items = backend.items 

44items_coro = backend.items_coro 

45kvitems = backend.kvitems 

46kvitems_coro = backend.kvitems_coro 

47if compat.IS_PY35: 

48 basic_parse_async = backend.basic_parse_async 

49 parse_async = backend.parse_async 

50 items_async = backend.items_async 

51 kvitems_async = backend.kvitems_async 

52backend = backend.backend