PK!hV88injectark/__init__.pyfrom .injectark import Injectark __version__ = "0.2.0" PK!RAAinjectark/injectark.pyfrom inspect import signature from typing import Any, Dict class Injectark: def __init__(self, strategy=None, factory=None, parent=None) -> None: self.parent = parent self.factory = factory self.strategy = strategy self.registry = {} # type: Dict[str, Any] def resolve(self, resource: str): fetched = self._registry_fetch(resource) if fetched: return fetched persist = not self.strategy.get(resource, {}).get('ephemeral', False) instance = self._dependency_build(resource, persist) return instance def forge(self, strategy, factory): return Injectark(parent=self, strategy=strategy, factory=factory) def _registry_fetch(self, resource: str): fetched = False rule = self.strategy.get(resource, {}) if rule.get('unique'): return fetched if resource in self.registry: fetched = self.registry[resource] else: parent = self.parent fetched = parent._registry_fetch(resource) if parent else False return fetched def _dependency_build(self, resource: str, persist=True): instance = None rule = self.strategy.get(resource, {'method': ''}) builder = self.factory.extract(rule['method']) if builder: dependencies = [ value.annotation.__name__ for key, value in signature(builder).parameters.items() if key != 'return'] dependency_instances = [] for dependency in dependencies: dependency_instance = self.resolve(dependency) dependency_instances.append(dependency_instance) instance = builder(*dependency_instances) else: instance = (self.parent._dependency_build(resource, persist) if self.parent else instance) persist = (persist and self.strategy.get( resource, {}).get('unique', False)) if persist: self.registry[resource] = instance return instance PK!)((!injectark-0.2.0.dist-info/LICENSEMIT License Copyright (c) 2019 knowark Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HڽTUinjectark-0.2.0.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!HwZ"injectark-0.2.0.dist-info/METADATAN]O1|5|L5|DDrTh{n$ }aݙٙYP%6㝂-)0t|d_e_ȭ'ɕt 3Ҭfx)fsɅ,W1I N^,_mj">a 9FH{w7!d{`aROTvwJWW]SNNѵz9V|PK!HI% injectark-0.2.0.dist-info/RECORD}B@{2iqfJ uF5 j"Tn%;FIBKZ'p{L$ErY4o𖅼jۄGüƖF ~PK!hV88injectark/__init__.pyPK!RAAkinjectark/injectark.pyPK!)((!injectark-0.2.0.dist-info/LICENSEPK!HڽTUG injectark-0.2.0.dist-info/WHEELPK!HwZ" injectark-0.2.0.dist-info/METADATAPK!HI% injectark-0.2.0.dist-info/RECORDPK]