BF(2.4): omit date patterns containing %f (.subsec) for Python before 2.5

pull/522/head
Yaroslav Halchenko 2013-12-27 02:08:47 -05:00
parent c6a7bc2221
commit 6815190685
1 changed files with 16 additions and 14 deletions

View File

@ -21,7 +21,7 @@ __author__ = "Cyril Jaquier and Fail2Ban Contributors"
__copyright__ = "Copyright (c) 2004 Cyril Jaquier" __copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL" __license__ = "GPL"
import time, logging import sys, time, logging
from datetemplate import DateStrptime, DateTai64n, DateEpoch, DateISO8601 from datetemplate import DateStrptime, DateTai64n, DateEpoch, DateISO8601
from threading import Lock from threading import Lock
@ -46,12 +46,13 @@ class DateDetector:
def addDefaultTemplate(self): def addDefaultTemplate(self):
self.__lock.acquire() self.__lock.acquire()
try: try:
# asctime with subsecond if sys.version_info >= (2, 5): # because of '%.f'
template = DateStrptime() # asctime with subsecond
template.setName("WEEKDAY MONTH Day Hour:Minute:Second[.subsecond] Year") template = DateStrptime()
template.setRegex("\S{3} \S{3}\s{1,2}\d{1,2} \d{2}:\d{2}:\d{2}\.\d+ \d{4}") template.setName("WEEKDAY MONTH Day Hour:Minute:Second[.subsecond] Year")
template.setPattern("%a %b %d %H:%M:%S.%f %Y") template.setRegex("\S{3} \S{3}\s{1,2}\d{1,2} \d{2}:\d{2}:\d{2}\.\d+ \d{4}")
self._appendTemplate(template) template.setPattern("%a %b %d %H:%M:%S.%f %Y")
self._appendTemplate(template)
# asctime without no subsecond # asctime without no subsecond
template = DateStrptime() template = DateStrptime()
template.setName("WEEKDAY MONTH Day Hour:Minute:Second Year") template.setName("WEEKDAY MONTH Day Hour:Minute:Second Year")
@ -101,13 +102,14 @@ class DateDetector:
template.setRegex("\d{2}/\d{2}/\d{4}:\d{2}:\d{2}:\d{2}") template.setRegex("\d{2}/\d{2}/\d{4}:\d{2}:\d{2}:\d{2}")
template.setPattern("%m/%d/%Y:%H:%M:%S") template.setPattern("%m/%d/%Y:%H:%M:%S")
self._appendTemplate(template) self._appendTemplate(template)
# proftpd 2013-11-16 21:43:03,296 if sys.version_info >= (2, 5): # because of '%.f'
# So like Exim below but with ,subsecond # proftpd 2013-11-16 21:43:03,296
template = DateStrptime() # So like Exim below but with ,subsecond
template.setName("Year-Month-Day Hour:Minute:Second[,subsecond]") template = DateStrptime()
template.setRegex("\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d+") template.setName("Year-Month-Day Hour:Minute:Second[,subsecond]")
template.setPattern("%Y-%m-%d %H:%M:%S,%f") template.setRegex("\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d+")
self._appendTemplate(template) template.setPattern("%Y-%m-%d %H:%M:%S,%f")
self._appendTemplate(template)
# Exim 2006-12-21 06:43:20 # Exim 2006-12-21 06:43:20
template = DateStrptime() template = DateStrptime()
template.setName("Year-Month-Day Hour:Minute:Second") template.setName("Year-Month-Day Hour:Minute:Second")