[PATCH] osmocom-bb[fixeria/trx]: fake_trx/data_dump.py: fix python3 compatibility

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Vadim Yanitskiy gerrit-no-reply at lists.osmocom.org
Wed Feb 28 09:07:14 UTC 2018


Review at  https://gerrit.osmocom.org/6988

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
---
M src/target/fake_trx/data_dump.py
1 file changed, 6 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/88/6988/1

diff --git a/src/target/fake_trx/data_dump.py b/src/target/fake_trx/data_dump.py
index 56e314c..6102dc5 100644
--- a/src/target/fake_trx/data_dump.py
+++ b/src/target/fake_trx/data_dump.py
@@ -28,8 +28,8 @@
 
 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 @@
 	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 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")

-- 
To view, visit https://gerrit.osmocom.org/6988
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib00c7f0bd5871fcfce931a4bfa501ae5bf797c45
Gerrit-PatchSet: 1
Gerrit-Project: osmocom-bb
Gerrit-Branch: fixeria/trx
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>



More information about the gerrit-log mailing list