ENH: Change all imports to "." style relative imports

pull/549/head
Steven Hiscocks 2014-01-04 13:19:09 +00:00
parent cd5c57c8dd
commit a070284a18
36 changed files with 121 additions and 137 deletions

View File

@ -26,7 +26,7 @@ __license__ = "GPL"
import logging, os import logging, os
from fail2ban.client.configreader import ConfigReader, DefinitionInitConfigReader from .configreader import ConfigReader, DefinitionInitConfigReader
# Gets the instance of the logger. # Gets the instance of the logger.
logSys = logging.getLogger(__name__) logSys = logging.getLogger(__name__)

View File

@ -23,7 +23,7 @@ __license__ = "GPL"
import logging import logging
from fail2ban.exceptions import UnknownJailException, DuplicateJailException from ..exceptions import UnknownJailException, DuplicateJailException
# Gets the instance of the logger. # Gets the instance of the logger.
logSys = logging.getLogger(__name__) logSys = logging.getLogger(__name__)

View File

@ -27,7 +27,7 @@ __license__ = "GPL"
import glob, logging, os import glob, logging, os
from ConfigParser import NoOptionError, NoSectionError from ConfigParser import NoOptionError, NoSectionError
from fail2ban.client.configparserinc import SafeConfigParserWithIncludes from .configparserinc import SafeConfigParserWithIncludes
# Gets the instance of the logger. # Gets the instance of the logger.
logSys = logging.getLogger(__name__) logSys = logging.getLogger(__name__)

View File

@ -26,9 +26,9 @@ __license__ = "GPL"
import logging import logging
from fail2ban.client.configreader import ConfigReader from .configreader import ConfigReader
from fail2ban.client.fail2banreader import Fail2banReader from .fail2banreader import Fail2banReader
from fail2ban.client.jailsreader import JailsReader from .jailsreader import JailsReader
# Gets the instance of the logger. # Gets the instance of the logger.
logSys = logging.getLogger(__name__) logSys = logging.getLogger(__name__)

View File

@ -26,7 +26,7 @@ __license__ = "GPL"
import logging import logging
from fail2ban.client.configreader import ConfigReader from .configreader import ConfigReader
# Gets the instance of the logger. # Gets the instance of the logger.
logSys = logging.getLogger(__name__) logSys = logging.getLogger(__name__)

View File

@ -26,7 +26,7 @@ __license__ = "GPL"
import logging, os, shlex import logging, os, shlex
from fail2ban.client.configreader import ConfigReader, DefinitionInitConfigReader from .configreader import ConfigReader, DefinitionInitConfigReader
# Gets the instance of the logger. # Gets the instance of the logger.
logSys = logging.getLogger(__name__) logSys = logging.getLogger(__name__)

View File

@ -27,9 +27,9 @@ __license__ = "GPL"
import logging, re, glob, os.path import logging, re, glob, os.path
import json import json
from fail2ban.client.configreader import ConfigReader from .configreader import ConfigReader
from fail2ban.client.filterreader import FilterReader from .filterreader import FilterReader
from fail2ban.client.actionreader import ActionReader from .actionreader import ActionReader
# Gets the instance of the logger. # Gets the instance of the logger.
logSys = logging.getLogger(__name__) logSys = logging.getLogger(__name__)

View File

@ -26,8 +26,8 @@ __license__ = "GPL"
import logging import logging
from fail2ban.client.configreader import ConfigReader from .configreader import ConfigReader
from fail2ban.client.jailreader import JailReader from .jailreader import JailReader
# Gets the instance of the logger. # Gets the instance of the logger.
logSys = logging.getLogger(__name__) logSys = logging.getLogger(__name__)

View File

