
    Gkc                         d Z dZdZddlZddlmZ ddlmZ ddlm	Z	 d	d
l
mZmZ  G d de      Zej                  dk  rej                  e_        y eed      sej$                  e_        yy)zCyril Jaquierz Copyright (c) 2004 Cyril JaquierGPL    N)Thread)abstractmethod   )Utils   )
excepthookprctl_set_th_namec                        e Zd ZdZd fd	Zej                  dk\  r fdZnd Ze	dd       Z
 fdZe	d        Zd	 Ze	d
        Z fdZ xZS )
JailThreada  Abstract class for threading elements in Fail2Ban.

	Attributes
	----------
	daemon
	ident
	name
	status
	active : bool
		Control the state of the thread.
	idle : bool
		Control the idle state of the thread.
	sleeptime : int
		The time the thread sleeps for in the loop.
	c                      t         t           |       d _        d  _        d _        t        j                   _         j                   fd}| _	        y )N)nameTFc                      	  | i | j                          y # t        $ r;}t        t        t        j                           nt        |       Y d }~y Y d }~y d }~ww xY wN)onStop	Exceptionsysr	   exc_infoprint)argskwargserunselfs      </usr/lib/python3/dist-packages/fail2ban/server/jailthread.pyrun_with_except_hookz1JailThread.__init__.<locals>.run_with_except_hookC   sQ    
KKM
   
1XX !	s    	A ,AA )
superr   __init__daemonactiveidler   DEFAULT_SLEEP_TIME	sleeptimer   )r   r   r   r   	__class__s   `  @r   r   zJailThread.__init__4   sP    
D""-$+$+$)++$. 	# "$(       c                 R    t        | j                         t        t        |          S r   )r
   r   r   r   
_bootstrapr   r$   s    r   r)   zJailThread._bootstrapR   s    TYY

D
,
..r%   c                 V    t        | j                         t        j                  |       S r   )r
   r   r   _Thread__bootstrapr   s    r   __bootstrapzJailThread.__bootstrapV   s    TYY

#
#D
))r%   c                      y)z0Abstract - Should provide status information.
		N )r   flavors     r   statuszJailThread.statusZ        r%   c                 8    d| _         t        t        |           y)z&Sets active flag and starts thread.
		TN)r    r   r   startr*   s    r   r5   zJailThread.start`   s     $+
D!r%   c                      y)z2Abstract - Called when thread ends (after run).
		Nr0   r-   s    r   r   zJailThread.onStopf   r3   r%   c                     d| _         y)zASets `active` property to False, to flag run method to return.
		FN)r    r-   s    r   stopzJailThread.stopl   s     $+r%   c                      y)zCAbstract - Called when thread starts, thread stops when returns.
		Nr0   r-   s    r   r   zJailThread.runq   r3   r%   c                 D    | j                   t        t        |           yy)z` Safer join, that could be called also for not started (or ended) threads (used for cleanup).
		N)r    r   r   joinr*   s    r   r;   zJailThread.joinw   s!     
[[T! r%   r   )basic)__name__
__module____qualname____doc__r   r   version_infor)   _JailThread__bootstrapr   r2   r5   r   r8   r   r;   __classcell__)r$   s   @r   r   r   #   sw     ": 0*  
"  

  
" "r%   r   r&   isAlive)
__author____copyright____license__r   	threadingr   abcr   utilsr   helpersr	   r
   r   rA   rB   r,   hasattris_aliverD   r0   r%   r   <module>rN      so   . 
2 
    3[" ["| d!+!B!B	Y	'!*** 
(r%   