summaryrefslogtreecommitdiff
path: root/simplejson/tool.py
diff options
context:
space:
mode:
authorBob Ippolito <bob@redivi.com>2013-02-21 15:13:39 -0800
committerBob Ippolito <bob@redivi.com>2013-02-21 15:13:39 -0800
commitdb53d9a525ea7fec93a00fc17a1e094e821961ad (patch)
tree1bd80ccbcfc4b581cdea292db5e00a9c5ccf066a /simplejson/tool.py
parent104b40fcf6aa39d9ba7b240c3c528d1f85e86ef2 (diff)
downloadsimplejson-db53d9a525ea7fec93a00fc17a1e094e821961ad.tar.gz
simplejson.tool tests and bugfix for Python 3.x (#60)
Diffstat (limited to 'simplejson/tool.py')
-rw-r--r--simplejson/tool.py24
1 files changed, 13 insertions, 11 deletions
diff --git a/simplejson/tool.py b/simplejson/tool.py
index f00e592..35627db 100644
--- a/simplejson/tool.py
+++ b/simplejson/tool.py
@@ -18,21 +18,23 @@ def main():
infile = sys.stdin
outfile = sys.stdout
elif len(sys.argv) == 2:
- infile = open(sys.argv[1], 'rb')
+ infile = open(sys.argv[1], 'r')
outfile = sys.stdout
elif len(sys.argv) == 3:
- infile = open(sys.argv[1], 'rb')
- outfile = open(sys.argv[2], 'wb')
+ infile = open(sys.argv[1], 'r')
+ outfile = open(sys.argv[2], 'w')
else:
raise SystemExit(sys.argv[0] + " [infile [outfile]]")
- try:
- obj = json.load(infile,
- object_pairs_hook=json.OrderedDict,
- use_decimal=True)
- except ValueError:
- raise SystemExit(sys.exc_info()[1])
- json.dump(obj, outfile, sort_keys=True, indent=' ', use_decimal=True)
- outfile.write('\n')
+ with infile:
+ try:
+ obj = json.load(infile,
+ object_pairs_hook=json.OrderedDict,
+ use_decimal=True)
+ except ValueError:
+ raise SystemExit(sys.exc_info()[1])
+ with outfile:
+ json.dump(obj, outfile, sort_keys=True, indent=' ', use_decimal=True)
+ outfile.write('\n')
if __name__ == '__main__':