minor codestyle fixes

This commit is contained in:
Roman Mogilatov 2015-03-10 11:51:13 +02:00
parent 259832bc75
commit 3b37476d23
2 changed files with 63 additions and 37 deletions

View File

@ -1,16 +1,43 @@
"""Objects.""" """Objects."""
from .catalog import AbstractCatalog, overrides from .catalog import AbstractCatalog, overrides
from .providers import (Provider, NewInstance, Singleton, Class, Object,
Function, Value) from .providers import Provider
from .injections import InitArg, Attribute, Method from .providers import ProviderDelegate
from .providers import NewInstance
from .providers import Singleton
from .providers import Scoped
from .providers import ExternalDependency
from .providers import Class
from .providers import Object
from .providers import Function
from .providers import Value
from .providers import Callable
from .providers import Config
from .injections import InitArg
from .injections import Attribute
from .injections import Method
__all__ = ('AbstractCatalog', 'overrides', __all__ = ('AbstractCatalog',
'overrides',
# Providers # Providers
'Provider', 'NewInstance', 'Singleton', 'Class', 'Provider',
'Object', 'Function', 'Value', 'ProviderDelegate',
'NewInstance',
'Singleton',
'Scoped',
'ExternalDependency',
'Class',
'Object',
'Function',
'Value',
'Callable',
'Config',
# Injections # Injections
'InitArg', 'Attribute', 'Method') 'InitArg',
'Attribute',
'Method')

View File

@ -1,12 +1,11 @@
"""Standard providers.""" """Standard providers."""
from collections import Iterable from collections import Iterable
from .injections import (
Injection, from .injections import Injection
InitArg, from .injections import InitArg
Attribute, from .injections import Attribute
Method, from .injections import Method
)
class Provider(object): class Provider(object):
@ -249,29 +248,6 @@ class Callable(Provider):
return self.calls(*args, **injections) return self.calls(*args, **injections)
class _DeferredConfig(Provider):
"""Deferred config provider.
Deferred config providers provide an value from the root config object.
"""
def __init__(self, paths, root_config):
"""Initializer."""
self.paths = paths
self.root_config = root_config
super(_DeferredConfig, self).__init__()
def __getattr__(self, item):
"""Return instance of deferred config."""
return _DeferredConfig(paths=self.paths + (item,),
root_config=self.root_config)
def __call__(self, *args, **kwargs):
"""Return provided instance."""
return self.root_config(self.paths)
class Config(Provider): class Config(Provider):
"""Config provider. """Config provider.
@ -302,7 +278,30 @@ class Config(Provider):
if paths: if paths:
for path in paths: for path in paths:
value = value[path] value = value[path]
return value return value
class _DeferredConfig(Provider):
"""Deferred config provider.
Deferred config providers provide an value from the root config object.
"""
def __init__(self, paths, root_config):
"""Initializer."""
self.paths = paths
self.root_config = root_config
super(_DeferredConfig, self).__init__()
def __getattr__(self, item):
"""Return instance of deferred config."""
return _DeferredConfig(paths=self.paths + (item,),
root_config=self.root_config)
def __call__(self, *args, **kwargs):
"""Return provided instance."""
return self.root_config(self.paths)
def _fetch_injections(injections, injection_type): def _fetch_injections(injections, injection_type):