Skip to content

Commit

Permalink
Remove six from other parts
Browse files Browse the repository at this point in the history
  • Loading branch information
johannaengland committed Mar 23, 2022
1 parent ff7441f commit 4c9e477
Show file tree
Hide file tree
Showing 23 changed files with 69 additions and 148 deletions.
5 changes: 2 additions & 3 deletions python/nav/asyncdns.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Copyright (C) 2008-2011 Uninett AS
# Copyright (C) 2022 Sikt
#
# This file is part of Network Administration Visualized (NAV).
#
Expand Down Expand Up @@ -44,8 +45,6 @@
from twisted.names.error import DNSServerError, DNSNameError
from twisted.names.error import DNSNotImplementedError, DNSQueryRefusedError

import six


def reverse_lookup(addresses):
"""Runs parallel reverse DNS lookups for addresses.
Expand Down Expand Up @@ -136,7 +135,7 @@ class ForwardResolver(Resolver):
def lookup(self, name):
"""Returns a deferred object with all records related to hostname"""

if isinstance(name, six.text_type):
if isinstance(name, str):
name = name.encode('idna')

resolver = next(self._resolvers)
Expand Down
9 changes: 3 additions & 6 deletions python/nav/bitvector.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Copyright (C) 2007, 2009 Uninett AS
# Copyright (C) 2022 Sikt
#
# This file is part of Network Administration Visualized (NAV).
#
Expand All @@ -18,10 +19,6 @@
import array
import re

import six

from .six import encode_array


class BitVector(object):
"""
Expand All @@ -38,7 +35,7 @@ def __init__(self, octetstring):
self.vector = array.array("B", octetstring)

def to_bytes(self):
return encode_array(self.vector)
return self.vector.tobytes()

def __len__(self):
return len(self.vector) * 8
Expand Down Expand Up @@ -85,7 +82,7 @@ def from_hex(cls, hexstring):
if len(hexstring) % 2 != 0:
raise ValueError("hexstring must contain an even number of digits")
hex_octets = [hexstring[i : i + 2] for i in range(0, len(hexstring), 2)]
octetstring = b''.join([six.int2byte(int(octet, 16)) for octet in hex_octets])
octetstring = b''.join([bytes((int(octet, 16),)) for octet in hex_octets])
return cls(octetstring)

def to_binary(self):
Expand Down
8 changes: 4 additions & 4 deletions python/nav/bulkimport.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Copyright (C) 2010, 2011, 2013-2015 Uninett AS
# Copyright (C) 2022 Sikt
#
# This file is part of Network Administration Visualized (NAV).
#
Expand All @@ -22,7 +23,6 @@
import json

from django.core.exceptions import ValidationError
import six

from nav.models.fields import PointField
from nav.models.manage import Netbox, Room, Organization
Expand All @@ -39,7 +39,7 @@
from nav.bulkparse import BulkParseError


class BulkImporter(six.Iterator):
class BulkImporter:
"""Abstract bulk import iterator"""

def __init__(self, parser):
Expand All @@ -51,7 +51,7 @@ def __iter__(self):
def __next__(self):
"""Parses and returns next line"""
try:
row = six.next(self.parser)
row = next(self.parser)
row = self._decode_as_utf8(row)
objects = self._create_objects_from_row(row)
except BulkParseError as error:
Expand All @@ -62,7 +62,7 @@ def __next__(self):
def _decode_as_utf8(row):
"""Decodes all unicode values in row as utf-8 strings"""
for key, value in row.items():
if isinstance(value, six.binary_type):
if isinstance(value, bytes):
row[key] = value.decode('utf-8')
return row

Expand Down
19 changes: 8 additions & 11 deletions python/nav/bulkparse.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Copyright (C) 2010-2015 Uninett AS
# Copyright (C) 2022 Sikt
#
# This file is part of Network Administration Visualized (NAV).
#
Expand All @@ -22,7 +23,6 @@
import io
import json

import six
from IPy import IP

from nav.django.validators import is_valid_point_string
Expand All @@ -37,7 +37,7 @@
)


class BulkParser(six.Iterator):
class BulkParser:
"""Abstract base class for bulk parsers"""

format = ()
Expand All @@ -49,13 +49,10 @@ def __init__(self, data, delimiter=None):
if hasattr(data, 'seek'):
self.data = data
else:
if six.PY3:
if isinstance(data, six.binary_type):
self.data = io.StringIO(data.decode('utf-8'))
else:
self.data = io.StringIO(data)
if isinstance(data, bytes):
self.data = io.StringIO(data.decode('utf-8'))
else:
self.data = io.BytesIO(data)
self.data = io.StringIO(data)

if delimiter is None:
try:
Expand Down Expand Up @@ -85,7 +82,7 @@ def __iter__(self):

def __next__(self):
"""Generate next parsed row"""
row = six.next(self.reader)
row = next(self.reader)
# although the DictReader doesn't return blank lines, we want
# to count them so we can pinpoint errors exactly within the
# source file.
Expand Down Expand Up @@ -139,7 +136,7 @@ def get_header(cls):

# don't complain about simple iterators, mr. Pylint!
# pylint: disable=R0903
class CommentStripper(six.Iterator):
class CommentStripper:
"""Iterator that strips comments from the input iterator"""

COMMENT_PATTERN = re.compile(r'\W*#[^\n\r]*')
Expand All @@ -152,7 +149,7 @@ def __iter__(self):

def __next__(self):
"""Returns next line"""
line = six.next(self.source_iterator)
line = next(self.source_iterator)
return self.COMMENT_PATTERN.sub('', line)


