From 762f1e00329b387493dcdfa1716f4cbcd337a318 Mon Sep 17 00:00:00 2001 From: "data-plane-api(CircleCI)" Date: Wed, 16 Jan 2019 06:01:19 +0000 Subject: [PATCH] Fix next(), print(), and raw_input() to work in both Python 2 and Python 3 (#5599) Legacy print statements are syntax errors in Python 3 but print() function works as expected in both Python 2 and Python 3. Resolves syntax errors and name errors that have the potential to halt the runtime. Risk Level: Minimal Testing: http://flake8.pycqa.org Signed-off-by: cclauss Mirrored from https://github.com/envoyproxy/envoy @ abd82f7c078b5c38faaecb885b46e0ac053e0353 --- tools/capture2pcap.py | 3 ++- tools/capture2pcap_test.py | 7 ++++--- tools/generate_listeners.py | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/capture2pcap.py b/tools/capture2pcap.py index 49f20086..fff1c725 100644 --- a/tools/capture2pcap.py +++ b/tools/capture2pcap.py @@ -17,6 +17,7 @@ issue. TODO(htuch): - Figure out IPv6 PCAP issue above, or file a bug once the root cause is clear. """ +from __future__ import print_function import datetime import socket @@ -81,6 +82,6 @@ def Capture2Pcap(capture_path, pcap_path): if __name__ == '__main__': if len(sys.argv) != 3: - print 'Usage: %s ' % sys.argv[0] + print('Usage: %s ' % sys.argv[0]) sys.exit(1) Capture2Pcap(sys.argv[1], sys.argv[2]) diff --git a/tools/capture2pcap_test.py b/tools/capture2pcap_test.py index bcbd04b6..055e0e6e 100644 --- a/tools/capture2pcap_test.py +++ b/tools/capture2pcap_test.py @@ -1,4 +1,5 @@ """Tests for capture2pcap.""" +from __future__ import print_function import os import subprocess as sp @@ -20,7 +21,7 @@ if __name__ == '__main__': with open(expected_path, 'r') as f: expected_output = f.read() if actual_output != expected_output: - print 'Mismatch' - print 'Expected: %s' % expected_output - print 'Actual: %s' % actual_output + print('Mismatch') + print('Expected: %s' % expected_output) + print('Actual: %s' % actual_output) sys.exit(1) diff --git a/tools/generate_listeners.py b/tools/generate_listeners.py index 7a3f8c28..9d073ccc 100644 --- a/tools/generate_listeners.py +++ b/tools/generate_listeners.py @@ -47,7 +47,7 @@ def GenerateListeners(listeners_pb_path, output_pb_path, output_json_path, fragm for filter_chain in listener.filter_chains: for f in filter_chain.filters: - f.config.CopyFrom(ProtoToStruct(ParseProto(fragments.next(), f.name))) + f.config.CopyFrom(ProtoToStruct(ParseProto(next(fragments), f.name))) with open(output_pb_path, 'w') as f: f.write(str(listener))