Skip to content

Commit

Permalink
[sffbase.py] Fix to make Python 3-compatible (sonic-net#156)
Browse files Browse the repository at this point in the history
Change sffbase.py code to make it compatible with python3

1. change iteritems to items
2. change type(*) = types.* to type(*) = $typename
  • Loading branch information
Junchao-Mellanox authored Dec 28, 2020
1 parent 9935fca commit ea59c0f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions sonic_platform_base/sonic_sfp/sffbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# sffbase class for sff8436 and sff8472
#----------------------------------------------------------------------------

from __future__ import print_function


try:
import fcntl
Expand Down Expand Up @@ -100,7 +100,7 @@ def parse_sff_element(self, eeprom_data, eeprom_ele, start_pos):
elif type == 'bitmap':
# Get the 'on' bitname
bitvalue_dict = {}
for bitname, bitinfo in sorted(decode.iteritems()):
for bitname, bitinfo in sorted(decode.items()):
bitinfo_offset = bitinfo.get('offset') + start_pos
bitinfo_pos = bitinfo.get('bit')
bitinfo_value = bitinfo.get('value')
Expand Down Expand Up @@ -145,7 +145,7 @@ def parse_sff_element(self, eeprom_data, eeprom_ele, start_pos):
# Recursively parses sff data into dictionary
def parse_sff(self, eeprom_map, eeprom_data, start_pos):
outdict = {}
for name, meta_data in sorted(eeprom_map.iteritems()):
for name, meta_data in sorted(eeprom_map.items()):
type = meta_data.get('type')

# Initialize output value
Expand Down Expand Up @@ -195,9 +195,9 @@ def parse(self, eeprom_map, eeprom_data, start_pos):
def get_data_pretty_dict(self, indict):
outdict = {}

for elem, elem_val in sorted(indict.iteritems()):
for elem, elem_val in sorted(indict.items()):
value = elem_val.get('value')
if type(value) == types.DictType:
if type(value) == dict:
outdict[elem] = sffbase.get_data_pretty_dict(
self, value)
else:
Expand Down Expand Up @@ -229,13 +229,13 @@ def get_data_pretty(self, indata):

# Dumps dict in pretty format
def dump_pretty(self, indict):
for elem, elem_val in sorted(indict.iteritems()):
if type(elem_val) == types.DictType:
for elem, elem_val in sorted(indict.items()):
if type(elem_val) == dict:
print(self._indent, elem, ': ')
self.inc_indent()
sff8472.dump_pretty(self, elem_val)
self.dec_indent()
elif type(elem_val) == types.ListType:
elif type(elem_val) == list:
if len(elem_val) == 1:
print(self._indent, elem, ': ', elem_val.pop())
else:
Expand Down

0 comments on commit ea59c0f

Please sign in to comment.