Skip to content

Commit

Permalink
Remove six from mibs
Browse files Browse the repository at this point in the history
  • Loading branch information
johannaengland committed Mar 23, 2022
1 parent 78e03b2 commit 770504d
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 53 deletions.
4 changes: 2 additions & 2 deletions python/nav/mibs/bgp4_mib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Copyright (C) 2017 Uninett AS
# Copyright (C) 2022 Sikt
#
# This file is part of Network Administration Visualized (NAV).
#
Expand All @@ -20,7 +21,6 @@
from pprint import pformat
import logging

from six import iteritems
from twisted.internet import defer
from twisted.internet.defer import returnValue

Expand Down Expand Up @@ -86,7 +86,7 @@ def get_bgp_peer_states(self):
(row[self.LOCAL_AS_COLUMN] if self.LOCAL_AS_COLUMN else local_as),
row[self.REMOTE_AS_COLUMN],
)
for key, row in iteritems(rows)
for key, row in rows.items()
}

if self._logger.isEnabledFor(logging.DEBUG):
Expand Down
5 changes: 2 additions & 3 deletions python/nav/mibs/cisco_process_mib.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# details. You should have received a copy of the GNU General Public License
# along with NAV. If not, see <http://www.gnu.org/licenses/>.
#
from six import itervalues, iteritems
from twisted.internet import defer

from nav.compatibility import smart_str
Expand Down Expand Up @@ -43,12 +42,12 @@ def get_cpu_loadavg(self):
)
self._logger.debug("cpu load results: %r", load)
physindexes = [
row[PHYSICAL_INDEX] for row in itervalues(load) if row[PHYSICAL_INDEX]
row[PHYSICAL_INDEX] for row in load.values() if row[PHYSICAL_INDEX]
]
names = yield self._get_cpu_names(physindexes)

