mirror of https://github.com/fail2ban/fail2ban
Merge pull request #647 from yarikoptic/0.8
Minor fixes for claimed compatibility with 2.4 and 2.5 -- not to be "merged" into 0.9pull/651/head^2
commit
dfac2f700a
|
@ -4,9 +4,16 @@
|
|||
|_| \__,_|_|_/___|_.__/\__,_|_||_|
|
||||
|
||||
================================================================================
|
||||
Fail2Ban (version 0.8.13) 2014/03/15
|
||||
Fail2Ban (version 0.8.13.dev) 2014/??/??
|
||||
================================================================================
|
||||
|
||||
ver. 0.8.14 (2014/??/??) - take-care-of-the-elderly
|
||||
-----------
|
||||
|
||||
- Fixes:
|
||||
- minor fixes for claimed Python 2.4 and 2.5 compatibility
|
||||
|
||||
|
||||
ver. 0.8.13 (2014/03/15) - maintenance-only-from-now-on
|
||||
-----------
|
||||
|
||||
|
|
|
@ -37,6 +37,42 @@ import logging, re, os, fcntl, time, shlex, subprocess
|
|||
# Gets the instance of the logger.
|
||||
logSys = logging.getLogger("fail2ban.filter")
|
||||
|
||||
|
||||
# For compatibility with elderly Pythons, left defined regardless of
|
||||
# the version for testing against stock version
|
||||
|
||||
hexDict = {
|
||||
'0':'0000', '1':'0001', '2':'0010', '3':'0011', '4':'0100', '5':'0101',
|
||||
'6':'0110', '7':'0111', '8':'1000', '9':'1001', 'a':'1010', 'b':'1011',
|
||||
'c':'1100', 'd':'1101', 'e':'1110', 'f':'1111', 'l':''}
|
||||
|
||||
def _bin(n):
|
||||
"""
|
||||
A foolishly simple look-up method of getting binary string from an integer
|
||||
This happens to be faster than all other ways!!!
|
||||
|
||||
Copyright: 2009, Vishal Sapre
|
||||
License: MIT
|
||||
Origin: http://code.activestate.com/recipes/576847/
|
||||
"""
|
||||
# =========================================================
|
||||
# create hex of int, remove '0x'. now for each hex char,
|
||||
# look up binary string, append in list and join at the end.
|
||||
# =========================================================
|
||||
# yoh: added 0b prefix and .lower() for when converting from long
|
||||
# We know how to deal only with positives here
|
||||
assert(n >= 0)
|
||||
nbin = ''.join([hexDict[hstr] for hstr in hex(n)[2:].lower()])
|
||||
# to unify appearance with stock bin()
|
||||
nbin = nbin.lstrip('0')
|
||||
if not nbin: # got empty
|
||||
nbin = '0'
|
||||
return '0b' + nbin
|
||||
|
||||
if sys.version_info < (2, 6):
|
||||
bin = _bin
|
||||
|
||||
|
||||
##
|
||||
# Log reader class.
|
||||
#
|
||||
|
|
|
@ -211,6 +211,6 @@ class ProcessPyinotify(pyinotify.ProcessEvent):
|
|||
def process_default(self, event):
|
||||
try:
|
||||
self.__FileFilter.callback(event, origin='Default ')
|
||||
except Exception as e:
|
||||
except Exception, e:
|
||||
logSys.error("Error in FilterPyinotify callback: %s",
|
||||
e, exc_info=logSys.getEffectiveLevel() <= logging.DEBUG)
|
||||
|
|
|
@ -158,6 +158,20 @@ class BasicFilter(unittest.TestCase):
|
|||
self.filter.setUseDns(False)
|
||||
self.assertEqual(self.filter.getUseDns(), 'no')
|
||||
|
||||
def testBin(self):
|
||||
# compare custom _bin against stock bin
|
||||
from server.filter import _bin
|
||||
if sys.version_info >= (2, 6):
|
||||
from __builtin__ import bin
|
||||
for n in (0, 1, 10, long(1), long(4294967168)):
|
||||
self.assertEqual(_bin(n), bin(n))
|
||||
else:
|
||||
from server.filter import bin
|
||||
self.assertEqual(bin(1), '0b1')
|
||||
self.assertEqual(bin(0), '0b0')
|
||||
self.assertEqual(bin(long(10)), '0b1010')
|
||||
|
||||
|
||||
|
||||
class IgnoreIP(LogCaptureTestCase):
|
||||
|
||||
|
|
Loading…
Reference in New Issue