Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/json/tool.py

    r2 r391  
    33Usage::
    44
    5     $ echo '{"json":"obj"}' | python -mjson.tool
     5    $ echo '{"json":"obj"}' | python -m json.tool
    66    {
    77        "json": "obj"
    88    }
    9     $ echo '{ 1.2:3.4}' | python -mjson.tool
    10     Expecting property name: line 1 column 2 (char 2)
     9    $ echo '{ 1.2:3.4}' | python -m json.tool
     10    Expecting property name enclosed in double quotes: line 1 column 3 (char 2)
    1111
    1212"""
     
    2525        outfile = open(sys.argv[2], 'wb')
    2626    else:
    27         raise SystemExit("{0} [infile [outfile]]".format(sys.argv[0]))
    28     try:
    29         obj = json.load(infile)
    30     except ValueError, e:
    31         raise SystemExit(e)
    32     json.dump(obj, outfile, sort_keys=True, indent=4)
    33     outfile.write('\n')
     27        raise SystemExit(sys.argv[0] + " [infile [outfile]]")
     28    with infile:
     29        try:
     30            obj = json.load(infile)
     31        except ValueError, e:
     32            raise SystemExit(e)
     33    with outfile:
     34        json.dump(obj, outfile, sort_keys=True,
     35                  indent=4, separators=(',', ': '))
     36        outfile.write('\n')
    3437
    3538
Note: See TracChangeset for help on using the changeset viewer.