@ -28,10 +28,10 @@ import time, logging
import os import os
import imp import imp
from fail2ban.server.banmanager import BanManager from .banmanager import BanManager
from fail2ban.server.jailthread import JailThread from .jailthread import JailThread
from fail2ban.server.action import ActionBase, CommandAction, CallingMap from .action import ActionBase, CommandAction, CallingMap
from fail2ban.server.mytime import MyTime from .mytime import MyTime
# Gets the instance of the logger. # Gets the instance of the logger.
logSys = logging.getLogger(__name__) logSys = logging.getLogger(__name__)

View File

@ -27,7 +27,7 @@ __license__ = "GPL"
from pickle import dumps, loads, HIGHEST_PROTOCOL from pickle import dumps, loads, HIGHEST_PROTOCOL
import asyncore, asynchat, socket, os, logging, sys, traceback, fcntl import asyncore, asynchat, socket, os, logging, sys, traceback, fcntl
from fail2ban import helpers from .. import helpers
# Gets the instance of the logger. # Gets the instance of the logger.
logSys = logging.getLogger(__name__) logSys = logging.getLogger(__name__)

View File

@ -27,8 +27,8 @@ __license__ = "GPL"
import logging import logging
from threading import Lock from threading import Lock
from fail2ban.server.ticket import BanTicket from .ticket import BanTicket
from fail2ban.server.mytime import MyTime from .mytime import MyTime
# Gets the instance of the logger. # Gets the instance of the logger.
logSys = logging.getLogger(__name__) logSys = logging.getLogger(__name__)

View File

@ -29,8 +29,8 @@ import json
import locale import locale
from functools import wraps from functools import wraps
from fail2ban.server.mytime import MyTime from .mytime import MyTime
from fail2ban.server.ticket import FailTicket from .ticket import FailTicket
# Gets the instance of the logger. # Gets the instance of the logger.
logSys = logging.getLogger(__name__) logSys = logging.getLogger(__name__)

View File

@ -24,7 +24,7 @@ __license__ = "GPL"
import sys, time, logging import sys, time, logging
from threading import Lock 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. # Gets the instance of the logger.
logSys = logging.getLogger(__name__) logSys = logging.getLogger(__name__)

View File

@ -29,8 +29,8 @@ import logging
from datetime import datetime from datetime import datetime
from datetime import timedelta from datetime import timedelta
from fail2ban.server.mytime import MyTime from .mytime import MyTime
from fail2ban.server import iso8601 from . import iso8601
logSys = logging.getLogger(__name__) logSys = logging.getLogger(__name__)

View File

@ -27,8 +27,8 @@ __license__ = "GPL"
from threading import Lock from threading import Lock
import logging import logging
from fail2ban.server.faildata import FailData from .faildata import FailData
from fail2ban.server.ticket import FailTicket from .ticket import FailTicket
# Gets the instance of the logger. # Gets the instance of the logger.
logSys = logging.getLogger(__name__) logSys = logging.getLogger(__name__)

View File

@ -23,15 +23,14 @@ __license__ = "GPL"
import logging, re, os, fcntl, time, sys, locale, codecs import logging, re, os, fcntl, time, sys, locale, codecs
from fail2ban.server.failmanager import FailManagerEmpty from .failmanager import FailManagerEmpty, FailManager
from fail2ban.server.failmanager import FailManager from .ticket import FailTicket
from fail2ban.server.ticket import FailTicket from .jailthread import JailThread
from fail2ban.server.jailthread import JailThread from .datedetector import DateDetector
from fail2ban.server.datedetector import DateDetector from .datetemplate import DatePatternRegex, DateISO8601, DateEpoch, DateTai64n
from fail2ban.server.datetemplate import DatePatternRegex, DateISO8601, DateEpoch, DateTai64n from .mytime import MyTime
from fail2ban.server.mytime import MyTime from .failregex import FailRegex, Regex, RegexException
from fail2ban.server.failregex import FailRegex, Regex, RegexException from .action import CommandAction
from fail2ban.server.action import CommandAction
# Gets the instance of the logger. # Gets the instance of the logger.
logSys = logging.getLogger(__name__) logSys = logging.getLogger(__name__)

