Пример #1
0
 def get(self, what, default=internal.raiseOnMissing):
     binds = self._bindings.get(what)
     if not binds:
         if internal.raiseOnMissing == default:
             raise InjectionError("'%s' not bound" % (internal.className(what)))
         return default
     elif len(binds) > 1:
         raise InjectionError("Get is ambiguous, '%s' has multiple bindings"
                              % (internal.className(what)))
     return binds[0]
Пример #2
0
 def checkCyclic(self):
     ctx = self.parent
     while ctx:
         if self.resolving.type == ctx.resolving.type:
             raise DeepInjectionError("Cyclic dependency on '%s'"
                                      % (internal.className(self.resolving.type)), self)
         ctx = ctx.parent
Пример #3
0
 def __init__(self, val, scope):
     self.value = val
     self.scope = scope
     self.activator = ActivatorFactory.getClassActivator(val)
     if val.__init__ != object.__init__ \
             and len(inspect.getargspec(val.__init__).args) != 1 \
             and not hasattr(val.__init__, internal.INJECT_ATTR):
         raise InjectionError("'%s' has non-trivial ctor so should be decorated with @inject"
                              % (internal.className(val)))
Пример #4
0
    def getPath(self, ctx, while_resolving):
        path = self.getPathElems(ctx, while_resolving)

        ret = []
        for i, (ip, binding) in enumerate(path):
            ct = internal.className(ip.type)
            mult = '*' if ip.multi else ''
            resolv = " as '%s'" % (binding) if binding else ''
            ret.append("%d. Resolving %s%s%s" % (i + 1, ct, mult, resolv))
        return '\n'.join(ret)
Пример #5
0
 def __str__(self):
     st = internal.className(self.type)
     return "inject_param: %s" % (st if not self.multi else "(%s)*" % (st))
Пример #6
0
 def __str__(self):
     return "class binding: %s [%s]" % (internal.className(self.value), self.scope.__class__.__name__)