result = {}
for index, row in iteritems(load):
for index, row in load.items():
name = names.get(row[PHYSICAL_INDEX], str(index[-1]))
result[name] = [(5, row[TOTAL_5_MIN_REV]), (1, row[TOTAL_1_MIN_REV])]
defer.returnValue(result)
Expand Down
6 changes: 3 additions & 3 deletions python/nav/mibs/cpqpower_mib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Copyright (C) 2019 Uninett AS
# Copyright (C) 2022 Sikt
#
# This file is part of Network Administration Visualized (NAV).
#
Expand All @@ -15,7 +16,6 @@
#
"""A class for extracting information from HPE power devices devices"""
from __future__ import unicode_literals
from six import iteritems, text_type
from twisted.internet import defer
from nav.smidumps import get_mib
from nav.mibs import reduce_index
Expand Down Expand Up @@ -206,7 +206,7 @@ def _get_sensors(self, names, sensors, extra_columns=None, filter=lambda x: True
entries = self.translate_result(entries)

result = []
for index, row in iteritems(entries):
for index, row in entries.items():
if not filter(row):
continue
result.extend(self._mksensors(index, row, sensors, names))
Expand All @@ -225,7 +225,7 @@ def _mksensors(self, index, row, table, names):
for key, value in config.items():
if callable(value):
value = value(row)
elif isinstance(value, text_type):
elif isinstance(value, str):
value = value.format(**row)
sensor[key] = value
name = names.get(index[0])
Expand Down
8 changes: 3 additions & 5 deletions python/nav/mibs/entity_mib.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import struct
import sys

import six
from six import iteritems
from twisted.internet import defer

from nav.oids import OID
Expand Down Expand Up @@ -346,7 +344,7 @@ def _get_non_chassis_duplicates(self):
for ent in self.values():
if not self.is_chassis(ent):
dupes[ent['entPhysicalName']].append(ent)
dupes = dict((key, value) for key, value in iteritems(dupes) if len(value) > 1)
dupes = dict((key, value) for key, value in dupes.items() if len(value) > 1)
return dupes

def _clean_unicode(self, encoding="utf-8"):
Expand All @@ -357,11 +355,11 @@ def _clean_unicode(self, encoding="utf-8"):
"""
for entity in self.values():
for key, value in entity.items():
if isinstance(value, six.binary_type):
if isinstance(value, bytes):
try:
new_value = value.decode(encoding)
except UnicodeDecodeError:
new_value = six.text_type(repr(value))
new_value = str(repr(value))
_logger.debug(
"cannot decode %s value as %s, using python "
"string repr instead: %s",
Expand Down
5 changes: 2 additions & 3 deletions python/nav/mibs/hpicf_powersupply_mib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Copyright 2008 - 2011, 2014, 2019 (C) Uninett AS
# Copyright (C) 2022 Sikt
#
# This file is part of Network Administration Visualized (NAV).
#
Expand All @@ -18,8 +19,6 @@

from twisted.internet import defer

import six

from nav.mibs import reduce_index
from nav.mibs.entity_mib import EntityMib
from nav.smidumps import get_mib
Expand Down Expand Up @@ -105,7 +104,7 @@ def get_power_supplies(self):


def _psu_index_from_internal_id(internal_id):
if isinstance(internal_id, six.string_types):
if isinstance(internal_id, str):
return int(internal_id.split(":")[1] if ":" in internal_id else internal_id)
else:
return internal_id
4 changes: 2 additions & 2 deletions python/nav/mibs/ip_forward_mib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Copyright (C) 2016 Uninett AS
# Copyright (C) 2022 Sikt
#
# This file is part of Network Administration Visualized (NAV).
#
Expand All @@ -19,7 +20,6 @@
from itertools import chain
from collections import namedtuple

from six import iteritems
from twisted.internet.defer import inlineCallbacks, returnValue

from nav.smidumps import get_mib
Expand Down Expand Up @@ -72,7 +72,7 @@ def get_routes(self, protocols=None):
protos = yield self.retrieve_column('inetCidrRouteProto')

by_proto = defaultdict(list)
for index, proto in iteritems(protos):
for index, proto in protos.items():
name = IANA_IP_ROUTE_PROTOCOLS.get(proto, proto)
by_proto[name].append(index)

Expand Down
6 changes: 2 additions & 4 deletions python/nav/mibs/ip_mib.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2009-2011 Uninett AS
# Copyright (C) 2022 Sikt
#
# This file is part of Network Administration Visualized (NAV).
#
Expand All @@ -17,7 +18,6 @@
"""MibRetriever implementation for IP-MIB"""
from __future__ import absolute_import

import six
from twisted.internet.defer import inlineCallbacks, returnValue

from nav.oids import OID
Expand Down Expand Up @@ -108,9 +108,7 @@ def _chop_index(cls, index, entry):
if not root or not root.oid.is_a_prefix_of(index):
return index

children = (
c.oid for c in six.itervalues(cls.nodes) if root.oid.is_a_prefix_of(c.oid)
)
children = (c.oid for c in cls.nodes.values() if root.oid.is_a_prefix_of(c.oid))
matched_prefixes = [c for c in children if c.is_a_prefix_of(index)] + [root.oid]
if matched_prefixes:
index = index.strip_prefix(matched_prefixes[0])
Expand Down
3 changes: 1 addition & 2 deletions python/nav/mibs/itw_mib.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
sensor-information.
"""
from nav.compatibility import smart_str
from six import itervalues
from twisted.internet import defer

from nav.mibs import reduce_index
Expand Down Expand Up @@ -365,7 +364,7 @@ def _handle_sensor_group(self, sensor_group, table_data):
serial_col = sensor_group['serial']
sensors = sensor_group['sensors']

for row in itervalues(table_data):
for row in table_data.values():
if not avail_col or row.get(avail_col):
oid = row.get(0)
serial = row.get(serial_col)
Expand Down
6 changes: 3 additions & 3 deletions python/nav/mibs/itw_mibv3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2008-2019 Uninett AS
# Copyright (C) 2022 Sikt
#
# This file is part of Network Administration Visualized (NAV).
#
Expand All @@ -20,7 +21,6 @@
Uses the vendor-specifica IT-WATCHDOGS-MIB-V3 to detect and collect
sensor-information.
"""
from six import itervalues
from twisted.internet import defer

from nav.mibs import reduce_index
Expand Down Expand Up @@ -394,7 +394,7 @@ class ItWatchDogsMibV3(BaseITWatchDogsMib):

def _get_power_dms_params(self, power_dms):
sensors = []
for power_dm in itervalues(power_dms):
for power_dm in power_dms.values():
power_dm_avail = power_dm.get('powerDMAvail')
if power_dm_avail:
power_dm_oid = power_dm.get(0)
Expand Down Expand Up @@ -426,7 +426,7 @@ def _get_power_dms_params(self, power_dms):

def _get_io_expanders_params(self, io_expanders):
sensors = []
for io_expander in itervalues(io_expanders):
for io_expander in io_expanders.values():
io_expander_avail = io_expander.get('ioExpanderAvail', 0)
if io_expander_avail:
io_expander_oid = io_expander.get(0)
Expand Down
8 changes: 4 additions & 4 deletions python/nav/mibs/lldp_mib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Copyright (C) 2012, 2016 Uninett AS
# Copyright (C) 2022 Sikt
#
# This file is part of Network Administration Visualized (NAV).
#
Expand All @@ -17,7 +18,6 @@
import socket
from collections import namedtuple

import six
from twisted.internet.defer import inlineCallbacks, returnValue

from nav.ip import IP
Expand Down Expand Up @@ -205,7 +205,7 @@ def isdigit(self):
class BinaryOrString(IdType):
def __new__(cls, *args, **_kwargs):
arg = args[0]
if isinstance(arg, six.binary_type):
if isinstance(arg, bytes):
try:
arg = arg.decode('utf-8')
except (ValueError, UnicodeDecodeError):
Expand All @@ -218,7 +218,7 @@ def __new__(cls, *args, **_kwargs):
class MacAddress(IdType):
def __new__(cls, *args, **_kwargs):
arg = args[0]
if isinstance(arg, six.binary_type):
if isinstance(arg, bytes):
try:
arg = macaddress.MacAddress.from_octets(arg)
except ValueError:
Expand All @@ -240,7 +240,7 @@ class NetworkAddress(IdType):

def __new__(cls, *args, **_kwargs):
arg = args[0]
if arg and isinstance(arg, six.binary_type):
if arg and isinstance(arg, bytes):
addr_type = arg[0]
addr_string = arg[1:]
if addr_type in cls.ADDR_FAMILY:
Expand Down
8 changes: 3 additions & 5 deletions python/nav/mibs/mibretriever.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2009-2012, 2014, 2015 Uninett AS
# Copyright (C) 2022 Sikt
#
# This file is part of Network Administration Visualized (NAV).
#
Expand Down Expand Up @@ -32,8 +33,6 @@

import logging

import six

from twisted.internet import defer, reactor
from twisted.internet.defer import returnValue
from twisted.internet.error import TimeoutError
Expand Down Expand Up @@ -122,7 +121,7 @@ def to_python(self, value):
SNMPv2-TC::TruthValue, it will be translated from int to bool.
"""
if self.enum and isinstance(value, six.integer_types) and value in self.enum:
if self.enum and isinstance(value, int) and value in self.enum:
value = self.enum[value]
return value

Expand Down Expand Up @@ -361,8 +360,7 @@ def __prepopulate_text_columns(cls):
cls.text_columns = nodes


@six.add_metaclass(MibRetrieverMaker)
class MibRetriever(object):
class MibRetriever(object, metaclass=MibRetrieverMaker):
"""Base class for functioning MIB retriever classes."""

mib = None
Expand Down
4 changes: 2 additions & 2 deletions python/nav/mibs/powernet_mib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Copyright (C) 2008-2014 Uninett AS
# Copyright (C) 2022 Sikt
#
# This file is part of Network Administration Visualized (NAV).
#
Expand All @@ -14,7 +15,6 @@
# along with NAV. If not, see <http://www.gnu.org/licenses/>.
#
"""A class for extracting information from APC devices"""
from six import iteritems
from twisted.internet import defer
from nav.smidumps import get_mib
from nav.mibs import reduce_index
Expand Down Expand Up @@ -101,7 +101,7 @@ def _get_pdu_bank_load_sensors(self):

result = []
column = self.nodes.get(R_PDU_LOAD_STATUS_LOAD, None)
for index, row in iteritems(banks):
for index, row in banks.items():
oid = str(column.oid + str(index))

bank_number = row.get(R_PDU_LOAD_STATUS_BANK_NUMBER, None)
Expand Down
7 changes: 2 additions & 5 deletions python/nav/mibs/pwt_3phase_mibv1.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
-- not a complete implementation of the mib --
"""
import six
from six import itervalues
from twisted.internet import defer

from nav.mibs import reduce_index
Expand All @@ -46,8 +44,7 @@ def for_table(table_name):

def decorate(method):
"""Setup link between table and function"""
name = method.func_name if six.PY2 else method.__name__
for_table.map[table_name] = name
for_table.map[table_name] = method.__name__
return method

return decorate
Expand Down Expand Up @@ -101,7 +98,7 @@ def _make_result_dict(
def _get_internal_sensors_params(self, internal_sensors):
sensors = []

for sensor in itervalues(internal_sensors):
for sensor in internal_sensors.values():
serial = sensor.get('inletIndex', None)
# The spesification says the value can be 0 - 3 but I am
# seeing 0 - 7 and only 0 has value
Expand Down
5 changes: 2 additions & 3 deletions python/nav/mibs/qbridge_mib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Copyright (C) 2009, 2011, 2012 Uninett AS
# Copyright (C) 2022 Sikt
#
# This file is part of Network Administration Visualized (NAV).
#
Expand All @@ -18,8 +19,6 @@

from twisted.internet import defer

import six

import nav.bitvector
from nav.smidumps import get_mib
from nav.mibs import mibretriever, reduce_index
Expand Down Expand Up @@ -149,7 +148,7 @@ def portlist_juniper(data):
"""
# data would normally be binary, but since Juniper ignores the spec, it's a comma
# separated ASCII string:
if isinstance(data, six.binary_type):
if isinstance(data, bytes):
try:
data = data.decode('ascii')
except UnicodeDecodeError:
Expand Down
Loading

0 comments on commit 770504d

Please sign in to comment.