mirror of https://github.com/fail2ban/fail2ban
BF: Require Python 2.7+ for badips.py action
parent
5c7630c4be
commit
dfb46cfda6
|
@ -17,11 +17,13 @@
|
|||
# along with Fail2Ban; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
import sys
|
||||
if sys.version_info < (2, 7):
|
||||
raise ImportError("badips.py action requires Python >= 2.7")
|
||||
import json
|
||||
from functools import partial
|
||||
import threading
|
||||
import logging
|
||||
import sys
|
||||
if sys.version_info >= (3, ):
|
||||
from urllib.request import Request, urlopen
|
||||
from urllib.parse import urlencode
|
||||
|
|
|
@ -31,7 +31,11 @@ if sys.version_info >= (3, 3):
|
|||
import importlib.machinery
|
||||
else:
|
||||
import imp
|
||||
from collections import Mapping, OrderedDict
|
||||
from collections import Mapping
|
||||
try:
|
||||
from collections import OrderedDict
|
||||
except ImportError:
|
||||
OrderedDict = None
|
||||
|
||||
from .banmanager import BanManager
|
||||
from .jailthread import JailThread
|
||||
|
@ -62,7 +66,10 @@ class Actions(JailThread, Mapping):
|
|||
JailThread.__init__(self)
|
||||
## The jail which contains this action.
|
||||
self._jail = jail
|
||||
if OrderedDict is not None:
|
||||
self._actions = OrderedDict()
|
||||
else:
|
||||
self._actions = dict()
|
||||
## The ban manager.
|
||||
self.__banManager = BanManager()
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ if os.path.exists('config/fail2ban.conf'):
|
|||
else:
|
||||
CONFIG_DIR='/etc/fail2ban'
|
||||
|
||||
if sys.version_info >= (2,7):
|
||||
class BadIPsActionTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
@ -59,7 +60,8 @@ class BadIPsActionTest(unittest.TestCase):
|
|||
self.assertTrue(len(categories) >= 10)
|
||||
|
||||
self.assertRaises(
|
||||
ValueError, setattr, self.action, "category", "invalid-category")
|
||||
ValueError, setattr, self.action, "category",
|
||||
"invalid-category")
|
||||
|
||||
# Not valid for reporting category...
|
||||
self.assertRaises(
|
||||
|
@ -74,7 +76,8 @@ class BadIPsActionTest(unittest.TestCase):
|
|||
|
||||
def testBanaction(self):
|
||||
self.assertRaises(
|
||||
ValueError, setattr, self.action, "banaction", "invalid-action")
|
||||
ValueError, setattr, self.action, "banaction",
|
||||
"invalid-action")
|
||||
self.action.banaction = "test"
|
||||
|
||||
def testUpdateperiod(self):
|
||||
|
|
Loading…
Reference in New Issue