mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 09:36:48 +03:00
35 lines
845 B
Python
35 lines
845 B
Python
"""Decorators module."""
|
|
|
|
from six import wraps
|
|
|
|
from .utils import ensure_is_injection
|
|
|
|
|
|
def override(catalog):
|
|
"""Catalog overriding decorator."""
|
|
def decorator(overriding_catalog):
|
|
"""Overriding decorator."""
|
|
catalog.override(overriding_catalog)
|
|
return overriding_catalog
|
|
return decorator
|
|
|
|
|
|
def inject(injection):
|
|
"""Inject decorator.
|
|
|
|
:type injection: Injection
|
|
:return: (callable) -> (callable)
|
|
"""
|
|
injection = ensure_is_injection(injection)
|
|
|
|
def decorator(callback):
|
|
"""Decorator."""
|
|
@wraps(callback)
|
|
def decorated(*args, **kwargs):
|
|
"""Decorated."""
|
|
if injection.name not in kwargs:
|
|
kwargs[injection.name] = injection.value
|
|
return callback(*args, **kwargs)
|
|
return decorated
|
|
return decorator
|