From c10ddaef4a98343c1c1f1dd1e47e26965453e427 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 28 Feb 2019 13:34:23 +0100 Subject: [PATCH] donate-cpu-server.py: Replace syntax that is deprecated in Python 3. (#1712) The function `iteritems()` of `dict`s is deprecated. The recommended alternative is to use `items()`, this function also works with Python 2. The next issue is that lambdas can no longer unpack tuple parameters in Python 3. It would be possible to use some workaround and still use a lambda, but using `operator.itemgetter(1)` instead is faster and the recommended method in such a case. The syntax is now compatible with Python 2 and 3 but the server script still does not work with Python 3. For example `socket.recv()` returns `bytes` in Python 3 and `str` in Python 2. Currently `str` is expected so it does not work with Python 3. --- .travis.yml | 2 +- tools/donate-cpu-server.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e4958fd90..53f3f6747 100644 --- a/.travis.yml +++ b/.travis.yml @@ -80,7 +80,7 @@ matrix: - python -m py_compile ./tools/donate-cpu.py - python3 -m py_compile ./tools/donate-cpu.py - python -m py_compile ./tools/donate-cpu-server.py - # donate-cpu-server.py is currently not Python 3 compatible + - python3 -m py_compile ./tools/donate-cpu-server.py # check addons/misra.py - cd addons/test - ${CPPCHECK} --dump misc-test.cpp diff --git a/tools/donate-cpu-server.py b/tools/donate-cpu-server.py index 3b23ea9e8..d3b2825e5 100644 --- a/tools/donate-cpu-server.py +++ b/tools/donate-cpu-server.py @@ -12,6 +12,7 @@ import sys import urllib import logging import logging.handlers +import operator OLD_VERSION = '1.87' @@ -522,7 +523,7 @@ def check_library_report(result_path, message_id): function_counts[function_name] = function_counts.setdefault(function_name, 0) + 1 function_details_list = [] - for function_name, count in sorted(function_counts.iteritems(), key=lambda (k, v): (v, k), reverse=True): + for function_name, count in sorted(function_counts.items(), key=operator.itemgetter(1), reverse=True): if len(function_details_list) >= functions_shown_max: break function_details_list.append(str(count).rjust(column_widths[0]) + ' ' +