o _@sdZdZdZddlZddlmZddlmZddlm Z d d l m Z m Z Gd d d eZ ejd kr7e je _dSee dsBe je _dSdS)z Cyril Jaquierz Copyright (c) 2004 Cyril JaquierGPLN)Thread)abstractmethod)Utils) excepthookprctl_set_th_namecs|eZdZdZdfdd ZejdkrfddZndd Ze dd d Z fd dZ ddZ e ddZ fddZZS) JailThreadaAbstract 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. NcsHtt|j|dd|_d|_d|_tj|_|j fdd}||_ dS)N)nameTFc shz |i|WdSty3}ztdurttn t|WYd}~dSWYd}~dSd}~wwN) Exceptionsysrexc_infoprint)argskwargserun.run_with_except_hook) superr __init__daemonactiveidlerDEFAULT_SLEEP_TIME sleeptimer)selfr r __class__rrr4s  zJailThread.__init__cst|jtt|Sr )r r rr _bootstrapr r!rrr%Ps zJailThread._bootstrapcCst|jt|Sr )r r r_Thread__bootstrapr&rrr __bootstrapTs  zJailThread.__bootstrapbasiccCdS)z0Abstract - Should provide status information. Nr)r flavorrrrstatusXzJailThread.statuscsd|_tt|dS)z&Sets active flag and starts thread. TN)rrr startr&r!rrr.^szJailThread.startcCs d|_dS)zASets `active` property to False, to flag run method to return. FN)rr&rrrstopds zJailThread.stopcCr*)zCAbstract - Called when thread starts, thread stops when returns. Nrr&rrrrir-zJailThread.runcs |jdurtt|dSdS)z` Safer join, that could be called also for not started (or ended) threads (used for cleanup). N)rrr joinr&r!rrr0os zJailThread.joinr )r))__name__ __module__ __qualname____doc__rr version_infor%_JailThread__bootstraprr,r.r/rr0 __classcell__rrr!rr #s    r r#isAlive) __author__ __copyright__ __license__r threadingrabcrutilsrhelpersrr r r5r6r'hasattris_aliver8rrrrs    V