Skip to content

Commit

Permalink
Make sonic_sfp Python2 and Python3 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
Myron Sosyak committed Jan 4, 2021
1 parent ea59c0f commit f63834a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions sonic_platform_base/sonic_sfp/sfputilbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,15 @@ def _read_eeprom_specific_bytes(self, sysfsfile_eeprom, offset, num_bytes):
return None

try:
for n in range(0, num_bytes):
eeprom_raw[n] = hex(ord(raw[n]))[2:].zfill(2)
# in case raw is bytes (python3 is used) raw[n] will return int,
# and in case raw is str(python2 is used) raw[n] will return str,
# so for python3 the are no need to call ord to convert str to int.
if type(raw) == bytes:
for n in range(0, num_bytes):
eeprom_raw[n] = hex(raw[n]))[2:].zfill(2)
else:
for n in range(0, num_bytes):
eeprom_raw[n] = hex(ord(raw[n]))[2:].zfill(2)
except Exception:
return None

Expand Down

0 comments on commit f63834a

Please sign in to comment.