<commit_before>from __future__ import unicode_literals
from __future__ import absolute_import
import sys
from faker import DEFAULT_LOCALE, DEFAULT_PROVIDERS, AVAILABLE_LOCALES
from faker import Generator
from faker import providers as providers_mod


class Factory(object):

    @classmethod
    def create(cls, locale=None, providers=None, generator=None, **config):

        # fix locale to package name
        locale = locale.replace('-', '_') if locale else DEFAULT_LOCALE
        if '_' in locale:
            locale = locale[:2] + locale[2:].upper()
        if locale not in AVAILABLE_LOCALES:
            raise AttributeError('Invalid configuration for faker locale "{0}"'.format(locale))

        providers = providers or DEFAULT_PROVIDERS

        faker = generator or Generator(**config)<commit_msg>Normalize locale names. Close #103<commit_after>from __future__ import unicode_literals
from __future__ import absolute_import
import locale as pylocale
import sys
from faker import DEFAULT_LOCALE, DEFAULT_PROVIDERS, AVAILABLE_LOCALES
from faker import Generator
from faker import providers as providers_mod


class Factory(object):

    @classmethod
    def create(cls, locale=None, providers=None, generator=None, **config):

        # fix locale to package name
        locale = locale.replace('-', '_') if locale else DEFAULT_LOCALE
        locale = pylocale.normalize(locale).split('.')[0]
        if locale not in AVAILABLE_LOCALES:
            raise AttributeError('Invalid configuration for faker locale "{0}"'.format(locale))

        providers = providers or DEFAULT_PROVIDERS

        faker = generator or Generator(**config)
{'fraction_non_alphanumeric': 0.07776427703523693, 'fraction_numerical': 0.004860267314702308, 'mean_word_length': 3.960843373493976, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5239037', 'n_tokens_mistral': 442, 'n_tokens_neox': 428, 'n_words': 147}