Submit
Path:
~
/
/
lib
/
python3.6
/
site-packages
/
fail2ban
/
server
/
__pycache__
/
File Content:
datetemplate.cpython-36.pyc
3 UB(d�1 � @ s0 d Z dZdZddlZddlZddlmZ ddlmZm Z m Z dd lmZ ee �Zejd �Zejd�dfZejd �Zejd�Zejd�Zejd�Zejd�Zejd�Zejd�Zejd�dd� fZejd�Zejd�Zejd�Zejdej�ZG dd� de�Z G dd� de �Z!G dd � d e �Z"G d!d"� d"e �Z#dS )#z Cyril Jaquierz Copyright (c) 2004 Cyril JaquierZGPL� N)�abstractmethod� )�reGroupDictStrptime�timeRE�getTimePatternRE� )� getLoggerz(?<!(?:\(\?))(?<!\\)\((?!\?)z-^((?:\(\?\w+\))?\^?(?:\(\?\w+\))?)(.*?)(\$?)$z\1(\2)\3z((?:^|(?!<\\))\(\?[a-z]+\))z^\{UNB\}z ^\{\^LN-BEG\}z^\((?:\?:)?\^\|\\b\|\\W\)z\(\?=\\b\|\\W\|\$\)$z-^\(*(?:\(\?\w+\))?(?:\^|\(*\*\*|\((?:\?:)?\^)z!(?<!\\)(?:\$\)?|\\b|\\s|\*\*\)*)$z)^\(*(?:\(\?\w+\))?\(*\*\*|(?<!\\)\*\*\)*$c C s | j � jdd�S )Nz**� )�group�replace)�m� r �"/usr/lib/python3.6/datetemplate.py�<lambda>/ s r z(^(?:\(\?\w+\))?(?:\^|\((?:\?:)?\^(?!\|))z(?<![\\\|])(?:\$\)?)$z(?<!\%)\%[aAbBpc]z(?<!\\)\{L?EPOCH\}c @ sr e Zd ZdZdZdZdZdZdd� Zdd � Z ddd�Z ee e d d�Zdd� Z dd� Zeddd��Zedd� �ZdS )�DateTemplatez�A template which searches for and returns a date from a log line. This is an not functional abstract class which other templates should inherit from. Attributes ---------- name regex � � r r c C s. d| _ d| _d| _d| _d| _d| _d | _d S )Nr g �?r )�nameZweight�flags�hits�time�_regex�_cRegex)�selfr r r �__init__J s zDateTemplate.__init__c C s | j S )N)r )r r r r �getRegexS s zDateTemplate.getRegexTc C sv |j � }tj|�}|r&tjd|dd�}|o4tj|� }|oDtj|� }tj|�sdtd jtd |�}d| _|r�| j|dkr�t j nt jO _|dkr�d| }n d| }| jj d�s�d| j | _|r�| jt jO _|d 7 }| jt j@ o�tj|��r| jt jO _| jt j@ �r0tj|��r0| jt jO _td jtd |�}|�rX|jd�| }|| _tjd d|� d| _dS ) a� Sets regex to use for searching for date in log line. Parameters ---------- regex : str The regex the template will use for searching for a date. wordBegin : bool Defines whether the regex should be modified to search at beginning of a word, by adding special boundary r'(?=^|\b|\W)' to start of regex. Can be disabled with specifying of ** at front of regex. Default True. wordEnd : bool Defines whether the regex should be modified to search at end of a word, by adding special boundary r'(?=\b|\W|$)' to end of regex. Can be disabled with specifying of ** at end of regex. Default True. Raises ------ re.error If regular expression fails to compile r r )�countr �startz(?=^|\b|\W)z ^(?:\W{0,2})?z {^LN-BEG}z(?=\b|\W|$)r z constructed regex %sN)�strip�RE_GLOBALFLAGS�search�sub�RE_NO_WRD_BOUND_BEG�RE_NO_WRD_BOUND_END� RE_GROUPED�RE_GROUPr r � WORD_BEGIN� LINE_BEGINr � startswith�WORD_END�RE_LINE_BOUND_BEG�LINE_END�RE_LINE_BOUND_END�RE_DEL_WRD_BOUNDSr r �logSys�logr )r �regex� wordBegin�wordEndZgfZ boundBeginZboundEndr r r �setRegexV s: zDateTemplate.setRegexz!Regex used to search for date. )�docc C sV | j sRytj| j�| _ W n8 tk rP } ztjd| j| j� |�W Y dd}~X nX dS )z Compile regex by first usage. z Compile %r failed, expression %rN)r �re�compiler0 � Exceptionr. �errorr )r �er r r � _compileRegex� s zDateTemplate._compileRegexc G sF | j s| j� tjdd| j� | j j|f|�� }|rB| jd7 _|S )z1Check if regex for date matches on a log line. r z search %sr )r r: r. r/ r0 r r )r �line�args� dateMatchr r r � matchDate� s zDateTemplate.matchDateNc C s t d��dS )aQ Abstract method, which should return the date for a log line This should return the date for a log line, typically taking the date from the part of the line which matched the templates regex. This requires abstraction, therefore just raises exception. Parameters ---------- line : str Log line, of which the date should be extracted from. default_tz: if no explicit time zone is present in the line passing this will interpret it as in that time zone. Raises ------ NotImplementedError Abstract method, therefore always returns this. zgetDate() is abstractN)�NotImplementedError)r r; r= � default_tzr r r �getDate� s zDateTemplate.getDatec C s$ t jdtjdtjdtjd| ����S )Nr )�RE_EXEANC_BOUND_BEGr! �RE_EXSANC_BOUND_BEG�RE_EXLINE_BOUND_BEG�RE_EXLINE_NO_BOUNDS)�patternr r r �unboundPattern� s zDateTemplate.unboundPattern)TT)NN)�__name__� __module__�__qualname__�__doc__r'