From a070284a186d448f1197a662a62d6c76a4f1e5d6 Mon Sep 17 00:00:00 2001 From: Steven Hiscocks Date: Sat, 4 Jan 2014 13:19:09 +0000 Subject: [PATCH] ENH: Change all imports to "." style relative imports --- fail2ban/client/actionreader.py | 2 +- fail2ban/client/beautifier.py | 2 +- fail2ban/client/configreader.py | 2 +- fail2ban/client/configurator.py | 6 +-- fail2ban/client/fail2banreader.py | 2 +- fail2ban/client/filterreader.py | 2 +- fail2ban/client/jailreader.py | 6 +-- fail2ban/client/jailsreader.py | 4 +- fail2ban/server/actions.py | 8 ++-- fail2ban/server/asyncserver.py | 2 +- fail2ban/server/banmanager.py | 4 +- fail2ban/server/database.py | 4 +- fail2ban/server/datedetector.py | 2 +- fail2ban/server/datetemplate.py | 4 +- fail2ban/server/failmanager.py | 4 +- fail2ban/server/filter.py | 17 ++++----- fail2ban/server/filtergamin.py | 6 +-- fail2ban/server/filterpoll.py | 6 +-- fail2ban/server/filterpyinotify.py | 6 +-- fail2ban/server/filtersystemd.py | 6 +-- fail2ban/server/jail.py | 2 +- fail2ban/server/jails.py | 4 +- fail2ban/server/server.py | 15 ++++---- fail2ban/tests/actionstestcase.py | 6 +-- fail2ban/tests/actiontestcase.py | 4 +- fail2ban/tests/banmanagertestcase.py | 4 +- fail2ban/tests/clientreadertestcase.py | 14 +++---- fail2ban/tests/databasetestcase.py | 10 ++--- fail2ban/tests/datedetectortestcase.py | 8 ++-- fail2ban/tests/failmanagertestcase.py | 4 +- fail2ban/tests/filtertestcase.py | 17 ++++----- fail2ban/tests/misctestcase.py | 4 +- fail2ban/tests/samplestestcase.py | 6 +-- fail2ban/tests/servertestcase.py | 10 ++--- fail2ban/tests/sockettestcase.py | 4 +- fail2ban/tests/utils.py | 51 ++++++++++---------------- 36 files changed, 121 insertions(+), 137 deletions(-) diff --git a/fail2ban/client/actionreader.py b/fail2ban/client/actionreader.py index e9e4fa3e..b11deaba 100644 --- a/fail2ban/client/actionreader.py +++ b/fail2ban/client/actionreader.py @@ -26,7 +26,7 @@ __license__ = "GPL" import logging, os -from fail2ban.client.configreader import ConfigReader, DefinitionInitConfigReader +from .configreader import ConfigReader, DefinitionInitConfigReader # Gets the instance of the logger. logSys = logging.getLogger(__name__) diff --git a/fail2ban/client/beautifier.py b/fail2ban/client/beautifier.py index e6476a21..724f068f 100644 --- a/fail2ban/client/beautifier.py +++ b/fail2ban/client/beautifier.py @@ -23,7 +23,7 @@ __license__ = "GPL" import logging -from fail2ban.exceptions import UnknownJailException, DuplicateJailException +from ..exceptions import UnknownJailException, DuplicateJailException # Gets the instance of the logger. logSys = logging.getLogger(__name__) diff --git a/fail2ban/client/configreader.py b/fail2ban/client/configreader.py index 337eb31e..af81ac24 100644 --- a/fail2ban/client/configreader.py +++ b/fail2ban/client/configreader.py @@ -27,7 +27,7 @@ __license__ = "GPL" import glob, logging, os from ConfigParser import NoOptionError, NoSectionError -from fail2ban.client.configparserinc import SafeConfigParserWithIncludes +from .configparserinc import SafeConfigParserWithIncludes # Gets the instance of the logger. logSys = logging.getLogger(__name__) diff --git a/fail2ban/client/configurator.py b/fail2ban/client/configurator.py index bd0fbb79..4fab0b26 100644 --- a/fail2ban/client/configurator.py +++ b/fail2ban/client/configurator.py @@ -26,9 +26,9 @@ __license__ = "GPL" import logging -from fail2ban.client.configreader import ConfigReader -from fail2ban.client.fail2banreader import Fail2banReader -from fail2ban.client.jailsreader import JailsReader +from .configreader import ConfigReader +from .fail2banreader import Fail2banReader +from .jailsreader import JailsReader # Gets the instance of the logger. logSys = logging.getLogger(__name__) diff --git a/fail2ban/client/fail2banreader.py b/fail2ban/client/fail2banreader.py index 0df8d352..5abdc141 100644 --- a/fail2ban/client/fail2banreader.py +++ b/fail2ban/client/fail2banreader.py @@ -26,7 +26,7 @@ __license__ = "GPL" import logging -from fail2ban.client.configreader import ConfigReader +from .configreader import ConfigReader # Gets the instance of the logger. logSys = logging.getLogger(__name__) diff --git a/fail2ban/client/filterreader.py b/fail2ban/client/filterreader.py index 27b3c3c4..7650af08 100644 --- a/fail2ban/client/filterreader.py +++ b/fail2ban/client/filterreader.py @@ -26,7 +26,7 @@ __license__ = "GPL" import logging, os, shlex -from fail2ban.client.configreader import ConfigReader, DefinitionInitConfigReader +from .configreader import ConfigReader, DefinitionInitConfigReader # Gets the instance of the logger. logSys = logging.getLogger(__name__) diff --git a/fail2ban/client/jailreader.py b/fail2ban/client/jailreader.py index c6248fb9..b61d0b0a 100644 --- a/fail2ban/client/jailreader.py +++ b/fail2ban/client/jailreader.py @@ -27,9 +27,9 @@ __license__ = "GPL" import logging, re, glob, os.path import json -from fail2ban.client.configreader import ConfigReader -from fail2ban.client.filterreader import FilterReader -from fail2ban.client.actionreader import ActionReader +from .configreader import ConfigReader +from .filterreader import FilterReader +from .actionreader import ActionReader # Gets the instance of the logger. logSys = logging.getLogger(__name__) diff --git a/fail2ban/client/jailsreader.py b/fail2ban/client/jailsreader.py index 284d18d8..f0794915 100644 --- a/fail2ban/client/jailsreader.py +++ b/fail2ban/client/jailsreader.py @@ -26,8 +26,8 @@ __license__ = "GPL" import logging -from fail2ban.client.configreader import ConfigReader -from fail2ban.client.jailreader import JailReader +from .configreader import ConfigReader +from .jailreader import JailReader # Gets the instance of the logger. logSys = logging.getLogger(__name__) diff --git a/fail2ban/server/actions.py b/fail2ban/server/actions.py index 72db2947..e62ecf9b 100644 --- a/fail2ban/server/actions.py +++ b/fail2ban/server/actions.py @@ -28,10 +28,10 @@ import time, logging import os import imp -from fail2ban.server.banmanager import BanManager -from fail2ban.server.jailthread import JailThread -from fail2ban.server.action import ActionBase, CommandAction, CallingMap -from fail2ban.server.mytime import MyTime +from .banmanager import BanManager +from .jailthread import JailThread +from .action import ActionBase, CommandAction, CallingMap +from .mytime import MyTime # Gets the instance of the logger. logSys = logging.getLogger(__name__) diff --git a/fail2ban/server/asyncserver.py b/fail2ban/server/asyncserver.py index aff33a60..fb301787 100644 --- a/fail2ban/server/asyncserver.py +++ b/fail2ban/server/asyncserver.py @@ -27,7 +27,7 @@ __license__ = "GPL" from pickle import dumps, loads, HIGHEST_PROTOCOL import asyncore, asynchat, socket, os, logging, sys, traceback, fcntl -from fail2ban import helpers +from .. import helpers # Gets the instance of the logger. logSys = logging.getLogger(__name__) diff --git a/fail2ban/server/banmanager.py b/fail2ban/server/banmanager.py index 82027089..fc9eb948 100644 --- a/fail2ban/server/banmanager.py +++ b/fail2ban/server/banmanager.py @@ -27,8 +27,8 @@ __license__ = "GPL" import logging from threading import Lock -from fail2ban.server.ticket import BanTicket -from fail2ban.server.mytime import MyTime +from .ticket import BanTicket +from .mytime import MyTime # Gets the instance of the logger. logSys = logging.getLogger(__name__) diff --git a/fail2ban/server/database.py b/fail2ban/server/database.py index b0d4200c..32e4f173 100644 --- a/fail2ban/server/database.py +++ b/fail2ban/server/database.py @@ -29,8 +29,8 @@ import json import locale from functools import wraps -from fail2ban.server.mytime import MyTime -from fail2ban.server.ticket import FailTicket +from .mytime import MyTime +from .ticket import FailTicket # Gets the instance of the logger. logSys = logging.getLogger(__name__) diff --git a/fail2ban/server/datedetector.py b/fail2ban/server/datedetector.py index 91541b92..64123a34 100644 --- a/fail2ban/server/datedetector.py +++ b/fail2ban/server/datedetector.py @@ -24,7 +24,7 @@ __license__ = "GPL" import sys, time, logging from threading import Lock -from fail2ban.server.datetemplate import DatePatternRegex, DateTai64n, DateEpoch, DateISO8601 +from .datetemplate import DatePatternRegex, DateTai64n, DateEpoch, DateISO8601 # Gets the instance of the logger. logSys = logging.getLogger(__name__) diff --git a/fail2ban/server/datetemplate.py b/fail2ban/server/datetemplate.py index 0aa20472..729b951c 100644 --- a/fail2ban/server/datetemplate.py +++ b/fail2ban/server/datetemplate.py @@ -29,8 +29,8 @@ import logging from datetime import datetime from datetime import timedelta -from fail2ban.server.mytime import MyTime -from fail2ban.server import iso8601 +from .mytime import MyTime +from . import iso8601 logSys = logging.getLogger(__name__) diff --git a/fail2ban/server/failmanager.py b/fail2ban/server/failmanager.py index 6527e1ab..548e6adb 100644 --- a/fail2ban/server/failmanager.py +++ b/fail2ban/server/failmanager.py @@ -27,8 +27,8 @@ __license__ = "GPL" from threading import Lock import logging -from fail2ban.server.faildata import FailData -from fail2ban.server.ticket import FailTicket +from .faildata import FailData +from .ticket import FailTicket # Gets the instance of the logger. logSys = logging.getLogger(__name__) diff --git a/fail2ban/server/filter.py b/fail2ban/server/filter.py index 645ed30e..b4d214d1 100644 --- a/fail2ban/server/filter.py +++ b/fail2ban/server/filter.py @@ -23,15 +23,14 @@ __license__ = "GPL" import logging, re, os, fcntl, time, sys, locale, codecs -from fail2ban.server.failmanager import FailManagerEmpty -from fail2ban.server.failmanager import FailManager -from fail2ban.server.ticket import FailTicket -from fail2ban.server.jailthread import JailThread -from fail2ban.server.datedetector import DateDetector -from fail2ban.server.datetemplate import DatePatternRegex, DateISO8601, DateEpoch, DateTai64n -from fail2ban.server.mytime import MyTime -from fail2ban.server.failregex import FailRegex, Regex, RegexException -from fail2ban.server.action import CommandAction +from .failmanager import FailManagerEmpty, FailManager +from .ticket import FailTicket +from .jailthread import JailThread +from .datedetector import DateDetector +from .datetemplate import DatePatternRegex, DateISO8601, DateEpoch, DateTai64n +from .mytime import MyTime +from .failregex import FailRegex, Regex, RegexException +from .action import CommandAction # Gets the instance of the logger. logSys = logging.getLogger(__name__) diff --git a/fail2ban/server/filtergamin.py b/fail2ban/server/filtergamin.py index 73834522..6cc9c45b 100644 --- a/fail2ban/server/filtergamin.py +++ b/fail2ban/server/filtergamin.py @@ -27,9 +27,9 @@ import time, logging, fcntl import gamin -from fail2ban.server.failmanager import FailManagerEmpty -from fail2ban.server.filter import FileFilter -from fail2ban.server.mytime import MyTime +from .failmanager import FailManagerEmpty +from .filter import FileFilter +from .mytime import MyTime # Gets the instance of the logger. logSys = logging.getLogger(__name__) diff --git a/fail2ban/server/filterpoll.py b/fail2ban/server/filterpoll.py index 54eea52a..d2f553b2 100644 --- a/fail2ban/server/filterpoll.py +++ b/fail2ban/server/filterpoll.py @@ -26,9 +26,9 @@ __license__ = "GPL" import time, logging, os -from fail2ban.server.failmanager import FailManagerEmpty -from fail2ban.server.filter import FileFilter -from fail2ban.server.mytime import MyTime +from .failmanager import FailManagerEmpty +from .filter import FileFilter +from .mytime import MyTime # Gets the instance of the logger. logSys = logging.getLogger(__name__) diff --git a/fail2ban/server/filterpyinotify.py b/fail2ban/server/filterpyinotify.py index 68b0bd5e..9ab8a83a 100644 --- a/fail2ban/server/filterpyinotify.py +++ b/fail2ban/server/filterpyinotify.py @@ -27,9 +27,9 @@ import time, logging, pyinotify from distutils.version import LooseVersion from os.path import dirname, sep as pathsep -from fail2ban.server.failmanager import FailManagerEmpty -from fail2ban.server.filter import FileFilter -from fail2ban.server.mytime import MyTime +from .failmanager import FailManagerEmpty +from .filter import FileFilter +from .mytime import MyTime if not hasattr(pyinotify, '__version__') \ diff --git a/fail2ban/server/filtersystemd.py b/fail2ban/server/filtersystemd.py index 1843b5ad..d39ba280 100644 --- a/fail2ban/server/filtersystemd.py +++ b/fail2ban/server/filtersystemd.py @@ -29,9 +29,9 @@ from systemd import journal if LooseVersion(getattr(journal, '__version__', "0")) < '204': raise ImportError("Fail2Ban requires systemd >= 204") -from fail2ban.server.failmanager import FailManagerEmpty -from fail2ban.server.filter import JournalFilter -from fail2ban.server.mytime import MyTime +from .failmanager import FailManagerEmpty +from .filter import JournalFilter +from .mytime import MyTime # Gets the instance of the logger. diff --git a/fail2ban/server/jail.py b/fail2ban/server/jail.py index 83012075..7683a087 100644 --- a/fail2ban/server/jail.py +++ b/fail2ban/server/jail.py @@ -25,7 +25,7 @@ __license__ = "GPL" import Queue, logging -from fail2ban.server.actions import Actions +from .actions import Actions # Gets the instance of the logger. logSys = logging.getLogger(__name__) diff --git a/fail2ban/server/jails.py b/fail2ban/server/jails.py index 07580b2e..53b0345b 100644 --- a/fail2ban/server/jails.py +++ b/fail2ban/server/jails.py @@ -23,8 +23,8 @@ __license__ = "GPL" from threading import Lock -from fail2ban.exceptions import DuplicateJailException, UnknownJailException -from fail2ban.server.jail import Jail +from ..exceptions import DuplicateJailException, UnknownJailException +from .jail import Jail ## # Handles the jails. diff --git a/fail2ban/server/server.py b/fail2ban/server/server.py index 41393db4..7b074b26 100644 --- a/fail2ban/server/server.py +++ b/fail2ban/server/server.py @@ -27,14 +27,13 @@ __license__ = "GPL" from threading import Lock, RLock import logging, logging.handlers, sys, os, signal -from fail2ban.server.jails import Jails -from fail2ban.server.filter import FileFilter, JournalFilter -from fail2ban.server.transmitter import Transmitter -from fail2ban.server.asyncserver import AsyncServer -from fail2ban.server.asyncserver import AsyncServerException -from fail2ban.server.database import Fail2BanDb -from fail2ban.server.action import CommandAction -from fail2ban import version +from .jails import Jails +from .filter import FileFilter, JournalFilter +from .transmitter import Transmitter +from .asyncserver import AsyncServer, AsyncServerException +from .database import Fail2BanDb +from .action import CommandAction +from .. import version # Gets the instance of the logger. logSys = logging.getLogger(__name__) diff --git a/fail2ban/tests/actionstestcase.py b/fail2ban/tests/actionstestcase.py index a133b8fa..6708b403 100644 --- a/fail2ban/tests/actionstestcase.py +++ b/fail2ban/tests/actionstestcase.py @@ -27,9 +27,9 @@ __license__ = "GPL" import unittest, time import sys, os, tempfile -from fail2ban.server.actions import Actions -from fail2ban.tests.dummyjail import DummyJail -from fail2ban.tests.utils import LogCaptureTestCase +from ..server.actions import Actions +from .dummyjail import DummyJail +from .utils import LogCaptureTestCase TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), "files") diff --git a/fail2ban/tests/actiontestcase.py b/fail2ban/tests/actiontestcase.py index 6d4636a8..a0503fae 100644 --- a/fail2ban/tests/actiontestcase.py +++ b/fail2ban/tests/actiontestcase.py @@ -27,9 +27,9 @@ __license__ = "GPL" import time import logging, sys -from fail2ban.server.action import CommandAction, CallingMap +from ..server.action import CommandAction, CallingMap -from fail2ban.tests.utils import LogCaptureTestCase +from .utils import LogCaptureTestCase class CommandActionTest(LogCaptureTestCase): diff --git a/fail2ban/tests/banmanagertestcase.py b/fail2ban/tests/banmanagertestcase.py index aff16883..7dcb73a7 100644 --- a/fail2ban/tests/banmanagertestcase.py +++ b/fail2ban/tests/banmanagertestcase.py @@ -26,8 +26,8 @@ __license__ = "GPL" import unittest -from fail2ban.server.banmanager import BanManager -from fail2ban.server.ticket import BanTicket +from ..server.banmanager import BanManager +from ..server.ticket import BanTicket class AddFailure(unittest.TestCase): diff --git a/fail2ban/tests/clientreadertestcase.py b/fail2ban/tests/clientreadertestcase.py index 577ab42a..be47aea8 100644 --- a/fail2ban/tests/clientreadertestcase.py +++ b/fail2ban/tests/clientreadertestcase.py @@ -23,13 +23,13 @@ __license__ = "GPL" import os, shutil, sys, tempfile, unittest -from fail2ban.client.configreader import ConfigReader -from fail2ban.client.jailreader import JailReader -from fail2ban.client.filterreader import FilterReader -from fail2ban.client.jailsreader import JailsReader -from fail2ban.client.actionreader import ActionReader -from fail2ban.client.configurator import Configurator -from fail2ban.tests.utils import LogCaptureTestCase +from ..client.configreader import ConfigReader +from ..client.jailreader import JailReader +from ..client.filterreader import FilterReader +from ..client.jailsreader import JailsReader +from ..client.actionreader import ActionReader +from ..client.configurator import Configurator +from .utils import LogCaptureTestCase TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), "files") if os.path.exists('config/fail2ban.conf'): diff --git a/fail2ban/tests/databasetestcase.py b/fail2ban/tests/databasetestcase.py index 1a2ac053..577f732f 100644 --- a/fail2ban/tests/databasetestcase.py +++ b/fail2ban/tests/databasetestcase.py @@ -28,11 +28,11 @@ import tempfile import sqlite3 import shutil -from fail2ban.server.database import Fail2BanDb -from fail2ban.server.filter import FileContainer -from fail2ban.server.mytime import MyTime -from fail2ban.server.ticket import FailTicket -from fail2ban.tests.dummyjail import DummyJail +from ..server.database import Fail2BanDb +from ..server.filter import FileContainer +from ..server.mytime import MyTime +from ..server.ticket import FailTicket +from .dummyjail import DummyJail class DatabaseTest(unittest.TestCase): diff --git a/fail2ban/tests/datedetectortestcase.py b/fail2ban/tests/datedetectortestcase.py index 301f9e5b..0077446f 100644 --- a/fail2ban/tests/datedetectortestcase.py +++ b/fail2ban/tests/datedetectortestcase.py @@ -25,10 +25,10 @@ __copyright__ = "Copyright (c) 2004 Cyril Jaquier" __license__ = "GPL" import unittest, calendar, time, datetime, re, pprint -from fail2ban.server.datedetector import DateDetector -from fail2ban.server.datetemplate import DateTemplate -from fail2ban.server.iso8601 import Utc -from fail2ban.tests.utils import setUpMyTime, tearDownMyTime +from ..server.datedetector import DateDetector +from ..server.datetemplate import DateTemplate +from ..server.iso8601 import Utc +from .utils import setUpMyTime, tearDownMyTime class DateDetectorTest(unittest.TestCase): diff --git a/fail2ban/tests/failmanagertestcase.py b/fail2ban/tests/failmanagertestcase.py index fb452b01..5f31181d 100644 --- a/fail2ban/tests/failmanagertestcase.py +++ b/fail2ban/tests/failmanagertestcase.py @@ -26,8 +26,8 @@ __license__ = "GPL" import unittest, socket, time, pickle -from fail2ban.server.failmanager import FailManager, FailManagerEmpty -from fail2ban.server.ticket import FailTicket +from ..server.failmanager import FailManager, FailManagerEmpty +from ..server.ticket import FailTicket class AddFailure(unittest.TestCase): diff --git a/fail2ban/tests/filtertestcase.py b/fail2ban/tests/filtertestcase.py index 7f94a9f1..02dfba2f 100644 --- a/fail2ban/tests/filtertestcase.py +++ b/fail2ban/tests/filtertestcase.py @@ -34,19 +34,16 @@ try: except ImportError: journal = None -from fail2ban.server.jail import Jail -from fail2ban.server.filterpoll import FilterPoll -from fail2ban.server.filter import Filter, FileFilter, DNSUtils -from fail2ban.server.failmanager import FailManager -from fail2ban.server.failmanager import FailManagerEmpty -from fail2ban.server.mytime import MyTime -from fail2ban.tests.utils import setUpMyTime, tearDownMyTime -from fail2ban.tests.utils import mtimesleep, LogCaptureTestCase +from ..server.jail import Jail +from ..server.filterpoll import FilterPoll +from ..server.filter import Filter, FileFilter, DNSUtils +from ..server.failmanager import FailManager, FailManagerEmpty +from ..server.mytime import MyTime +from .utils import setUpMyTime, tearDownMyTime, mtimesleep, LogCaptureTestCase +from .dummyjail import DummyJail TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), "files") -from fail2ban.tests.dummyjail import DummyJail - # yoh: per Steven Hiscocks's insight while troubleshooting # https://github.com/fail2ban/fail2ban/issues/103#issuecomment-15542836 # adding a sufficiently large buffer might help to guarantee that diff --git a/fail2ban/tests/misctestcase.py b/fail2ban/tests/misctestcase.py index 54ef502d..04822e41 100644 --- a/fail2ban/tests/misctestcase.py +++ b/fail2ban/tests/misctestcase.py @@ -28,8 +28,8 @@ import shutil from glob import glob -from fail2ban.tests.utils import mbasename, TraceBack, FormatterWithTraceBack -from fail2ban.helpers import formatExceptionInfo +from .utils import mbasename, TraceBack, FormatterWithTraceBack +from ..helpers import formatExceptionInfo class HelpersTest(unittest.TestCase): diff --git a/fail2ban/tests/samplestestcase.py b/fail2ban/tests/samplestestcase.py index 4eca8ba4..e9137226 100644 --- a/fail2ban/tests/samplestestcase.py +++ b/fail2ban/tests/samplestestcase.py @@ -30,9 +30,9 @@ else: import simplejson as json next = lambda x: x.next() -from fail2ban.server.filter import Filter -from fail2ban.client.filterreader import FilterReader -from fail2ban.tests.utils import setUpMyTime, tearDownMyTime +from ..server.filter import Filter +from ..client.filterreader import FilterReader +from .utils import setUpMyTime, tearDownMyTime TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), "files") if os.path.exists('config/fail2ban.conf'): diff --git a/fail2ban/tests/servertestcase.py b/fail2ban/tests/servertestcase.py index e632840e..7159fdc3 100644 --- a/fail2ban/tests/servertestcase.py +++ b/fail2ban/tests/servertestcase.py @@ -26,11 +26,11 @@ __license__ = "GPL" import unittest, socket, time, tempfile, os, locale, sys, logging -from fail2ban.server.failregex import Regex, FailRegex, RegexException -from fail2ban.server.server import Server, logSys -from fail2ban.server.jail import Jail -from fail2ban.exceptions import UnknownJailException -from fail2ban.tests.utils import LogCaptureTestCase +from ..server.failregex import Regex, FailRegex, RegexException +from ..server.server import Server, logSys +from ..server.jail import Jail +from ..exceptions import UnknownJailException +from .utils import LogCaptureTestCase #from bin.fail2ban-client import Fail2banClient try: from fail2ban.server import filtersystemd diff --git a/fail2ban/tests/sockettestcase.py b/fail2ban/tests/sockettestcase.py index 413d8081..e668be39 100644 --- a/fail2ban/tests/sockettestcase.py +++ b/fail2ban/tests/sockettestcase.py @@ -26,8 +26,8 @@ __license__ = "GPL" import unittest, time, tempfile, os, threading -from fail2ban.server.asyncserver import AsyncServer, AsyncServerException -from fail2ban.client.csocket import CSocket +from ..server.asyncserver import AsyncServer, AsyncServerException +from ..client.csocket import CSocket class Socket(unittest.TestCase): diff --git a/fail2ban/tests/utils.py b/fail2ban/tests/utils.py index cf9e70cc..fba308c4 100644 --- a/fail2ban/tests/utils.py +++ b/fail2ban/tests/utils.py @@ -25,16 +25,9 @@ __license__ = "GPL" import logging, os, re, traceback, time, unittest, sys from os.path import basename, dirname from StringIO import StringIO +import json -if sys.version_info >= (2, 6): - import json -else: - try: - import simplejson as json - except ImportError: - json = None - -from fail2ban.server.mytime import MyTime +from ..server.mytime import MyTime logSys = logging.getLogger(__name__) @@ -138,19 +131,18 @@ def tearDownMyTime(): def gatherTests(regexps=None, no_network=False): # Import all the test cases here instead of a module level to # avoid circular imports - from fail2ban.tests import banmanagertestcase - from fail2ban.tests import clientreadertestcase - from fail2ban.tests import failmanagertestcase - from fail2ban.tests import filtertestcase - from fail2ban.tests import servertestcase - from fail2ban.tests import datedetectortestcase - from fail2ban.tests import actiontestcase - from fail2ban.tests import actionstestcase - from fail2ban.tests import sockettestcase - from fail2ban.tests import misctestcase - from fail2ban.tests import databasetestcase - if json: - from fail2ban.tests import samplestestcase + from . import banmanagertestcase + from . import clientreadertestcase + from . import failmanagertestcase + from . import filtertestcase + from . import servertestcase + from . import datedetectortestcase + from . import actiontestcase + from . import actionstestcase + from . import sockettestcase + from . import misctestcase + from . import databasetestcase + from . import samplestestcase if not regexps: # pragma: no cover tests = unittest.TestSuite() @@ -207,30 +199,27 @@ def gatherTests(regexps=None, no_network=False): # DateDetector tests.addTest(unittest.makeSuite(datedetectortestcase.DateDetectorTest)) - if json: - # Filter Regex tests with sample logs - tests.addTest(unittest.makeSuite(samplestestcase.FilterSamplesRegex)) - else: - logSys.warning("I: Skipping filter samples testing. No simplejson/json module") + # Filter Regex tests with sample logs + tests.addTest(unittest.makeSuite(samplestestcase.FilterSamplesRegex)) # # Extensive use-tests of different available filters backends # - from fail2ban.server.filterpoll import FilterPoll + from ..server.filterpoll import FilterPoll filters = [FilterPoll] # always available # Additional filters available only if external modules are available # yoh: Since I do not know better way for parametric tests # with good old unittest try: - from fail2ban.server.filtergamin import FilterGamin + from ..server.filtergamin import FilterGamin filters.append(FilterGamin) except Exception, e: # pragma: no cover logSys.warning("Skipping gamin backend testing. Got exception '%s'" % e) try: - from fail2ban.server.filterpyinotify import FilterPyinotify + from ..server.filterpyinotify import FilterPyinotify filters.append(FilterPyinotify) except Exception, e: # pragma: no cover logSys.warning("I: Skipping pyinotify backend testing. Got exception '%s'" % e) @@ -239,7 +228,7 @@ def gatherTests(regexps=None, no_network=False): tests.addTest(unittest.makeSuite( filtertestcase.get_monitor_failures_testcase(Filter_))) try: # pragma: systemd no cover - from fail2ban.server.filtersystemd import FilterSystemd + from ..server.filtersystemd import FilterSystemd tests.addTest(unittest.makeSuite(filtertestcase.get_monitor_failures_journal_testcase(FilterSystemd))) except Exception, e: # pragma: no cover logSys.warning("I: Skipping systemd backend testing. Got exception '%s'" % e)