"Fossies" - the Fresh Open Source Software Archive

Member "fail2ban-0.11.1/fail2ban/tests/dummyjail.py" (11 Jan 2020, 2144 Bytes) of package /linux/misc/fail2ban-0.11.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "dummyjail.py": 0.10.5_vs_0.11.1.

    1 # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*-
    2 # vi: set ft=python sts=4 ts=4 sw=4 noet :
    3 
    4 # This file is part of Fail2Ban.
    5 #
    6 # Fail2Ban is free software; you can redistribute it and/or modify
    7 # it under the terms of the GNU General Public License as published by
    8 # the Free Software Foundation; either version 2 of the License, or
    9 # (at your option) any later version.
   10 #
   11 # Fail2Ban is distributed in the hope that it will be useful,
   12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14 # GNU General Public License for more details.
   15 #
   16 # You should have received a copy of the GNU General Public License
   17 # along with Fail2Ban; if not, write to the Free Software
   18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   19 
   20 # Fail2Ban developers
   21 
   22 __copyright__ = "Copyright (c) 2012 Yaroslav Halchenko"
   23 __license__ = "GPL"
   24 
   25 from threading import Lock
   26 
   27 from ..server.jail import Jail
   28 from ..server.actions import Actions
   29 
   30 
   31 class DummyActions(Actions):
   32     def checkBan(self):
   33         return self._Actions__checkBan()
   34 
   35 
   36 class DummyJail(Jail):
   37     """A simple 'jail' to suck in all the tickets generated by Filter's
   38     """
   39     def __init__(self, name='DummyJail', backend=None):
   40         self.lock = Lock()
   41         self.queue = []
   42         super(DummyJail, self).__init__(name=name, backend=backend)
   43         self.__db = None
   44         self.__actions = DummyActions(self)
   45 
   46     def __len__(self):
   47         with self.lock:
   48             return len(self.queue)
   49 
   50     def isEmpty(self):
   51         with self.lock:
   52             return not self.queue
   53 
   54     def isFilled(self):
   55         with self.lock:
   56             return bool(self.queue)
   57 
   58     def putFailTicket(self, ticket):
   59         with self.lock:
   60             self.queue.append(ticket)
   61 
   62     def getFailTicket(self):
   63         with self.lock:
   64             try:
   65                 return self.queue.pop()
   66             except IndexError:
   67                 return False
   68 
   69     @property
   70     def idle(self):
   71         return False;
   72     
   73     @idle.setter
   74     def idle(self, value):
   75         pass
   76 
   77     @property
   78     def database(self):
   79         return self.__db;
   80     
   81     @database.setter
   82     def database(self, value):
   83         self.__db = value;
   84 
   85     @property
   86     def actions(self):
   87         return self.__actions;
   88 
   89     def isAlive(self):
   90         return True;