View File

@ -27,9 +27,9 @@ import time, logging, fcntl
import gamin import gamin
from fail2ban.server.failmanager import FailManagerEmpty from .failmanager import FailManagerEmpty
from fail2ban.server.filter import FileFilter from .filter import FileFilter
from fail2ban.server.mytime import MyTime from .mytime import MyTime
# Gets the instance of the logger. # Gets the instance of the logger.
logSys = logging.getLogger(__name__) logSys = logging.getLogger(__name__)

View File

@ -26,9 +26,9 @@ __license__ = "GPL"
import time, logging, os import time, logging, os
from fail2ban.server.failmanager import FailManagerEmpty from .failmanager import FailManagerEmpty
from fail2ban.server.filter import FileFilter from .filter import FileFilter
from fail2ban.server.mytime import MyTime from .mytime import MyTime
# Gets the instance of the logger. # Gets the instance of the logger.
logSys = logging.getLogger(__name__) logSys = logging.getLogger(__name__)

View File

@ -27,9 +27,9 @@ import time, logging, pyinotify
from distutils.version import LooseVersion from distutils.version import LooseVersion
from os.path import dirname, sep as pathsep from os.path import dirname, sep as pathsep
from fail2ban.server.failmanager import FailManagerEmpty from .failmanager import FailManagerEmpty
from fail2ban.server.filter import FileFilter from .filter import FileFilter
from fail2ban.server.mytime import MyTime from .mytime import MyTime
if not hasattr(pyinotify, '__version__') \ if not hasattr(pyinotify, '__version__') \

View File

@ -29,9 +29,9 @@ from systemd import journal
if LooseVersion(getattr(journal, '__version__', "0")) < '204': if LooseVersion(getattr(journal, '__version__', "0")) < '204':
raise ImportError("Fail2Ban requires systemd >= 204") raise ImportError("Fail2Ban requires systemd >= 204")
from fail2ban.server.failmanager import FailManagerEmpty from .failmanager import FailManagerEmpty
from fail2ban.server.filter import JournalFilter from .filter import JournalFilter
from fail2ban.server.mytime import MyTime from .mytime import MyTime
# Gets the instance of the logger. # Gets the instance of the logger.

View File

@ -25,7 +25,7 @@ __license__ = "GPL"
import Queue, logging import Queue, logging
from fail2ban.server.actions import Actions from .actions import Actions
# Gets the instance of the logger. # Gets the instance of the logger.
logSys = logging.getLogger(__name__) logSys = logging.getLogger(__name__)

View File

@ -23,8 +23,8 @@ __license__ = "GPL"
from threading import Lock from threading import Lock
from fail2ban.exceptions import DuplicateJailException, UnknownJailException from ..exceptions import DuplicateJailException, UnknownJailException
from fail2ban.server.jail import Jail from .jail import Jail
## ##
# Handles the jails. # Handles the jails.

View File

@ -27,14 +27,13 @@ __license__ = "GPL"
from threading import Lock, RLock from threading import Lock, RLock
import logging, logging.handlers, sys, os, signal import logging, logging.handlers, sys, os, signal
from fail2ban.server.jails import Jails from .jails import Jails
from fail2ban.server.filter import FileFilter, JournalFilter from .filter import FileFilter, JournalFilter
from fail2ban.server.transmitter import Transmitter from .transmitter import Transmitter
from fail2ban.server.asyncserver import AsyncServer from .asyncserver import AsyncServer, AsyncServerException
from fail2ban.server.asyncserver import AsyncServerException from .database import Fail2BanDb
from fail2ban.server.database import Fail2BanDb from .action import CommandAction
from fail2ban.server.action import CommandAction from .. import version
from fail2ban import version
# Gets the instance of the logger. # Gets the instance of the logger.
logSys = logging.getLogger(__name__) logSys = logging.getLogger(__name__)

