From 57af171055a523c4ae4fc0e49ec51e46c94551af Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Thu, 18 Mar 2010 00:31:51 +0000 Subject: [PATCH] Fix support with python 2.6 without simplejson. Review URL: http://codereview.chromium.org/1050005 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@41902 0039d316-1c4b-4281-b951-d872f2087c98 --- trychange.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/trychange.py b/trychange.py index 96f72b868..85d589f0f 100755 --- a/trychange.py +++ b/trychange.py @@ -20,6 +20,14 @@ import sys import tempfile import urllib +try: + import simplejson as json +except ImportError: + try: + import json + except ImportError: + json = None + try: import breakpad except ImportError: @@ -621,13 +629,11 @@ def TryChange(argv, elif options.issue and options.patchset is None: # Retrieve the patch from rietveld when the diff is not specified. # When patchset is specified, it's because it's done by gcl/git-try. - try: - import simplejson - except ImportError: - parser.error('simplejson library is missing, please install.') + if json is None: + parser.error('json or simplejson library is missing, please install.') api_url = '%s/api/%d' % (options.rietveld_url, options.issue) logging.debug(api_url) - contents = simplejson.loads(urllib.urlopen(api_url).read()) + contents = json.loads(urllib.urlopen(api_url).read()) options.patchset = contents['patchsets'][-1] diff_url = ('%s/download/issue%d_%d.diff' % (options.rietveld_url, options.issue, options.patchset))