Skip to content

Commit ea59c0f

Browse files
[sffbase.py] Fix to make Python 3-compatible (sonic-net#156)
Change sffbase.py code to make it compatible with python3 1. change iteritems to items 2. change type(*) = types.* to type(*) = $typename
1 parent 9935fca commit ea59c0f

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

sonic_platform_base/sonic_sfp/sffbase.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# sffbase class for sff8436 and sff8472
33
#----------------------------------------------------------------------------
44

5-
from __future__ import print_function
5+
66

77
try:
88
import fcntl
@@ -100,7 +100,7 @@ def parse_sff_element(self, eeprom_data, eeprom_ele, start_pos):
100100
elif type == 'bitmap':
101101
# Get the 'on' bitname
102102
bitvalue_dict = {}
103-
for bitname, bitinfo in sorted(decode.iteritems()):
103+
for bitname, bitinfo in sorted(decode.items()):
104104
bitinfo_offset = bitinfo.get('offset') + start_pos
105105
bitinfo_pos = bitinfo.get('bit')
106106
bitinfo_value = bitinfo.get('value')
@@ -145,7 +145,7 @@ def parse_sff_element(self, eeprom_data, eeprom_ele, start_pos):
145145
# Recursively parses sff data into dictionary
146146
def parse_sff(self, eeprom_map, eeprom_data, start_pos):
147147
outdict = {}
148-
for name, meta_data in sorted(eeprom_map.iteritems()):
148+
for name, meta_data in sorted(eeprom_map.items()):
149149
type = meta_data.get('type')
150150

151151
# Initialize output value
@@ -195,9 +195,9 @@ def parse(self, eeprom_map, eeprom_data, start_pos):
195195
def get_data_pretty_dict(self, indict):
196196
outdict = {}
197197

198-
for elem, elem_val in sorted(indict.iteritems()):
198+
for elem, elem_val in sorted(indict.items()):
199199
value = elem_val.get('value')
200-
if type(value) == types.DictType:
200+
if type(value) == dict:
201201
outdict[elem] = sffbase.get_data_pretty_dict(
202202
self, value)
203203
else:
@@ -229,13 +229,13 @@ def get_data_pretty(self, indata):
229229

230230
# Dumps dict in pretty format
231231
def dump_pretty(self, indict):
232-
for elem, elem_val in sorted(indict.iteritems()):
233-
if type(elem_val) == types.DictType:
232+
for elem, elem_val in sorted(indict.items()):
233+
if type(elem_val) == dict:
234234
print(self._indent, elem, ': ')
235235
self.inc_indent()
236236
sff8472.dump_pretty(self, elem_val)
237237
self.dec_indent()
238-
elif type(elem_val) == types.ListType:
238+
elif type(elem_val) == list:
239239
if len(elem_val) == 1:
240240
print(self._indent, elem, ': ', elem_val.pop())
241241
else:

0 commit comments

Comments
 (0)