View File

@ -27,9 +27,9 @@ __license__ = "GPL"
import unittest, time import unittest, time
import sys, os, tempfile import sys, os, tempfile
from fail2ban.server.actions import Actions from ..server.actions import Actions
from fail2ban.tests.dummyjail import DummyJail from .dummyjail import DummyJail
from fail2ban.tests.utils import LogCaptureTestCase from .utils import LogCaptureTestCase
TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), "files") TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), "files")

View File

@ -27,9 +27,9 @@ __license__ = "GPL"
import time import time
import logging, sys 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): class CommandActionTest(LogCaptureTestCase):

View File

@ -26,8 +26,8 @@ __license__ = "GPL"
import unittest import unittest
from fail2ban.server.banmanager import BanManager from ..server.banmanager import BanManager
from fail2ban.server.ticket import BanTicket from ..server.ticket import BanTicket
class AddFailure(unittest.TestCase): class AddFailure(unittest.TestCase):

View File

@ -23,13 +23,13 @@ __license__ = "GPL"
import os, shutil, sys, tempfile, unittest import os, shutil, sys, tempfile, unittest
from fail2ban.client.configreader import ConfigReader from ..client.configreader import ConfigReader
from fail2ban.client.jailreader import JailReader from ..client.jailreader import JailReader
from fail2ban.client.filterreader import FilterReader from ..client.filterreader import FilterReader
from fail2ban.client.jailsreader import JailsReader from ..client.jailsreader import JailsReader
from fail2ban.client.actionreader import ActionReader from ..client.actionreader import ActionReader
from fail2ban.client.configurator import Configurator from ..client.configurator import Configurator
from fail2ban.tests.utils import LogCaptureTestCase from .utils import LogCaptureTestCase
TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), "files") TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), "files")
if os.path.exists('config/fail2ban.conf'): if os.path.exists('config/fail2ban.conf'):

View File

@ -28,11 +28,11 @@ import tempfile
import sqlite3 import sqlite3
import shutil import shutil
from fail2ban.server.database import Fail2BanDb from ..server.database import Fail2BanDb
from fail2ban.server.filter import FileContainer from ..server.filter import FileContainer
from fail2ban.server.mytime import MyTime from ..server.mytime import MyTime
from fail2ban.server.ticket import FailTicket from ..server.ticket import FailTicket
from fail2ban.tests.dummyjail import DummyJail from .dummyjail import DummyJail
class DatabaseTest(unittest.TestCase): class DatabaseTest(unittest.TestCase):

View File

@ -25,10 +25,10 @@ __copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL" __license__ = "GPL"
import unittest, calendar, time, datetime, re, pprint import unittest, calendar, time, datetime, re, pprint
from fail2ban.server.datedetector import DateDetector from ..server.datedetector import DateDetector
from fail2ban.server.datetemplate import DateTemplate from ..server.datetemplate import DateTemplate
from fail2ban.server.iso8601 import Utc from ..server.iso8601 import Utc
from fail2ban.tests.utils import setUpMyTime, tearDownMyTime from .utils import setUpMyTime, tearDownMyTime
class DateDetectorTest(unittest.TestCase): class DateDetectorTest(unittest.TestCase):

View File

@ -26,8 +26,8 @@ __license__ = "GPL"
import unittest, socket, time, pickle import unittest, socket, time, pickle
from fail2ban.server.failmanager import FailManager, FailManagerEmpty from ..server.failmanager import FailManager, FailManagerEmpty
from fail2ban.server.ticket import FailTicket from ..server.ticket import FailTicket
class AddFailure(unittest.TestCase): class AddFailure(unittest.TestCase):

View File