Expand Down
7 changes: 2 additions & 5 deletions python/nav/colors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Copyright (C) 2013, 2019 Uninett AS
# Copyright (C) 2022 Sikt
#
# This file is part of Network Administration Visualized (NAV).
#
Expand Down Expand Up @@ -31,7 +32,6 @@
COLOR_WHITE,
COLOR_YELLOW,
)
import six

__all__ = [
'COLOR_BLACK',
Expand Down Expand Up @@ -63,10 +63,7 @@
if not _set_color:
_is_term = False

if six.PY3:
_term = sys.stdout.buffer
else:
_term = sys.stdout
_term = sys.stdout.buffer


def colorize(color):
Expand Down
6 changes: 2 additions & 4 deletions python/nav/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import configparser
import pkg_resources

import six

from nav.errors import GeneralException
from . import buildconf

Expand Down Expand Up @@ -80,7 +78,7 @@ def read_flat_config(config_file, delimiter='='):
:returns: dictionary of the key/value pairs that were read.
"""

if isinstance(config_file, six.string_types):
if isinstance(config_file, str):
config_file = open_configfile(config_file)

configuration = {}
Expand Down Expand Up @@ -109,7 +107,7 @@ def getconfig(configfile, defaults=None):
section as values.
"""
if isinstance(configfile, six.string_types):
if isinstance(configfile, str):
configfile = open_configfile(configfile)

config = configparser.RawConfigParser(defaults)
Expand Down
5 changes: 2 additions & 3 deletions python/nav/event2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Copyright (C) 2015 Uninett AS
# Copyright (C) 2022 Sikt
#
# This file is part of Network Administration Visualized (NAV).
#
Expand All @@ -19,8 +20,6 @@
"""
from __future__ import absolute_import

import six

from nav.models.event import EventQueue


Expand Down Expand Up @@ -69,7 +68,7 @@ def base(self, device=None, netbox=None, subid='', varmap=None, alert_type=None)
else:
event.netbox = netbox

event.subid = six.text_type(subid)
event.subid = str(subid)

var = dict(varmap or {})
if alert_type:
Expand Down
5 changes: 2 additions & 3 deletions python/nav/eventengine/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Copyright (C) 2012 Uninett AS
# Copyright (C) 2022 Sikt
#
# This file is part of Network Administration Visualized (NAV).
#
Expand All @@ -17,8 +18,6 @@
from __future__ import unicode_literals
from configparser import NoSectionError, NoOptionError

import six

from nav.config import NAVConfigParser
from nav.util import parse_interval

Expand Down Expand Up @@ -49,7 +48,7 @@ def get_timeout_for(self, option):
an int, option is returned unchanged.
"""
if isinstance(option, six.integer_types):
if isinstance(option, int):
return option
try:
return parse_interval(self.get('timeouts', option))
Expand Down
8 changes: 3 additions & 5 deletions python/nav/eventengine/export.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Copyright (C) 2019 UNINETT
# Copyright (C) 2019 Uninett AS
# Copyright (C) 2022 Sikt
#
# This file is part of Network Administration Visualized (NAV).
#
Expand All @@ -23,7 +24,6 @@
import subprocess32 as subprocess
except ImportError:
import subprocess
import six

from nav.web.api.v1.alert_serializers import AlertQueueSerializer

Expand Down Expand Up @@ -86,8 +86,6 @@ def export(self, alert):
def _send_string(self, string):
if self.is_ok():
self._process.stdin.write(
string
if not isinstance(string, six.text_type)
else string.encode("utf-8")
string if not isinstance(string, str) else string.encode("utf-8")
)
self._process.stdin.flush()
1 change: 0 additions & 1 deletion python/nav/ipdevpoll/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

from IPy import IP

import six
from twisted.internet import defer
from twisted.internet.defer import Deferred
from twisted.internet import reactor
Expand Down
14 changes: 3 additions & 11 deletions python/nav/logengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@
import datetime
import optparse

import six

import nav
import nav.logs
from nav import db
Expand Down Expand Up @@ -322,10 +320,7 @@ def read_log_lines(config):
logfile = None
# open log
try:
if six.PY3:
logfile = open(filename, "r+", encoding=charset)
else:
logfile = open(filename, "r+")
logfile = open(filename, "r+", encoding=charset)
except IOError as err:
# If logfile can't be found, we ignore it. We won't needlessly
# spam the NAV admin every minute with a file not found error!
Expand All @@ -350,9 +345,6 @@ def read_log_lines(config):
logfile.close()

for line in fcon:
if six.PY2:
# Make sure the data is encoded as UTF-8 before we begin work on it
line = line.decode(charset).encode("UTF-8")
yield line


Expand Down Expand Up @@ -454,7 +446,7 @@ def add_category(category, categories, database):
def add_origin(origin, category, origins, database):
database.execute("SELECT nextval('origin_origin_seq')")
originid = database.fetchone()[0]
assert isinstance(originid, six.integer_types)
assert isinstance(originid, int)
database.execute(
"INSERT INTO origin (origin, name, " "category) VALUES (%s, %s, %s)",
(originid, origin, category),
Expand All @@ -466,7 +458,7 @@ def add_origin(origin, category, origins, database):
def add_type(facility, mnemonic, priorityid, types, database):
database.execute("SELECT nextval('log_message_type_type_seq')")
typeid = int(database.fetchone()[0])
assert isinstance(typeid, six.integer_types)
assert isinstance(typeid, int)

database.execute(
"INSERT INTO log_message_type (type, facility, "
Expand Down
Loading

0 comments on commit 4c9e477

Please sign in to comment.