class BaseProvider(ValidateEnumMixin, StrMixin): """ This is a base class for all data providers. """ def __init__(self, locale: Optional[str] = None, seed: Optional[int] = None) -> None: """Base constructor for all providers. :param str locale: Current locale. Default is 'en'. :param int seed: Seed to all the random functions. Default is 'None'. """ self.seed = seed self.random = Random() self.locale = setup_locale(locale) if seed is not None: self.random.seed(self.seed) def get_current_locale(self) -> str: """Current locale of provider. ..Note: Default for all providers is locale ``en``. """ return self.locale
class BaseProvider(object): """This is a base class for all providers.""" def __init__(self, locale=None, seed=None): """Base constructor for all providers. :param locale: Current locale. Default is 'en'. :param seed: Seed to all the random functions. Default is 'None'. """ if not locale: self.locale = DEFAULT_LOCALE else: self.locale = locale self.seed = seed self.random = Random() if seed is not None: self.random.seed(self.seed) def __str__(self): return '{}:{}:{}'.format( self.__class__.__name__, self.locale, locale_info(self.locale), )
class BaseProvider(object): """This is a base class for all providers.""" def __init__(self, seed: Optional[Seed] = None) -> None: """Initialize attributes. :param seed: Seed for random. """ self.seed = seed self.random = Random() if seed is not None: self.random.seed(self.seed) def _validate_enum(self, item: Any, enum: Any) -> Any: """Validate enum parameter of method in subclasses of BaseProvider. :param item: Item of enum object. :param enum: Enum object. :return: Value of item. :raises NonEnumerableError: if ``item`` not in ``enum``. """ if item is None: result = get_random_item(enum, self.random) elif item and isinstance(item, enum): result = item else: raise NonEnumerableError(enum) return result.value
def __init__(self, seed: Optional[Seed] = None) -> None: """Initialize attributes. :param seed: Seed for random. """ self.seed = seed self.random = Random() if seed is not None: self.random.seed(self.seed)
def __init__(self, locale: str = '', seed: Optional[int] = None) -> None: """Base constructor for all providers. :param str locale: Current locale. Default is 'en'. :param int seed: Seed to all the random functions. Default is 'None'. """ self.seed = seed self.random = Random() self.locale = setup_locale(locale) if seed is not None: self.random.seed(self.seed)
class BaseProvider(object): """This is a base class for all providers.""" def __init__(self, seed: Optional[Seed] = None) -> None: """Initialize attributes. :param seed: Seed for random. When set to `None` the current system time is used. """ self.seed = seed self.random = random if seed is not None: self.reseed(seed) def reseed(self, seed: Optional[Seed] = None) -> None: """Reseed the internal random generator. In case we use the default seed, we need to create a per instance random generator, in this case two providers with the same seed will always return the same values. :param seed: Seed for random. When set to `None` the current system time is used. """ if self.random is random: self.random = Random() self.seed = seed self.random.seed(self.seed) def _validate_enum(self, item: Any, enum: Any) -> Any: """Validate enum parameter of method in subclasses of BaseProvider. :param item: Item of enum object. :param enum: Enum object. :return: Value of item. :raises NonEnumerableError: if ``item`` not in ``enum``. """ if item is None: result = get_random_item(enum, self.random) elif item and isinstance(item, enum): result = item else: raise NonEnumerableError(enum) return result.value def __str__(self) -> str: """Human-readable representation of locale.""" return self.__class__.__name__
def reseed(self, seed: Optional[Seed] = None) -> None: """Reseed the internal random generator. In case we use the default seed, we need to create a per instance random generator, in this case two providers with the same seed will always return the same values. :param seed: Seed for random. When set to `None` the current system time is used. """ if self.random is random: self.random = Random() self.seed = seed self.random.seed(self.seed)
def __init__(self, locale=None, seed=None): """Base constructor for all providers. :param locale: Current locale. Default is 'en'. :param seed: Seed to all the random functions. Default is 'None'. """ if not locale: self.locale = DEFAULT_LOCALE else: self.locale = locale self.seed = seed self.random = Random() if seed is not None: self.random.seed(self.seed)
class BaseProvider(object): """This is a base class for all providers.""" def __init__(self, locale: str = '', seed: Optional[int] = None) -> None: """Base constructor for all providers. :param str locale: Current locale. Default is 'en'. :param int seed: Seed to all the random functions. Default is 'None'. """ self.seed = seed self.random = Random() self.locale = setup_locale(locale) if seed is not None: self.random.seed(self.seed) def __str__(self) -> str: return '{}:{}:{}'.format( self.__class__.__name__, self.locale, locale_info(self.locale), )
def random(): return Random()