@ -34,19 +34,16 @@ try:
except ImportError: except ImportError:
journal = None journal = None
from fail2ban.server.jail import Jail from ..server.jail import Jail
from fail2ban.server.filterpoll import FilterPoll from ..server.filterpoll import FilterPoll
from fail2ban.server.filter import Filter, FileFilter, DNSUtils from ..server.filter import Filter, FileFilter, DNSUtils
from fail2ban.server.failmanager import FailManager from ..server.failmanager import FailManager, FailManagerEmpty
from fail2ban.server.failmanager import FailManagerEmpty from ..server.mytime import MyTime
from fail2ban.server.mytime import MyTime from .utils import setUpMyTime, tearDownMyTime, mtimesleep, LogCaptureTestCase
from fail2ban.tests.utils import setUpMyTime, tearDownMyTime from .dummyjail import DummyJail
from fail2ban.tests.utils import mtimesleep, LogCaptureTestCase
TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), "files") 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 # yoh: per Steven Hiscocks's insight while troubleshooting
# https://github.com/fail2ban/fail2ban/issues/103#issuecomment-15542836 # https://github.com/fail2ban/fail2ban/issues/103#issuecomment-15542836
# adding a sufficiently large buffer might help to guarantee that # adding a sufficiently large buffer might help to guarantee that

View File

@ -28,8 +28,8 @@ import shutil
from glob import glob from glob import glob
from fail2ban.tests.utils import mbasename, TraceBack, FormatterWithTraceBack from .utils import mbasename, TraceBack, FormatterWithTraceBack
from fail2ban.helpers import formatExceptionInfo from ..helpers import formatExceptionInfo
class HelpersTest(unittest.TestCase): class HelpersTest(unittest.TestCase):

View File

@ -30,9 +30,9 @@ else:
import simplejson as json import simplejson as json
next = lambda x: x.next() next = lambda x: x.next()
from fail2ban.server.filter import Filter from ..server.filter import Filter
from fail2ban.client.filterreader import FilterReader from ..client.filterreader import FilterReader
from fail2ban.tests.utils import setUpMyTime, tearDownMyTime from .utils import setUpMyTime, tearDownMyTime
TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), "files") TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), "files")
if os.path.exists('config/fail2ban.conf'): if os.path.exists('config/fail2ban.conf'):

View File

@ -26,11 +26,11 @@ __license__ = "GPL"
import unittest, socket, time, tempfile, os, locale, sys, logging import unittest, socket, time, tempfile, os, locale, sys, logging
from fail2ban.server.failregex import Regex, FailRegex, RegexException from ..server.failregex import Regex, FailRegex, RegexException
from fail2ban.server.server import Server, logSys from ..server.server import Server, logSys
from fail2ban.server.jail import Jail from ..server.jail import Jail
from fail2ban.exceptions import UnknownJailException from ..exceptions import UnknownJailException
from fail2ban.tests.utils import LogCaptureTestCase from .utils import LogCaptureTestCase
#from bin.fail2ban-client import Fail2banClient #from bin.fail2ban-client import Fail2banClient
try: try:
from fail2ban.server import filtersystemd from fail2ban.server import filtersystemd

View File

@ -26,8 +26,8 @@ __license__ = "GPL"
import unittest, time, tempfile, os, threading import unittest, time, tempfile, os, threading
from fail2ban.server.asyncserver import AsyncServer, AsyncServerException from ..server.asyncserver import AsyncServer, AsyncServerException
from fail2ban.client.csocket import CSocket from ..client.csocket import CSocket
class Socket(unittest.TestCase): class Socket(unittest.TestCase):

View File

