def factory(label, manager, *args): ''' factory for manager @param label: label for manager ''' # build manager manager = manager(label) # register things in manager exhaust(starmap(lambda x, y: manager.set(y, x), iter(args))) return manager
def _populate(self, past, future, _map=starmap, _items=items): def _coro(key, value, new=self._new): if isinstance(value, (Mapping, Sequence)): # see if stuf can be converted to nested stuf trial = new(self.default_factory, value) if len(trial) > 0: future[key] = trial else: future[key] = value else: future[key] = value exhaust(_map(_coro, _items(past)))
def _populate(cls, past, future, _is=isinstance, m=starmap, _i=items): def _coro(key, value, new=cls._new, _is=_is): if _is(value, (Sequence, Mapping)) and not _is(value, strings): # see if stuf can be converted to nested stuf trial = new(value) if len(trial) > 0: future[key] = trial else: future[key] = value else: future[key] = value exhaust(m(_coro, _i(past))) return cls._postpopulate(future)
def _key(cls, label, manager): try: # lazily load key key = cls.key if isinstance(key, strings): key = lazyimport(key) # register class key ez_register = manager.ez_register ez_register(ANamespace, label, key) exhaust(imap( lambda x: ez_register(KService, x, label), iter(key.names(True)), )) except AttributeError: key = manager.key(ANamespace, label)