Esempio n. 1
0
    def getGenerator(cls, locale=None, providers=None, codename=None):
        """
        use a codename to cache generators
        """

        codename = codename or cls.getCodename(locale, providers)

        if codename not in cls.generators:
            from faker import Faker as FakerGenerator
            # initialize with faker.generator.Generator instance
            # and remember in cache
            cls.generators[codename] = FakerGenerator(locale, providers)
            cls.generators[codename].seed(cls.generators[codename].random_int())

        return cls.generators[codename]
Esempio n. 2
0
    def get_generator(cls, locale=None, providers=None, codename=None, seed=None):
        """
        use a codename to cache generators
        """

        codename = codename or cls.get_codename(locale, providers, seed)

        # Refresh if seed given
        if codename not in cls.generators or seed is not None:
            # initialize with faker.generator.Generator instance
            # and remember in cache
            from faker import Faker as FakerGenerator
            cls.generators[codename] = FakerGenerator(locale, providers)
            if seed is None:
                seed = cls.generators[codename].random_int()
            cls.generators[codename].seed(seed)

        return cls.generators[codename]