Source code for ascetic_ddd.faker.domain.distributors.m2o.interfaces

import typing
from abc import ABCMeta, abstractmethod

from ascetic_ddd.observable.interfaces import IObservable
from ascetic_ddd.session.interfaces import ISession
from ascetic_ddd.faker.domain.specification.interfaces import ISpecification

__all__ = (
    'IM2ODistributor',
    'IM2ODistributorFactory',
    'ICursor',
    'IExternalSource',
)


T = typing.TypeVar("T", covariant=True)


[docs] @typing.runtime_checkable class IExternalSource(IObservable, typing.Protocol[T]): ...
[docs] class IM2ODistributor(IObservable, typing.Generic[T], metaclass=ABCMeta):
[docs] @abstractmethod async def next( self, session: ISession, # To get Redis connect from it. specification: ISpecification[T] | None = None, ) -> T: """ Returns next value from distribution. Raises ICursor(num) when mean is reached, signaling caller to create new value. num is sequence position (for SequenceDistributor) or None. """ raise NotImplementedError
[docs] @abstractmethod async def append(self, session: ISession, value: T): """ Appends value to the distributor. """ raise NotImplementedError
@property @abstractmethod def provider_name(self): raise NotImplementedError @provider_name.setter @abstractmethod def provider_name(self, value): raise NotImplementedError
[docs] @abstractmethod async def setup(self, session: ISession): raise NotImplementedError
[docs] @abstractmethod async def cleanup(self, session: ISession): raise NotImplementedError
@abstractmethod def __copy__(self): raise NotImplementedError @abstractmethod def __deepcopy__(self, memodict={}): raise NotImplementedError
[docs] @abstractmethod def bind_external_source(self, external_source: typing.Any) -> None: """Binds an external data source (repository).""" raise NotImplementedError
[docs] class ICursor(typing.Generic[T], StopAsyncIteration, metaclass=ABCMeta): @property @abstractmethod def position(self): raise NotImplementedError
[docs] @abstractmethod async def append(self, session: ISession, value: T): raise NotImplementedError
[docs] class IM2ODistributorFactory(typing.Protocol[T]): def __call__( self, weights: list[float] | None = None, skew: float | None = None, mean: float | None = None, null_weight: float = 0, sequence: bool = False, ) -> IM2ODistributor[T]: """ Factory for Distributor. Args: weights: If a weights sequence is specified, selections are made according to the relative weights. skew: Skew parameter (1.0 = uniform, 2.0+ = skewed towards the beginning). Default = 2.0 mean: Average number of uses for each value. null_weight: Probability of returning None (0-1) sequence: Pass sequence number to value generator. """ ...