You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by ko...@apache.org on 2019/11/02 16:28:31 UTC

[avro] branch master updated: AVRO-2614: Remove Trailing Spaces in Pretty Print (#697)

This is an automated email from the ASF dual-hosted git repository.

kojiromike pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/master by this push:
     new 62f3c26  AVRO-2614: Remove Trailing Spaces in Pretty Print (#697)
62f3c26 is described below

commit 62f3c26e2c303df0a208590041bcf20590fce62d
Author: Michael A. Smith <mi...@smith-li.com>
AuthorDate: Sat Nov 2 12:28:24 2019 -0400

    AVRO-2614: Remove Trailing Spaces in Pretty Print (#697)
---
 lang/py/scripts/avro        | 6 +++++-
 lang/py/test/test_script.py | 4 ++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/lang/py/scripts/avro b/lang/py/scripts/avro
index 1aac028..7488f70 100644
--- a/lang/py/scripts/avro
+++ b/lang/py/scripts/avro
@@ -39,7 +39,11 @@ def print_json(row):
     print(json.dumps(row))
 
 def print_json_pretty(row):
-    print(json.dumps(row, indent=4))
+    """Pretty print JSON"""
+    # Need to work around https://bugs.python.org/issue16333
+    # where json.dumps leaves trailing spaces.
+    result = json.dumps(row, indent=4).replace(' \n', '\n')
+    print(result)
 
 _write_row = csv.writer(stdout).writerow
 _encoding = stdout.encoding or "UTF-8"
diff --git a/lang/py/test/test_script.py b/lang/py/test/test_script.py
index bd0cb4d..39e856e 100644
--- a/lang/py/test/test_script.py
+++ b/lang/py/test/test_script.py
@@ -66,8 +66,8 @@ def looney_records():
 SCRIPT = join(dirname(__file__), "..", "scripts", "avro")
 
 _JSON_PRETTY = '''{
-    "type": "duck", 
-    "last": "duck", 
+    "type": "duck",
+    "last": "duck",
     "first": "daffy"
 }'''