Skip to content

Commit fc3c1a0

Browse files
authored
[sonic_eeprom] Make compatible with Python 2 and 3 (#127)
The `string` type has changed between Python 2 and 3. Therefore, the Python 3 version of this library is broken. This PR changes the data type of the raw EEPROM data to a `bytearray`, which is treated the same in both Python 2 and Python 3, and is technically a more appropriate data type for the raw bytes anyway. However, this PR could cause issues if any vendors are overriding the `read_eeprom_bytes()` or `read_eeprom()` functions and returning a `string`. Any vendors doing so will need to refactor their implementation to return a `bytearray` instead.
1 parent 012dc39 commit fc3c1a0

File tree

2 files changed

+113
-113
lines changed

2 files changed

+113
-113
lines changed

sonic_platform_base/sonic_eeprom/eeprom_base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ def compute_2s_complement(self, e, size):
101101
def compute_dell_crc(self, message):
102102
poly = 0x8005
103103
reg = 0x0000
104-
message += '\x00\x00'
104+
message += bytearray(b'\x00\x00')
105105
for byte in message:
106106
mask = 0x80
107107
while (mask > 0):
108108
reg<<=1
109-
if ord(byte) & mask:
109+
if byte & mask:
110110
reg += 1
111111
mask>>=1
112112
if reg > 0xffff:
@@ -265,7 +265,7 @@ def read_eeprom_bytes(self, byteCount, offset=0):
265265
if F is not None:
266266
F.close()
267267

268-
return o
268+
return bytearray(o)
269269

270270
def read_eeprom_db(self):
271271
return 0

0 commit comments

Comments
 (0)