Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/jsonschema/__init__.py: 60%

20 statements  

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

1""" 

2An implementation of JSON Schema for Python 

3 

4The main functionality is provided by the validator classes for each of the 

5supported JSON Schema versions. 

6 

7Most commonly, `jsonschema.validators.validate` is the quickest way to simply 

8validate a given instance under a schema, and will create a validator 

9for you. 

10""" 

11import warnings 

12 

13from jsonschema._format import FormatChecker 

14from jsonschema._types import TypeChecker 

15from jsonschema.exceptions import ( 

16 ErrorTree, 

17 FormatError, 

18 RefResolutionError, 

19 SchemaError, 

20 ValidationError, 

21) 

22from jsonschema.protocols import Validator 

23from jsonschema.validators import ( 

24 Draft3Validator, 

25 Draft4Validator, 

26 Draft6Validator, 

27 Draft7Validator, 

28 Draft201909Validator, 

29 Draft202012Validator, 

30 RefResolver, 

31 validate, 

32) 

33 

34 

35def __getattr__(name): 

36 if name == "__version__": 

37 warnings.warn( 

38 "Accessing jsonschema.__version__ is deprecated and will be " 

39 "removed in a future release. Use importlib.metadata directly " 

40 "to query for jsonschema's version.", 

41 DeprecationWarning, 

42 stacklevel=2, 

43 ) 

44 

45 try: 

46 from importlib import metadata 

47 except ImportError: 

48 import importlib_metadata as metadata 

49 

50 return metadata.version("jsonschema") 

51 

52 format_checkers = { 

53 "draft3_format_checker": Draft3Validator, 

54 "draft4_format_checker": Draft4Validator, 

55 "draft6_format_checker": Draft6Validator, 

56 "draft7_format_checker": Draft7Validator, 

57 "draft201909_format_checker": Draft201909Validator, 

58 "draft202012_format_checker": Draft202012Validator, 

59 } 

60 ValidatorForFormat = format_checkers.get(name) 

61 if ValidatorForFormat is not None: 

62 warnings.warn( 

63 f"Accessing jsonschema.{name} is deprecated and will be " 

64 "removed in a future release. Instead, use the FORMAT_CHECKER " 

65 "attribute on the corresponding Validator.", 

66 DeprecationWarning, 

67 stacklevel=2, 

68 ) 

69 return ValidatorForFormat.FORMAT_CHECKER 

70 

71 raise AttributeError(f"module {__name__} has no attribute {name}")