コード例 #1
0
ファイル: factory.py プロジェクト: jruffing/faker
    def _find_provider_class(cls, provider, locale=None):
        providers_mod_name = providers_mod.__package__ or providers_mod.__name__

        path = "{providers}.{provider}".format(providers=providers_mod_name,
                                               provider=provider)

        provider_module = import_module(path)
        if getattr(provider_module, 'localized', False):
            available_locales = list_module(provider_module)
            if not locale or locale not in available_locales:
                locale = getattr(provider_module, 'default_locale',
                                 DEFAULT_LOCALE)

            path = "{providers}.{provider}.{locale}".format(
                providers=providers_mod_name, locale=locale, provider=provider)
            provider_module = import_module(path)
        else:
            if locale is not None:

                path = "{providers}.{locale}.{provider}".format(
                    providers=providers_mod_name,
                    locale=locale,
                    provider=provider)
                try:
                    provider_module = import_module(path)
                except ImportError:
                    path = "{providers}.{provider}".format(
                        providers=providers_mod_name, provider=provider)
                    provider_module = import_module(path)

        return provider_module.Provider
コード例 #2
0
ファイル: factory.py プロジェクト: Brobin/faker
    def _find_provider_class(cls, provider, locale=None):
        providers_mod_name = providers_mod.__package__ or providers_mod.__name__
 
        path = "{providers}.{provider}".format(
            providers=providers_mod_name,
            provider=provider
        )

        provider_module = import_module(path)
        if getattr(provider_module, 'localized', False):
            available_locales = list_module(provider_module)
            if not locale or locale not in available_locales:
                locale = getattr(provider_module, 'default_locale', DEFAULT_LOCALE)

            path = "{providers}.{provider}.{locale}".format(
                providers=providers_mod_name,
                locale=locale,
                provider=provider
            )
            provider_module = import_module(path)
        else:
            if locale is not None:
                path = "{providers}.{provider}".format(
                    providers=providers_mod_name,
                    provider=provider
                )
                provider_module = import_module(path)

        return provider_module.Provider
コード例 #3
0
ファイル: factory.py プロジェクト: 4sp1r3/faker
    def _find_provider_class(cls, provider_path, locale=None):
        provider_module = import_module(provider_path)

        if getattr(provider_module, 'localized', False):
            available_locales = list_module(provider_module)
            if not locale or locale not in available_locales:
                locale = getattr(provider_module, 'default_locale', DEFAULT_LOCALE)

            path = "{provider_path}.{locale}".format(
                provider_path=provider_path,
                locale=locale,
            )
            provider_module = import_module(path)
        else:
            if locale is not None:
                provider_module = import_module(provider_path)

        return provider_module.Provider
コード例 #4
0
ファイル: factory.py プロジェクト: MarekBleschke/faker
    def _find_provider_class(cls, provider_path, locale=None):
        provider_module = import_module(provider_path)

        if getattr(provider_module, 'localized', False):
            available_locales = list_module(provider_module)
            if not locale or locale not in available_locales:
                locale = getattr(provider_module, 'default_locale', DEFAULT_LOCALE)

            path = "{provider_path}.{locale}".format(
                provider_path=provider_path,
                locale=locale,
            )
            provider_module = import_module(path)
        else:
            if locale is not None:
                provider_module = import_module(provider_path)

        return provider_module.Provider
コード例 #5
0
ファイル: factory.py プロジェクト: joke2k/faker
    def _find_provider_class(cls, provider_path, locale=None):

        provider_module = import_module(provider_path)

        if getattr(provider_module, 'localized', False):

            logger.debug('Looking for locale `{}` in provider `{}`.'.format(
                locale, provider_module.__name__))

            available_locales = list_module(provider_module)
            if not locale or locale not in available_locales:
                unavailable_locale = locale
                locale = getattr(
                    provider_module, 'default_locale', DEFAULT_LOCALE)
                logger.debug('Specified locale `{}` is not available for '
                             'provider `{}`. Locale reset to `{}` for this '
                             'provider.'.format(
                                 unavailable_locale, provider_module.__name__, locale),
                             )
            else:
                logger.debug('Provider `{}` has been localized to `{}`.'.format(
                    provider_module.__name__, locale))

            path = "{provider_path}.{locale}".format(
                provider_path=provider_path,
                locale=locale,
            )
            provider_module = import_module(path)

        else:

            logger.debug('Provider `{}` does not feature localization. '
                         'Specified locale `{}` is not utilized for this '
                         'provider.'.format(
                             provider_module.__name__, locale),
                         )

            if locale is not None:
                provider_module = import_module(provider_path)

        return provider_module.Provider
コード例 #6
0
    def _find_provider_class(cls, provider_path, locale=None):

        provider_module = import_module(provider_path)

        if getattr(provider_module, 'localized', False):

            logger.debug('Looking for locale `{}` in provider `{}`.'.format(
                locale, provider_module.__name__))

            available_locales = list_module(provider_module)
            if not locale or locale not in available_locales:
                unavailable_locale = locale
                locale = getattr(provider_module, 'default_locale',
                                 DEFAULT_LOCALE)
                logger.debug(
                    'Specified locale `{}` is not available for '
                    'provider `{}`. Locale reset to `{}` for this '
                    'provider.'.format(unavailable_locale,
                                       provider_module.__name__, locale), )
            else:
                logger.debug(
                    'Provider `{}` has been localized to `{}`.'.format(
                        provider_module.__name__, locale))

            path = "{provider_path}.{locale}".format(
                provider_path=provider_path,
                locale=locale,
            )
            provider_module = import_module(path)

        else:

            logger.debug(
                'Provider `{}` does not feature localization. '
                'Specified locale `{}` is not utilized for this '
                'provider.'.format(provider_module.__name__, locale), )

            if locale is not None:
                provider_module = import_module(provider_path)

        return provider_module.Provider