Skip to content

Commit

Permalink
remove py2 compatibility code
Browse files Browse the repository at this point in the history
  • Loading branch information
infothrill committed Mar 30, 2021
1 parent 982eb51 commit e30eecd
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 58 deletions.
39 changes: 10 additions & 29 deletions dyndnsc/common/six.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,19 @@

"""Module for providing python compatibility across interpreter versions."""

import sys
import inspect
import ipaddress as _ipaddress

# collect most py23 madness here
PY3 = sys.version_info[0] == 3
if PY3:
getargspec = inspect.getfullargspec # pylint: disable=invalid-name
string_types = (str,) # pylint: disable=invalid-name
from io import StringIO # noqa: @UnresolvedImport @UnusedImport pylint: disable=unused-import,import-error
else:
getargspec = inspect.getargspec # pylint: disable=invalid-name
string_types = (basestring,) # noqa: @UndefinedName pylint: disable=undefined-variable,invalid-name
from cStringIO import StringIO # noqa: @UnresolvedImport @UnusedImport pylint: disable=unused-import,import-error
getargspec = inspect.getfullargspec # pylint: disable=invalid-name
string_types = (str,) # pylint: disable=invalid-name
from io import StringIO # noqa: @UnresolvedImport @UnusedImport pylint: disable=unused-import,import-error


if PY3:
import ipaddress as _ipaddress
def ipaddress(addr):
"""Return an ipaddress.ip_address object from the given string IP."""
return _ipaddress.ip_address(addr)

def ipaddress(addr):
"""Return an ipaddress.ip_address object from the given string IP."""
return _ipaddress.ip_address(addr)

def ipnetwork(addr):
"""Return an ipaddress.ip_network object from the given string IP."""
return _ipaddress.ip_network(addr)
else:
import IPy as _IPy # @UnresolvedImport pylint: disable=import-error

def ipaddress(addr):
"""Return an IPy.IP object from the given string IP."""
return _IPy.IP(addr)

def ipnetwork(addr):
"""Return an IPy.IP object from the given string IP."""
return _IPy.IP(addr)
def ipnetwork(addr):
"""Return an ipaddress.ip_network object from the given string IP."""
return _ipaddress.ip_network(addr)
5 changes: 1 addition & 4 deletions dyndnsc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

import logging
import os
try:
import configparser
except ImportError:
import ConfigParser as configparser
import configparser


from .resources import get_filename, PRESETS_INI
Expand Down
6 changes: 1 addition & 5 deletions dyndnsc/detector/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""Module containing logic for command based detectors."""

from .base import IPDetector
from ..common.six import PY3


class IPDetector_Command(IPDetector):
Expand Down Expand Up @@ -34,10 +33,7 @@ def setHostname(self, hostname):

def detect(self):
"""Detect and return the IP address."""
if PY3: # py23
import subprocess # noqa: S404 @UnresolvedImport pylint: disable=import-error
else:
import commands as subprocess # @UnresolvedImport pylint: disable=import-error
import subprocess # noqa: S404 @UnresolvedImport pylint: disable=import-error
try:
theip = subprocess.getoutput(self.opts_command) # noqa: S605
except Exception:
Expand Down
12 changes: 2 additions & 10 deletions dyndnsc/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@
import unittest
import argparse
import os
# py23
try:
import configparser
except ImportError:
import ConfigParser as configparser
import configparser

from dyndnsc.common.six import PY3
from dyndnsc.common.six import StringIO
from dyndnsc import cli

Expand All @@ -36,10 +31,7 @@ def test_list_presets(self):
detector-url = http://ip.example.com/
detector-parser = plain"""
parser = configparser.ConfigParser()
if PY3:
parser.read_file(StringIO(sample_config))
else:
parser.readfp(StringIO(sample_config)) # pylint: disable=deprecated-method
parser.read_file(StringIO(sample_config))
output = StringIO()
cli.list_presets(parser, out=output)
buf = output.getvalue()
Expand Down
12 changes: 2 additions & 10 deletions dyndnsc/tests/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
"""Tests for the conf module."""

import unittest
# py23
try:
import configparser
except ImportError:
import ConfigParser as configparser
import configparser

from dyndnsc.common.six import PY3
from dyndnsc.common.six import StringIO

from dyndnsc.conf import get_configuration, collect_config
Expand Down Expand Up @@ -56,10 +51,7 @@ def test_collect_configuration(self):
detector-parser = plain
"""
parser = configparser.ConfigParser()
if PY3:
parser.read_file(StringIO(sample_config))
else:
parser.readfp(StringIO(sample_config)) # pylint: disable=deprecated-method
parser.read_file(StringIO(sample_config))
config = collect_config(parser)
self.assertEqual(dict, type(config))
self.assertTrue("testconfig" in config)
Expand Down

0 comments on commit e30eecd

Please sign in to comment.