python-dependency-injector/objects/catalog.py

33 lines
839 B
Python
Raw Normal View History

2015-01-04 14:26:33 +00:00
"""
Catalog module.
"""
2015-01-11 13:03:45 +00:00
from .providers import Provider
2015-01-04 14:26:33 +00:00
class Catalog(object):
"""
Object provides catalog.
"""
def __init__(self, *used_providers):
"""
Initializer.
"""
self._clean_unused_providers(used_providers)
def _clean_unused_providers(self, used_providers):
"""
Sets every catalog's provider in None except of `used_providers` list.
:param list|tuple|set used_providers:
:return:
"""
used_providers = set(used_providers)
for attribute_name in set(dir(self.__class__)) - set(dir(Catalog)):
provider = getattr(self, attribute_name)
if not isinstance(provider, Provider):
continue
if provider not in used_providers:
setattr(self, attribute_name, None)