From a1aa7a4054e709c7120c2226898f0b4fb4348634 Mon Sep 17 00:00:00 2001 From: Serge Guelton Date: Wed, 20 Mar 2019 07:42:13 +0000 Subject: [PATCH] Python 2/3 compatibility This should be the only change required to have lld's python code base compatible with both Python 2 and Python 3 Differential Revision: https://reviews.llvm.org/D59538 llvm-svn: 356538 --- lld/utils/benchmark.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lld/utils/benchmark.py b/lld/utils/benchmark.py index 8ca6cca89f33..47490b9a9828 100755 --- a/lld/utils/benchmark.py +++ b/lld/utils/benchmark.py @@ -13,8 +13,13 @@ import subprocess import json import datetime import argparse -import urllib -import urllib2 +try: + from urllib.parse import urlencode + from urllib.request import urlopen, Request +except ImportError: + from urllib import urlencode + from urllib2 import urlopen, Request + parser = argparse.ArgumentParser() parser.add_argument('benchmark_directory') @@ -126,8 +131,8 @@ def buildLntJson(benchmarks): return json.dumps(ret, sort_keys=True, indent=4) def submitToServer(data): - data2 = urllib.urlencode({ 'input_data' : data }).encode('ascii') - urllib2.urlopen(urllib2.Request(args.url, data2)) + data2 = urlencode({ 'input_data' : data }).encode('ascii') + urlopen(Request(args.url, data2)) os.chdir(args.benchmark_directory) data = buildLntJson(getBenchmarks())