mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-25 02:53:56 +03:00
adding positional arg numbers for Python 2.6 compatibility
This commit is contained in:
parent
c13c2ad6eb
commit
87fc17284c
|
@ -21,7 +21,7 @@ class AbstractCatalog(object):
|
||||||
return attribute
|
return attribute
|
||||||
|
|
||||||
if attribute not in self.__used_providers__:
|
if attribute not in self.__used_providers__:
|
||||||
raise Error('Provider \'{}\' '.format(item) +
|
raise Error('Provider \'{0}\' '.format(item) +
|
||||||
'is not listed in dependencies')
|
'is not listed in dependencies')
|
||||||
return attribute
|
return attribute
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ class Provider(object):
|
||||||
try:
|
try:
|
||||||
return self.overridden[-1]
|
return self.overridden[-1]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
raise Error('Provider {} '.format(str(self)) +
|
raise Error('Provider {0} '.format(str(self)) +
|
||||||
'is not overridden')
|
'is not overridden')
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ class NewInstance(Provider):
|
||||||
"""Initializer."""
|
"""Initializer."""
|
||||||
if not isclass(provides):
|
if not isclass(provides):
|
||||||
raise Error('NewInstance provider expects to get class, ' +
|
raise Error('NewInstance provider expects to get class, ' +
|
||||||
'got {} instead'.format(str(provides)))
|
'got {0} instead'.format(str(provides)))
|
||||||
self.provides = provides
|
self.provides = provides
|
||||||
self.init_args = tuple((injection
|
self.init_args = tuple((injection
|
||||||
for injection in injections
|
for injection in injections
|
||||||
|
@ -160,12 +160,12 @@ class Scoped(NewInstance):
|
||||||
del self.scopes_to_instances[scope]
|
del self.scopes_to_instances[scope]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise Error('Trying to move out of undefined scope '
|
raise Error('Trying to move out of undefined scope '
|
||||||
'"{}"'.format(scope))
|
'"{0}"'.format(scope))
|
||||||
|
|
||||||
def __call__(self, *args, **kwargs):
|
def __call__(self, *args, **kwargs):
|
||||||
"""Return provided instance."""
|
"""Return provided instance."""
|
||||||
if not self.current_scope:
|
if not self.current_scope:
|
||||||
raise Error('Trying to provide {} '.format(self.provides) +
|
raise Error('Trying to provide {0} '.format(self.provides) +
|
||||||
'while provider has no active scope')
|
'while provider has no active scope')
|
||||||
try:
|
try:
|
||||||
instance = self.scopes_to_instances[self.current_scope]
|
instance = self.scopes_to_instances[self.current_scope]
|
||||||
|
@ -199,8 +199,8 @@ class ExternalDependency(Provider):
|
||||||
instance = self.dependency.__call__(*args, **kwargs)
|
instance = self.dependency.__call__(*args, **kwargs)
|
||||||
|
|
||||||
if not isinstance(instance, self.instance_of):
|
if not isinstance(instance, self.instance_of):
|
||||||
raise Error('{} is not an '.format(instance) +
|
raise Error('{0} is not an '.format(instance) +
|
||||||
'instance of {}'.format(self.instance_of))
|
'instance of {0}'.format(self.instance_of))
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
@ -260,7 +260,7 @@ class Callable(Provider):
|
||||||
def __init__(self, callback, *injections):
|
def __init__(self, callback, *injections):
|
||||||
"""Initializer."""
|
"""Initializer."""
|
||||||
if not callable(callback):
|
if not callable(callback):
|
||||||
raise Error('Callable expected, got {}'.format(str(callback)))
|
raise Error('Callable expected, got {0}'.format(str(callback)))
|
||||||
self.callback = callback
|
self.callback = callback
|
||||||
self.injections = tuple((injection
|
self.injections = tuple((injection
|
||||||
for injection in injections
|
for injection in injections
|
||||||
|
@ -314,7 +314,7 @@ class Config(Provider):
|
||||||
value = value[path]
|
value = value[path]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise Error('Config key '
|
raise Error('Config key '
|
||||||
'"{}" is undefined'.format('.'.join(paths)))
|
'"{0}" is undefined'.format('.'.join(paths)))
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ def ensure_is_provider(instance):
|
||||||
"""Check if instance is provider instance, otherwise raise and error."""
|
"""Check if instance is provider instance, otherwise raise and error."""
|
||||||
if not is_provider(instance):
|
if not is_provider(instance):
|
||||||
raise Error('Expected provider instance, '
|
raise Error('Expected provider instance, '
|
||||||
'got {}'.format(str(instance)))
|
'got {0}'.format(str(instance)))
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user