
    "d                        d Z ddlmZ ddlZddlZddlmZ  G d de      Z G d de      Z	 G d	 d
ej                        Zd Zd Zesej                  dk\  rddlmZ y G d d      Zy)u  
:module: watchdog.utils
:synopsis: Utility classes and functions.
:author: yesudeep@google.com (Yesudeep Mangalapilly)
:author: contact@tiger-222.fr (Mickaël Schoentgen)

Classes
-------
.. autoclass:: BaseThread
   :members:
   :show-inheritance:
   :inherited-members:

    )annotationsN)TYPE_CHECKINGc                      e Zd Zy)UnsupportedLibcN__name__
__module____qualname__     9/usr/lib/python3/dist-packages/watchdog/utils/__init__.pyr   r   &   s    r   r   c                      e Zd ZdZy)WatchdogShutdownzG
    Semantic exception used to signal an external shutdown event.
    N)r   r	   r
   __doc__r   r   r   r   r   *   s     	r   r   c                  D    e Zd ZdZd Zed        Zd Zd Zd Z	d Z
d Zy	)

BaseThreadz1Convenience class for creating stoppable threads.c                    t         j                  j                  |        t        | d      rd| _        n| j                  d       t        j                         | _        y )NdaemonT)	threadingThread__init__hasattrr   	setDaemonEvent_stopped_eventselfs    r   r   zBaseThread.__init__5   sB    !!$'4"DKNN4 'oo/r   c                    | j                   S N)r   r   s    r   stopped_eventzBaseThread.stopped_event=   s    """r   c                8    | j                   j                          S )z6Determines whether the thread should continue running.)r   is_setr   s    r   should_keep_runningzBaseThread.should_keep_runningA   s    &&--///r   c                     y)zOverride this method instead of :meth:`stop()`.
        :meth:`stop()` calls this method.

        This method is called immediately after the thread is signaled to stop.
        Nr   r   s    r   on_thread_stopzBaseThread.on_thread_stopE   s     	r   c                X    | j                   j                          | j                          y)zSignals the thread to stop.N)r   setr%   r   s    r   stopzBaseThread.stopM   s     !r   c                     y)u   Override this method instead of :meth:`start()`. :meth:`start()`
        calls this method.

        This method is called right before this thread is started and this
        object’s run() method is invoked.
        Nr   r   s    r   on_thread_startzBaseThread.on_thread_startR   s     	r   c                b    | j                          t        j                  j                  |        y r   )r*   r   r   startr   s    r   r,   zBaseThread.start[   s"    t$r   N)r   r	   r
   r   r   propertyr    r#   r%   r(   r*   r,   r   r   r   r   r   2   s7    ;0 # #0
%r   r   c                v    	 t        |        t        j                  |    S # t        $ r t        d|        w xY w)z;Imports a module given its name and returns a handle to it.zNo module named )
__import__ImportErrorsysmodules)module_names    r   load_moduler4   `   sD    <; ;;{##  <,[M:;;<s     8c                    | j                  d      }t        |      dk  rt        d|  d      |d   }dj                  |dd       }t	        |      }t        ||      rt        ||      S t        d| d|       )	ak  Loads and returns a class definition provided a dotted path
    specification the last part of the dotted path is the class name
    and there is at least one module name preceding the class name.

    Notes:
    You will need to ensure that the module you are trying to load
    exists in the Python path.

    Examples:
    - module.name.ClassName    # Provided module.name is in the Python path.
    - module.ClassName         # Provided module is in the Python path.

    What won't work:
    - ClassName
    - modle.name.ClassName     # Typo in module name.
    - module.name.ClasNam      # Typo in classname.
    .   zDotted module path z+ must contain a module name and a classnameNzModule z does not have class attribute )splitlen
ValueErrorjoinr4   r   getattrAttributeError)dotted_pathdotted_path_split
klass_namer3   modules        r   
load_classrC   i   s    $ $))#.
"!+.YZ
 	
 #2&J((,Sb12K%Fvz"vz** k]"A*N
 	
r   )      )Protocolc                      e Zd Zy)rF   Nr   r   r   r   rF   rF      s    r   rF   )r   
__future__r   r1   r   typingr   	Exceptionr   r   r   r   r4   rC   version_inforF   r   r   r   <module>rL      sm   " # 
   	i 		y 	+%!! +%\$"
J C$$.+
 r   