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
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-10 06:15 +0000
1"""Miscellaneous mappings used to avoid circular imports.
3Variables:
5`class_name_dict`
6 Node class name to class object mapping.
7`class_id_dict`
8 Class identifier to class object mapping.
10Misc variables:
12`__docformat__`
13 The format of documentation strings in this module.
15"""
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!
22__docformat__ = 'reStructuredText'
23"""The format of documentation strings in this module."""
25class_name_dict = {}
26"""Node class name to class object mapping.
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.
33.. versionchanged:: 3.0
34 The *classNameDict* dictionary has been renamed into *class_name_dict*.
36"""
38class_id_dict = {}
39"""Class identifier to class object mapping.
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.
47.. versionchanged:: 3.0
48 The *classIdDict* dictionary has been renamed into *class_id_dict*.
50"""
52# Deprecated API
53classNameDict = class_name_dict
54classIdDict = class_id_dict
57def get_class_by_name(classname):
58 """Get the node class matching the `classname`.
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.
63 .. versionadded:: 3.0
65 """
67 # The empty string is accepted for compatibility
68 # with old default arguments.
69 if classname is None or classname == '':
70 classname = 'Node'
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,))
77 return class_name_dict[classname]