/usr/lib/python3/dist-packages/provisioningserver/utils/registry.py is in python3-maas-provisioningserver 2.4.0~beta2-6865-gec43e47e6-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | # Copyright 2014-2016 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Registry base class for registry singletons."""
__all__ = [
"Registry",
]
from collections import defaultdict
_registry = defaultdict(dict)
class RegistryType(type):
"""This exists to subvert ``type``'s builtins."""
def __getitem__(cls, name):
return _registry[cls][name]
def __contains__(cls, name):
return name in _registry[cls]
def __iter__(cls):
return iter(_registry[cls].items())
def get_item(cls, name, default=None):
return _registry[cls].get(name, default)
def register_item(cls, name, item):
_registry[cls][name] = item
def unregister_item(cls, name):
_registry[cls].pop(name, None)
class Registry(metaclass=RegistryType):
"""Base class for singleton registries."""
|