~ubuntu-branches/ubuntu/saucy/click/saucy-proposed

« back to all changes in this revision

Viewing changes to bin/click

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2013-07-30 15:14:16 UTC
  • Revision ID: package-import@ubuntu.com-20130730151416-ajoe6kqrb59kkamo
Tags: 0.2.10
* Force click's stdout encoding to UTF-8 regardless of the locale.
* Don't encode non-ASCII characters in JSON dumps.
* Treat manifests as UTF-8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
from click import commands
31
31
 
32
32
 
 
33
def fix_stdout():
 
34
    if sys.version >= "3":
 
35
        # Force encoding to UTF-8 even in non-UTF-8 locales.
 
36
        import io
 
37
        sys.stdout = io.TextIOWrapper(
 
38
            sys.stdout.detach(), encoding="UTF-8", line_buffering=True)
 
39
    else:
 
40
        # Avoid having to do .encode("UTF-8") everywhere.
 
41
        import codecs
 
42
        sys.stdout = codecs.EncodedFile(sys.stdout, "UTF-8")
 
43
 
 
44
        def null_decode(input, errors="strict"):
 
45
            return input, len(input)
 
46
 
 
47
        sys.stdout.decode = null_decode
 
48
 
 
49
 
33
50
def main():
 
51
    fix_stdout()
 
52
 
34
53
    parser = OptionParser(dedent("""\
35
54
        %%prog COMMAND [options]
36
55