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 <cclauss@me.com>

Mirrored from https://github.com/envoyproxy/envoy @ abd82f7c078b5c38faaecb885b46e0ac053e0353
pull/620/head
data-plane-api(CircleCI) 6 years ago
parent 47a7eabcd2
commit 762f1e0032
  1. 3
      tools/capture2pcap.py
  2. 7
      tools/capture2pcap_test.py
  3. 2
      tools/generate_listeners.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 <capture .pb/.pb_text> <pcap path>' % sys.argv[0]
print('Usage: %s <capture .pb/.pb_text> <pcap path>' % sys.argv[0])
sys.exit(1)
Capture2Pcap(sys.argv[1], sys.argv[2])

@ -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)

@ -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))

Loading…
Cancel
Save