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]
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
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)))
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)
def __str__(self): st = internal.className(self.type) return "inject_param: %s" % (st if not self.multi else "(%s)*" % (st))
def __str__(self): return "class binding: %s [%s]" % (internal.className(self.value), self.scope.__class__.__name__)