From 1b5c43b848c2ad5f204cd198672c388188db7ca7 Mon Sep 17 00:00:00 2001 From: "data-plane-api(CircleCI)" Date: Tue, 7 Apr 2020 00:32:21 +0000 Subject: [PATCH] build: remove explicit PY2/PY3 references. (#10664) Now that we are Python 3 everywhere, remove explicit python_versions. I haven't made this change yet to the Thrift extension, as it has explicit PY2/PY3 overrides that I'm guessing relate to external libs. Risk level: Low (tooling only) Testing: bazel.api Signed-off-by: Harvey Tuch Mirrored from https://github.com/envoyproxy/envoy @ 197f6b1cebbd49a591b916ece168d7e984c87a15 --- tools/BUILD | 2 -- tools/tap2pcap.py | 8 ++++---- tools/tap2pcap_test.py | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/tools/BUILD b/tools/BUILD index d94214d7..8d2207b9 100644 --- a/tools/BUILD +++ b/tools/BUILD @@ -4,7 +4,6 @@ py_binary( name = "tap2pcap", srcs = ["tap2pcap.py"], licenses = ["notice"], # Apache 2 - python_version = "PY2", visibility = ["//visibility:public"], deps = ["//envoy/data/tap/v2alpha:pkg_py_proto"], ) @@ -16,7 +15,6 @@ py_test( "data/tap2pcap_h2_ipv4.pb_text", "data/tap2pcap_h2_ipv4.txt", ], - python_version = "PY2", # Don't run this by default, since we don't want to force local dependency on Wireshark/tshark, # will explicitly invoke in CI. tags = ["manual"], diff --git a/tools/tap2pcap.py b/tools/tap2pcap.py index db653272..2e905794 100644 --- a/tools/tap2pcap.py +++ b/tools/tap2pcap.py @@ -20,8 +20,8 @@ TODO(htuch): from __future__ import print_function import datetime +import io import socket -import StringIO import subprocess as sp import sys import time @@ -32,14 +32,14 @@ from envoy.data.tap.v2alpha import wrapper_pb2 def DumpEvent(direction, timestamp, data): - dump = StringIO.StringIO() + dump = io.StringIO() dump.write('%s\n' % direction) # Adjust to local timezone adjusted_dt = timestamp.ToDatetime() - datetime.timedelta(seconds=time.altzone) dump.write('%s\n' % adjusted_dt) od = sp.Popen(['od', '-Ax', '-tx1', '-v'], stdout=sp.PIPE, stdin=sp.PIPE, stderr=sp.PIPE) packet_dump = od.communicate(data)[0] - dump.write(packet_dump) + dump.write(packet_dump.decode()) return dump.getvalue() @@ -78,7 +78,7 @@ def Tap2Pcap(tap_path, pcap_path): '%d,%d' % (remote_port, local_port), '-', pcap_path ] text2pcap = sp.Popen(text2pcap_args, stdout=sp.PIPE, stdin=sp.PIPE) - text2pcap.communicate('\n'.join(dumps)) + text2pcap.communicate('\n'.join(dumps).encode()) if __name__ == '__main__': diff --git a/tools/tap2pcap_test.py b/tools/tap2pcap_test.py index 9f504cf6..429bbbbf 100644 --- a/tools/tap2pcap_test.py +++ b/tools/tap2pcap_test.py @@ -18,7 +18,7 @@ if __name__ == '__main__': tap2pcap.Tap2Pcap(tap_path, pcap_path) actual_output = sp.check_output(['tshark', '-r', pcap_path, '-d', 'tcp.port==10000,http2', '-P']) - with open(expected_path, 'r') as f: + with open(expected_path, 'rb') as f: expected_output = f.read() if actual_output != expected_output: print('Mismatch')