Example #1
0
    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
Example #2
0
    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
Example #3
0
    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
Example #4
0
    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
Example #5
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
    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