How to use the omniduct.duct.Duct function in omniduct

To help you get started, we’ve selected a few omniduct examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github airbnb / omniduct / omniduct / caches / base.py View on Github external
# destructive (e.g. reading from cursors)
            return _cache.get(
                _key,
                namespace=_namespace,
                serializer=_serializer
            )
        except:
            logger.warning("Failed to save results to cache. If needed, please save them manually.")
            if config.cache_fail_hard:
                six.reraise(*sys.exc_info())
            return value  # As a last resort, return value object (which could be mutated by serialization).

    return wrapped


class Cache(Duct):
    """
    An abstract class providing the common API for all cache clients.
    """

    DUCT_TYPE = Duct.Type.CACHE

    @quirk_docs('_init', mro=True)
    def __init__(self, **kwargs):
        Duct.__init_with_kwargs__(self, kwargs)
        self._init(**kwargs)

    @abstractmethod
    def _init(self):
        pass

    # Data insertion and retrieval
github airbnb / omniduct / omniduct / duct.py View on Github external
def __init_with_kwargs__(cls, self, kwargs, **fallbacks):
        if not hasattr(self, '_Duct__inited_using_kwargs'):
            self._Duct__inited_using_kwargs = {}
        for cls_parent in reversed([
                parent for parent in inspect.getmro(cls)
                if issubclass(parent, Duct)
                and parent not in self._Duct__inited_using_kwargs
                and '__init__' in parent.__dict__
        ]):
            self._Duct__inited_using_kwargs[cls_parent] = True
            if six.PY3:
                argspec = inspect.getfullargspec(cls_parent.__init__)
                keys = argspec.args[1:] + argspec.kwonlyargs
            else:
                keys = inspect.getargspec(cls_parent.__init__).args[1:]
            params = {}
            for key in keys:
                if key in kwargs:
                    params[key] = kwargs.pop(key)
                elif key in fallbacks:
                    params[key] = fallbacks[key]
            cls_parent.__init__(self, **params)