prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Honor Environment LANG
  I am currently using a wrapper for fake-factory to be able to choose the output but it would be great it would become part of fake-factory core.
  
  This is the script i have in my path: https://gist.github.com/makefu/9101269
  
  usage: 
  $ LANG=de_DE.utf-8 faker address
      Davide-Kaul-Weg 175
      94892 Königs Wusterhausen
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `faker/__main__.py`
  Content:
  ```
  1 from __future__ import unicode_literals
  2 from __future__ import print_function
  3 import sys
  4 
  5 if sys.version < '3':
  6     text_type = unicode
  7     binary_type = str
  8 else:
  9     text_type = str
  10     binary_type = bytes
  11 
  12 
  13 def print_provider(doc, provider, formatters, excludes=None):
  14     if excludes is None:
  15         excludes = []
  16 
  17     print()
  18     print("### faker.providers.{0}".format(doc.get_provider_name(provider)))
  19     print()
  20 
  21     for signature, example in formatters.items():
  22         if signature in excludes:
  23             continue
  24         try:
  25             lines = text_type(example).expandtabs().splitlines()
  26         except UnicodeEncodeError:
  27             raise Exception('error on "{0}" with value "{1}"'.format(signature, example))
  28         margin = max(30, doc.max_name_len+1)
  29         remains = 150 - margin
  30         separator = '#'
  31         for line in lines:
  32             for i in range(0, (len(line) // remains) + 1):
  33                 print("\t{fake:<{margin}}{separator} {example}".format(
  34                     fake=signature,
  35                     separator=separator,
  36                     example=line[i*remains:(i+1)*remains],
  37                     margin=margin
  38                 ))
  39                 signature = separator = ' '
  40 
  41 
  42 def main(provider_or_field=None, *args):
  43     from faker import Faker, Factory, documentor, DEFAULT_LOCALE, AVAILABLE_LOCALES
  44     fake = Faker(locale=DEFAULT_LOCALE)
  45 
  46     from faker.providers import BaseProvider
  47     base_provider_formatters = [f for f in dir(BaseProvider)]
  48 
  49     if provider_or_field:
  50         if '.' in provider_or_field:
  51             parts = provider_or_field.split('.')
  52             locale = parts[-2] if parts[-2] in AVAILABLE_LOCALES else DEFAULT_LOCALE
  53             fake = Factory.create(locale, providers=[parts[-1]])
  54             doc = documentor.Documentor(fake)
  55             doc.already_generated = base_provider_formatters
  56             print_provider(doc, fake.get_providers()[0], doc.get_provider_formatters(fake.get_providers()[0]))
  57         else:
  58             try:
  59                 print(fake.format(provider_or_field, *args))
  60             except AttributeError:
  61                 print('No faker found for "{0}({1})"'.format(provider_or_field, args))
  62 
  63     else:
  64         doc = documentor.Documentor(fake)
  65 
  66         formatters = doc.get_formatters(with_args=True, with_defaults=True)
  67 
  68         for provider, fakers in formatters:
  69 
  70             print_provider(doc, provider, fakers)
  71 
  72         for lang in AVAILABLE_LOCALES:
  73             if lang == DEFAULT_LOCALE:
  74                 continue
  75             print()
  76             print('## LANGUAGE {0}'.format(lang))
  77             fake = Faker(locale=lang)
  78             d = documentor.Documentor(fake)
  79 
  80             for p, fs in d.get_formatters(with_args=True, with_defaults=True, locale=lang,
  81                                           excludes=base_provider_formatters):
  82                 print_provider(d, p, fs)
  83 
  84 
  85 if __name__ == "__main__":
  86     if sys.stdout.encoding is None:
  87         print("please set python env PYTHONIOENCODING=UTF-8, example: "
  88               "export PYTHONIOENCODING=UTF-8, when write to stdout", file=sys.stderr)
  89         exit(1)
  90     main(*sys.argv[1:])
  ```
  
  Path: `setup.py`
  Content:
  ```
  1 #!/usr/bin/env python
  2 
  3 import os
  4 from setuptools import setup, find_packages
  5 
  6 here = os.path.abspath(os.path.dirname(__file__))
  7 README = open(os.path.join(here, 'README.md')).read()
  8 NEWS = open(os.path.join(here, 'NEWS.txt')).read()
  9 
  10 
  11 version = '0.3.2'
  12 
  13 setup(name='fake-factory',
  14       version=version,
  15       description="Faker is a Python package that generates fake data for you.",
  16       long_description=README + '\n\n' + NEWS,
  17       classifiers=[
  18           # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
  19           'Development Status :: 3 - Alpha',
  20           'Environment :: Console',
  21           'Intended Audience :: Developers',
  22           'Programming Language :: Python',
  23           'Programming Language :: Python :: 2',
  24           'Programming Language :: Python :: 3',
  25           'Topic :: Software Development :: Libraries :: Python Modules',
  26           'Topic :: Software Development :: Testing',
  27           'Topic :: Utilities',
  28           'License :: OSI Approved :: MIT License'
  29       ],
  30       keywords='faker fixtures data test mock generator',
  31       author='joke2k',
  32       author_email='joke2k@gmail.com',
  33       url='http://github.com/joke2k/faker',
  34       license='MIT License',
  35       packages=find_packages(exclude=['*.tests']),
  36       platforms=["any"],
  37       test_suite='faker.tests',
  38       )
  39
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/faker/__main__.py b/faker/__main__.py
  --- a/faker/__main__.py
  +++ b/faker/__main__.py
  @@ -1,5 +1,9 @@
   from __future__ import unicode_literals
   from __future__ import print_function
  +
  +from faker import Faker, Factory, documentor, AVAILABLE_LOCALES, DEFAULT_LOCALE
  +
  +import os
   import sys
   
   if sys.version < '3':
  @@ -40,7 +44,6 @@
   
   
   def main(provider_or_field=None, *args):
  -    from faker import Faker, Factory, documentor, DEFAULT_LOCALE, AVAILABLE_LOCALES
       fake = Faker(locale=DEFAULT_LOCALE)
   
       from faker.providers import BaseProvider
  @@ -82,6 +85,28 @@
                   print_provider(d, p, fs)
   
   
  +def command(*args):
  +    try:
  +        f = args[0]
  +    except IndexError:
  +        f = '--help'
  +
  +    if f in ["--help", "-h"]:
  +        main()
  +        sys.exit()
  +
  +    locale = os.environ['LANG'].split('.')[0]
  +     
  +    if locale not in AVAILABLE_LOCALES:
  +        locale = DEFAULT_LOCALE
  +    fake = Faker(locale=locale)
  +
  +    try:
  +        print(fake.format(f, *args[1:]))
  +    except AttributeError:
  +        print('No faker found for "{0}"'.format(f))
  +
  +
   if __name__ == "__main__":
       if sys.stdout.encoding is None:
           print("please set python env PYTHONIOENCODING=UTF-8, example: "
  diff --git a/setup.py b/setup.py
  --- a/setup.py
  +++ b/setup.py
  @@ -14,6 +14,7 @@
         version=version,
         description="Faker is a Python package that generates fake data for you.",
         long_description=README + '\n\n' + NEWS,
  +      scripts=['bin/faker'],
         classifiers=[
             # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
             'Development Status :: 3 - Alpha',
  
verification_info: {"golden_diff": "diff --git a/faker/__main__.py b/faker/__main__.py\n--- a/faker/__main__.py\n+++ b/faker/__main__.py\n@@ -1,5 +1,9 @@\n from __future__ import unicode_literals\n from __future__ import print_function\n+\n+from faker import Faker, Factory, documentor, AVAILABLE_LOCALES, DEFAULT_LOCALE\n+\n+import os\n import sys\n \n if sys.version < '3':\n@@ -40,7 +44,6 @@\n \n \n def main(provider_or_field=None, *args):\n-    from faker import Faker, Factory, documentor, DEFAULT_LOCALE, AVAILABLE_LOCALES\n     fake = Faker(locale=DEFAULT_LOCALE)\n \n     from faker.providers import BaseProvider\n@@ -82,6 +85,28 @@\n                 print_provider(d, p, fs)\n \n \n+def command(*args):\n+    try:\n+        f = args[0]\n+    except IndexError:\n+        f = '--help'\n+\n+    if f in [\"--help\", \"-h\"]:\n+        main()\n+        sys.exit()\n+\n+    locale = os.environ['LANG'].split('.')[0]\n+     \n+    if locale not in AVAILABLE_LOCALES:\n+        locale = DEFAULT_LOCALE\n+    fake = Faker(locale=locale)\n+\n+    try:\n+        print(fake.format(f, *args[1:]))\n+    except AttributeError:\n+        print('No faker found for \"{0}\"'.format(f))\n+\n+\n if __name__ == \"__main__\":\n     if sys.stdout.encoding is None:\n         print(\"please set python env PYTHONIOENCODING=UTF-8, example: \"\ndiff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -14,6 +14,7 @@\n       version=version,\n       description=\"Faker is a Python package that generates fake data for you.\",\n       long_description=README + '\\n\\n' + NEWS,\n+      scripts=['bin/faker'],\n       classifiers=[\n           # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers\n           'Development Status :: 3 - Alpha',\n", "issue": "Honor Environment LANG\nI am currently using a wrapper for fake-factory to be able to choose the output but it would be great it would become part of fake-factory core.\n\nThis is the script i have in my path: https://gist.github.com/makefu/9101269\n\nusage: \n$ LANG=de_DE.utf-8 faker address\n    Davide-Kaul-Weg 175\n    94892 K\u00f6nigs Wusterhausen\n\n", "before_files": [{"content": "from __future__ import unicode_literals\nfrom __future__ import print_function\nimport sys\n\nif sys.version < '3':\n    text_type = unicode\n    binary_type = str\nelse:\n    text_type = str\n    binary_type = bytes\n\n\ndef print_provider(doc, provider, formatters, excludes=None):\n    if excludes is None:\n        excludes = []\n\n    print()\n    print(\"### faker.providers.{0}\".format(doc.get_provider_name(provider)))\n    print()\n\n    for signature, example in formatters.items():\n        if signature in excludes:\n            continue\n        try:\n            lines = text_type(example).expandtabs().splitlines()\n        except UnicodeEncodeError:\n            raise Exception('error on \"{0}\" with value \"{1}\"'.format(signature, example))\n        margin = max(30, doc.max_name_len+1)\n        remains = 150 - margin\n        separator = '#'\n        for line in lines:\n            for i in range(0, (len(line) // remains) + 1):\n                print(\"\\t{fake:<{margin}}{separator} {example}\".format(\n                    fake=signature,\n                    separator=separator,\n                    example=line[i*remains:(i+1)*remains],\n                    margin=margin\n                ))\n                signature = separator = ' '\n\n\ndef main(provider_or_field=None, *args):\n    from faker import Faker, Factory, documentor, DEFAULT_LOCALE, AVAILABLE_LOCALES\n    fake = Faker(locale=DEFAULT_LOCALE)\n\n    from faker.providers import BaseProvider\n    base_provider_formatters = [f for f in dir(BaseProvider)]\n\n    if provider_or_field:\n        if '.' in provider_or_field:\n            parts = provider_or_field.split('.')\n            locale = parts[-2] if parts[-2] in AVAILABLE_LOCALES else DEFAULT_LOCALE\n            fake = Factory.create(locale, providers=[parts[-1]])\n            doc = documentor.Documentor(fake)\n            doc.already_generated = base_provider_formatters\n            print_provider(doc, fake.get_providers()[0], doc.get_provider_formatters(fake.get_providers()[0]))\n        else:\n            try:\n                print(fake.format(provider_or_field, *args))\n            except AttributeError:\n                print('No faker found for \"{0}({1})\"'.format(provider_or_field, args))\n\n    else:\n        doc = documentor.Documentor(fake)\n\n        formatters = doc.get_formatters(with_args=True, with_defaults=True)\n\n        for provider, fakers in formatters:\n\n            print_provider(doc, provider, fakers)\n\n        for lang in AVAILABLE_LOCALES:\n            if lang == DEFAULT_LOCALE:\n                continue\n            print()\n            print('## LANGUAGE {0}'.format(lang))\n            fake = Faker(locale=lang)\n            d = documentor.Documentor(fake)\n\n            for p, fs in d.get_formatters(with_args=True, with_defaults=True, locale=lang,\n                                          excludes=base_provider_formatters):\n                print_provider(d, p, fs)\n\n\nif __name__ == \"__main__\":\n    if sys.stdout.encoding is None:\n        print(\"please set python env PYTHONIOENCODING=UTF-8, example: \"\n              \"export PYTHONIOENCODING=UTF-8, when write to stdout\", file=sys.stderr)\n        exit(1)\n    main(*sys.argv[1:])", "path": "faker/__main__.py"}, {"content": "#!/usr/bin/env python\n\nimport os\nfrom setuptools import setup, find_packages\n\nhere = os.path.abspath(os.path.dirname(__file__))\nREADME = open(os.path.join(here, 'README.md')).read()\nNEWS = open(os.path.join(here, 'NEWS.txt')).read()\n\n\nversion = '0.3.2'\n\nsetup(name='fake-factory',\n      version=version,\n      description=\"Faker is a Python package that generates fake data for you.\",\n      long_description=README + '\\n\\n' + NEWS,\n      classifiers=[\n          # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers\n          'Development Status :: 3 - Alpha',\n          'Environment :: Console',\n          'Intended Audience :: Developers',\n          'Programming Language :: Python',\n          'Programming Language :: Python :: 2',\n          'Programming Language :: Python :: 3',\n          'Topic :: Software Development :: Libraries :: Python Modules',\n          'Topic :: Software Development :: Testing',\n          'Topic :: Utilities',\n          'License :: OSI Approved :: MIT License'\n      ],\n      keywords='faker fixtures data test mock generator',\n      author='joke2k',\n      author_email='joke2k@gmail.com',\n      url='http://github.com/joke2k/faker',\n      license='MIT License',\n      packages=find_packages(exclude=['*.tests']),\n      platforms=[\"any\"],\n      test_suite='faker.tests',\n      )\n", "path": "setup.py"}], "after_files": [{"content": "from __future__ import unicode_literals\nfrom __future__ import print_function\n\nfrom faker import Faker, Factory, documentor, AVAILABLE_LOCALES, DEFAULT_LOCALE\n\nimport os\nimport sys\n\nif sys.version < '3':\n    text_type = unicode\n    binary_type = str\nelse:\n    text_type = str\n    binary_type = bytes\n\n\ndef print_provider(doc, provider, formatters, excludes=None):\n    if excludes is None:\n        excludes = []\n\n    print()\n    print(\"### faker.providers.{0}\".format(doc.get_provider_name(provider)))\n    print()\n\n    for signature, example in formatters.items():\n        if signature in excludes:\n            continue\n        try:\n            lines = text_type(example).expandtabs().splitlines()\n        except UnicodeEncodeError:\n            raise Exception('error on \"{0}\" with value \"{1}\"'.format(signature, example))\n        margin = max(30, doc.max_name_len+1)\n        remains = 150 - margin\n        separator = '#'\n        for line in lines:\n            for i in range(0, (len(line) // remains) + 1):\n                print(\"\\t{fake:<{margin}}{separator} {example}\".format(\n                    fake=signature,\n                    separator=separator,\n                    example=line[i*remains:(i+1)*remains],\n                    margin=margin\n                ))\n                signature = separator = ' '\n\n\ndef main(provider_or_field=None, *args):\n    fake = Faker(locale=DEFAULT_LOCALE)\n\n    from faker.providers import BaseProvider\n    base_provider_formatters = [f for f in dir(BaseProvider)]\n\n    if provider_or_field:\n        if '.' in provider_or_field:\n            parts = provider_or_field.split('.')\n            locale = parts[-2] if parts[-2] in AVAILABLE_LOCALES else DEFAULT_LOCALE\n            fake = Factory.create(locale, providers=[parts[-1]])\n            doc = documentor.Documentor(fake)\n            doc.already_generated = base_provider_formatters\n            print_provider(doc, fake.get_providers()[0], doc.get_provider_formatters(fake.get_providers()[0]))\n        else:\n            try:\n                print(fake.format(provider_or_field, *args))\n            except AttributeError:\n                print('No faker found for \"{0}({1})\"'.format(provider_or_field, args))\n\n    else:\n        doc = documentor.Documentor(fake)\n\n        formatters = doc.get_formatters(with_args=True, with_defaults=True)\n\n        for provider, fakers in formatters:\n\n            print_provider(doc, provider, fakers)\n\n        for lang in AVAILABLE_LOCALES:\n            if lang == DEFAULT_LOCALE:\n                continue\n            print()\n            print('## LANGUAGE {0}'.format(lang))\n            fake = Faker(locale=lang)\n            d = documentor.Documentor(fake)\n\n            for p, fs in d.get_formatters(with_args=True, with_defaults=True, locale=lang,\n                                          excludes=base_provider_formatters):\n                print_provider(d, p, fs)\n\n\ndef command(*args):\n    try:\n        f = args[0]\n    except IndexError:\n        f = '--help'\n\n    if f in [\"--help\", \"-h\"]:\n        main()\n        sys.exit()\n\n    locale = os.environ['LANG'].split('.')[0]\n     \n    if locale not in AVAILABLE_LOCALES:\n        locale = DEFAULT_LOCALE\n    fake = Faker(locale=locale)\n\n    try:\n        print(fake.format(f, *args[1:]))\n    except AttributeError:\n        print('No faker found for \"{0}\"'.format(f))\n\n\nif __name__ == \"__main__\":\n    if sys.stdout.encoding is None:\n        print(\"please set python env PYTHONIOENCODING=UTF-8, example: \"\n              \"export PYTHONIOENCODING=UTF-8, when write to stdout\", file=sys.stderr)\n        exit(1)\n    main(*sys.argv[1:])", "path": "faker/__main__.py"}, {"content": "#!/usr/bin/env python\n\nimport os\nfrom setuptools import setup, find_packages\n\nhere = os.path.abspath(os.path.dirname(__file__))\nREADME = open(os.path.join(here, 'README.md')).read()\nNEWS = open(os.path.join(here, 'NEWS.txt')).read()\n\n\nversion = '0.3.2'\n\nsetup(name='fake-factory',\n      version=version,\n      description=\"Faker is a Python package that generates fake data for you.\",\n      long_description=README + '\\n\\n' + NEWS,\n      scripts=['bin/faker'],\n      classifiers=[\n          # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers\n          'Development Status :: 3 - Alpha',\n          'Environment :: Console',\n          'Intended Audience :: Developers',\n          'Programming Language :: Python',\n          'Programming Language :: Python :: 2',\n          'Programming Language :: Python :: 3',\n          'Topic :: Software Development :: Libraries :: Python Modules',\n          'Topic :: Software Development :: Testing',\n          'Topic :: Utilities',\n          'License :: OSI Approved :: MIT License'\n      ],\n      keywords='faker fixtures data test mock generator',\n      author='joke2k',\n      author_email='joke2k@gmail.com',\n      url='http://github.com/joke2k/faker',\n      license='MIT License',\n      packages=find_packages(exclude=['*.tests']),\n      platforms=[\"any\"],\n      test_suite='faker.tests',\n      )\n", "path": "setup.py"}]}