From d93c1debb0f2b782c7b051c338753508bd6bca23 Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Wed, 28 Feb 2018 15:08:58 +0700 Subject: fake_trx/data_dump.py: fix python3 compatibility There is no 'file' type in Python3 anymore, so let's reverse the condition in DATADumpFile constructor. Also, the tag definition was incorrect: both '\x01' and b'\x01' aren't the same. Change-Id: Ib00c7f0bd5871fcfce931a4bfa501ae5bf797c45 --- src/target/fake_trx/data_dump.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/target/fake_trx/data_dump.py b/src/target/fake_trx/data_dump.py index 56e314c4..6102dc56 100644 --- a/src/target/fake_trx/data_dump.py +++ b/src/target/fake_trx/data_dump.py @@ -28,8 +28,8 @@ from data_msg import * class DATADump: # Constants - TAG_L12TRX = '\x01' - TAG_TRX2L1 = '\x02' + TAG_L12TRX = b'\x01' + TAG_TRX2L1 = b'\x02' HDR_LENGTH = 3 # Generates raw bytes from a DATA message @@ -58,7 +58,7 @@ class DATADump: def parse_hdr(self, hdr): # Extract the header info msg_len = struct.unpack(">H", hdr[1:3])[0] - tag = hdr[0] + tag = hdr[:1] # Check if tag is known if tag == self.TAG_L12TRX: @@ -76,11 +76,11 @@ class DATADump: class DATADumpFile(DATADump): def __init__(self, capture): # Check if capture file is already opened - if type(capture) is file: - self.f = capture - else: + if isinstance(capture, str): print("[i] Opening capture file '%s'..." % capture) self.f = open(capture, "a+b") + else: + self.f = capture def __del__(self): print("[i] Closing the capture file") -- cgit v1.2.3