/usr/lib/python2.7/dist-packages/provisioningserver/utils/registry.py is in python-maas-provisioningserver 1.5+bzr2252-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 40 41 42 43 44 45 46 47 48 49 50 | # Copyright 2014 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."""
from __future__ import (
absolute_import,
print_function,
unicode_literals,
)
str = None
__metaclass__ = type
__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 _registry[cls].iteritems()
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:
"""Base class for singleton registries."""
__metaclass__ = RegistryType
|