Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON output should print unicode chars instead of escape sequences #1048

Closed
jamesls opened this issue Dec 8, 2014 · 0 comments
Closed

JSON output should print unicode chars instead of escape sequences #1048

jamesls opened this issue Dec 8, 2014 · 0 comments
Labels
bug This issue is a bug.

Comments

@jamesls
Copy link
Member

jamesls commented Dec 8, 2014

In the JSON output, the JSON encoder will escape any non-ascii characters to be in the form \u<hex> instead of encoding the unicode char in the encoding of stdout.

$ aws dynamodb scan --table-name testtable2
{
    "ScannedCount": 1,
    "ConsumedCapacity": null,
    "Items": [
        {
            "foo": {
                "S": "\u2713"
            }
        }
    ],
    "Count": 1
}

However, for text/table output, py3/py27 will print unicode:

$ aws dynamodb scan --table-name testtable2 --output text
FOO ✓

but py2.6 (and only py2.6) will raise an encoding error for table/text output:

$ aws dynamodb scan --table-name testtable2 --output text

'ascii' codec can't encode character u'\u2713' in position 4: ordinal not in range(128)

I believe this is due to a bug in py2.6 (http://bugs.python.org/issue4947) in which the .encoding attribute of sys.stdout is not being honored. To fix this, we can use the compat.get_stdout_text_writer to ensure we have something that will always encode to our preferred encoding.

So the end result of this should be that we always display unicode chars instead of the escape sequences, and this should occur across all of the supported output formats.

@jamesls jamesls added bug This issue is a bug. confirmed labels Dec 8, 2014
jamesls added a commit to jamesls/aws-cli that referenced this issue Dec 8, 2014
Also, we need to use the get_stdout_text_writer because of a
bug in py2.6 in which the `.encoding` attribute is not honored
for `sys.stdout` (http://bugs.python.org/issue4947).

Fixes aws#1048.
@jamesls jamesls closed this as completed in e5ddf48 Dec 9, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant