mirror of https://github.com/fail2ban/fail2ban
python3: Default open encoding for files to UTF-8
Also tidy up unicode check in processLine, which is handled by `2to3`pull/128/merge^2
parent
5d0d362e3f
commit
df255063ae
|
@ -289,8 +289,7 @@ class Filter(JailThread):
|
||||||
def processLine(self, line):
|
def processLine(self, line):
|
||||||
"""Split the time portion from log msg and return findFailures on them
|
"""Split the time portion from log msg and return findFailures on them
|
||||||
"""
|
"""
|
||||||
if (sys.version_info >= (3,) and isinstance(line, bytes)) or \
|
if not isinstance(line, unicode):
|
||||||
(sys.version_info < (3,) and isinstance(line, str)):
|
|
||||||
try:
|
try:
|
||||||
# Decode line to UTF-8
|
# Decode line to UTF-8
|
||||||
line = line.decode('utf-8')
|
line = line.decode('utf-8')
|
||||||
|
@ -523,7 +522,7 @@ class FileContainer:
|
||||||
self.__handler = None
|
self.__handler = None
|
||||||
# Try to open the file. Raises an exception if an error occured.
|
# Try to open the file. Raises an exception if an error occured.
|
||||||
if sys.version_info >= (3,):
|
if sys.version_info >= (3,):
|
||||||
handler = open(filename, errors='ignore')
|
handler = open(filename, encoding='utf-8', errors='ignore')
|
||||||
else:
|
else:
|
||||||
handler = open(filename)
|
handler = open(filename)
|
||||||
stats = os.fstat(handler.fileno())
|
stats = os.fstat(handler.fileno())
|
||||||
|
@ -548,6 +547,10 @@ class FileContainer:
|
||||||
return self.__filename
|
return self.__filename
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
|
if sys.version_info >= (3,):
|
||||||
|
self.__handler = open(
|
||||||
|
self.__filename, encoding='utf-8', errors='ignore')
|
||||||
|
else:
|
||||||
self.__handler = open(self.__filename)
|
self.__handler = open(self.__filename)
|
||||||
# Set the file descriptor to be FD_CLOEXEC
|
# Set the file descriptor to be FD_CLOEXEC
|
||||||
fd = self.__handler.fileno()
|
fd = self.__handler.fileno()
|
||||||
|
|
Loading…
Reference in New Issue