Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tables/registry.py: 55%

11 statements  

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

1"""Miscellaneous mappings used to avoid circular imports. 

2 

3Variables: 

4 

5`class_name_dict` 

6 Node class name to class object mapping. 

7`class_id_dict` 

8 Class identifier to class object mapping. 

9 

10Misc variables: 

11 

12`__docformat__` 

13 The format of documentation strings in this module. 

14 

15""" 

16 

17 

18# Important: no modules from PyTables should be imported here 

19# (but standard modules are OK), since the main reason for this module 

20# is avoiding circular imports! 

21 

22__docformat__ = 'reStructuredText' 

23"""The format of documentation strings in this module.""" 

24 

25class_name_dict = {} 

26"""Node class name to class object mapping. 

27 

28This dictionary maps class names (e.g. ``'Group'``) to actual class 

29objects (e.g. `Group`). Classes are registered here when they are 

30defined, and they are not expected to be unregistered (by now), but they 

31can be replaced when the module that defines them is reloaded. 

32 

33.. versionchanged:: 3.0 

34 The *classNameDict* dictionary has been renamed into *class_name_dict*. 

35 

36""" 

37 

38class_id_dict = {} 

39"""Class identifier to class object mapping. 

40 

41This dictionary maps class identifiers (e.g. ``'GROUP'``) to actual 

42class objects (e.g. `Group`). Classes defining a new ``_c_classid`` 

43attribute are registered here when they are defined, and they are not 

44expected to be unregistered (by now), but they can be replaced when the 

45module that defines them is reloaded. 

46 

47.. versionchanged:: 3.0 

48 The *classIdDict* dictionary has been renamed into *class_id_dict*. 

49 

50""" 

51 

52# Deprecated API 

53classNameDict = class_name_dict 

54classIdDict = class_id_dict 

55 

56 

57def get_class_by_name(classname): 

58 """Get the node class matching the `classname`. 

59 

60 If the name is not registered, a ``TypeError`` is raised. The empty 

61 string and ``None`` are also accepted, and mean the ``Node`` class. 

62 

63 .. versionadded:: 3.0 

64 

65 """ 

66 

67 # The empty string is accepted for compatibility 

68 # with old default arguments. 

69 if classname is None or classname == '': 

70 classname = 'Node' 

71 

72 # Get the class object corresponding to `classname`. 

73 if classname not in class_name_dict: 

74 raise TypeError("there is no registered node class named ``%s``" 

75 % (classname,)) 

76 

77 return class_name_dict[classname]