Skip to content

Commit a6f837e

Browse files
committed
Python 3 support: Use items() when iteritems() is not available
1 parent a670331 commit a6f837e

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

netsnmpagent.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@
3030
# http://stackoverflow.com/questions/36932/how-can-i-represent-an-enum-in-python
3131
def enum(*sequential, **named):
3232
enums = dict(zip(sequential, range(len(sequential))), **named)
33-
enums["Names"] = dict((value,key) for key, value in enums.iteritems())
33+
try:
34+
# Python 2.x
35+
enums_iterator = enums.iteritems()
36+
except AttributeError:
37+
# Python 3.x
38+
enums_iterator = enums.items()
39+
enums["Names"] = dict((value,key) for key, value in enums_iterator)
3440
return type("Enum", (), enums)
3541

3642
# Indicates the status of a netsnmpAgent object
@@ -907,7 +913,13 @@ def getRegistered(self, context = ""):
907913
Returned is a dictionary objects for the specified "context",
908914
which defaults to the default context. """
909915
myobjs = {}
910-
for oidstr, snmpobj in self._objs[context].iteritems():
916+
try:
917+
# Python 2.x
918+
objs_iterator = self._objs[context].iteritems()
919+
except AttributeError:
920+
# Python 3.x
921+
objs_iterator = self._objs[context].items()
922+
for oidstr, snmpobj in objs_iterator:
911923
myobjs[oidstr] = {
912924
"type": type(snmpobj).__name__,
913925
"value": snmpobj.value()

0 commit comments

Comments
 (0)