@ -25,16 +25,9 @@ __license__ = "GPL"
import logging, os, re, traceback, time, unittest, sys import logging, os, re, traceback, time, unittest, sys
from os.path import basename, dirname from os.path import basename, dirname
from StringIO import StringIO from StringIO import StringIO
import json
if sys.version_info >= (2, 6): from ..server.mytime import MyTime
import json
else:
try:
import simplejson as json
except ImportError:
json = None
from fail2ban.server.mytime import MyTime
logSys = logging.getLogger(__name__) logSys = logging.getLogger(__name__)
@ -138,19 +131,18 @@ def tearDownMyTime():
def gatherTests(regexps=None, no_network=False): def gatherTests(regexps=None, no_network=False):
# Import all the test cases here instead of a module level to # Import all the test cases here instead of a module level to
# avoid circular imports # avoid circular imports
from fail2ban.tests import banmanagertestcase from . import banmanagertestcase
from fail2ban.tests import clientreadertestcase from . import clientreadertestcase
from fail2ban.tests import failmanagertestcase from . import failmanagertestcase
from fail2ban.tests import filtertestcase from . import filtertestcase
from fail2ban.tests import servertestcase from . import servertestcase
from fail2ban.tests import datedetectortestcase from . import datedetectortestcase
from fail2ban.tests import actiontestcase from . import actiontestcase
from fail2ban.tests import actionstestcase from . import actionstestcase
from fail2ban.tests import sockettestcase from . import sockettestcase
from fail2ban.tests import misctestcase from . import misctestcase
from fail2ban.tests import databasetestcase from . import databasetestcase
if json: from . import samplestestcase
from fail2ban.tests import samplestestcase
if not regexps: # pragma: no cover if not regexps: # pragma: no cover
tests = unittest.TestSuite() tests = unittest.TestSuite()
@ -207,30 +199,27 @@ def gatherTests(regexps=None, no_network=False):
# DateDetector # DateDetector
tests.addTest(unittest.makeSuite(datedetectortestcase.DateDetectorTest)) tests.addTest(unittest.makeSuite(datedetectortestcase.DateDetectorTest))
if json: # Filter Regex tests with sample logs
# Filter Regex tests with sample logs tests.addTest(unittest.makeSuite(samplestestcase.FilterSamplesRegex))
tests.addTest(unittest.makeSuite(samplestestcase.FilterSamplesRegex))
else:
logSys.warning("I: Skipping filter samples testing. No simplejson/json module")
# #
# Extensive use-tests of different available filters backends # Extensive use-tests of different available filters backends
# #
from fail2ban.server.filterpoll import FilterPoll from ..server.filterpoll import FilterPoll
filters = [FilterPoll] # always available filters = [FilterPoll] # always available
# Additional filters available only if external modules are available # Additional filters available only if external modules are available
# yoh: Since I do not know better way for parametric tests # yoh: Since I do not know better way for parametric tests
# with good old unittest # with good old unittest
try: try:
from fail2ban.server.filtergamin import FilterGamin from ..server.filtergamin import FilterGamin
filters.append(FilterGamin) filters.append(FilterGamin)
except Exception, e: # pragma: no cover except Exception, e: # pragma: no cover
logSys.warning("Skipping gamin backend testing. Got exception '%s'" % e) logSys.warning("Skipping gamin backend testing. Got exception '%s'" % e)
try: try:
from fail2ban.server.filterpyinotify import FilterPyinotify from ..server.filterpyinotify import FilterPyinotify
filters.append(FilterPyinotify) filters.append(FilterPyinotify)
except Exception, e: # pragma: no cover except Exception, e: # pragma: no cover
logSys.warning("I: Skipping pyinotify backend testing. Got exception '%s'" % e) 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( tests.addTest(unittest.makeSuite(
filtertestcase.get_monitor_failures_testcase(Filter_))) filtertestcase.get_monitor_failures_testcase(Filter_)))
try: # pragma: systemd no cover 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))) tests.addTest(unittest.makeSuite(filtertestcase.get_monitor_failures_journal_testcase(FilterSystemd)))
except Exception, e: # pragma: no cover except Exception, e: # pragma: no cover
logSys.warning("I: Skipping systemd backend testing. Got exception '%s'" % e) logSys.warning("I: Skipping systemd backend testing. Got exception '%s'" % e)