o
    h                     @  s   d Z ddlmZ ddlZddlZddlmZ er$ddlmZ ddl	m
Z
 G dd deZG d	d
 d
eZG dd dejZdddZdddZdS )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_CHECKING)
ModuleType)Trickc                   @  s   e Zd ZdS )UnsupportedLibcErrorN)__name__
__module____qualname__ r
   r
   K/var/www/vscode/kcb/lib/python3.10/site-packages/watchdog/utils/__init__.pyr      s    r   c                   @  s   e Zd ZdZdS )WatchdogShutdownErrorz=Semantic exception used to signal an external shutdown event.N)r   r   r	   __doc__r
   r
   r
   r   r      s    r   c                   @  sZ   e Zd ZdZdddZedddZdd
dZdddZdddZ	dddZ
dddZdS )
BaseThreadz1Convenience class for creating stoppable threads.returnNonec                 C  s6   t j|  t| drd| _n| d t  | _d S )NdaemonT)	threadingThread__init__hasattrr   	setDaemonEvent_stopped_eventselfr
   r
   r   r   &   s
   

zBaseThread.__init__threading.Eventc                 C  s   | j S N)r   r   r
   r
   r   stopped_event.   s   zBaseThread.stopped_eventboolc                 C  s   | j   S )z6Determines whether the thread should continue running.)r   is_setr   r
   r
   r   should_keep_running2   s   zBaseThread.should_keep_runningc                 C     dS )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   r
   r
   r   on_thread_stop6       zBaseThread.on_thread_stopc                 C  s   | j   |   dS )zSignals the thread to stop.N)r   setr"   r   r
   r
   r   stop=   s   
zBaseThread.stopc                 C  r!   )zOverride 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   r
   r
   r   on_thread_startB   r#   zBaseThread.on_thread_startc                 C  s   |    tj|  d S r   )r&   r   r   startr   r
   r
   r   r'   J   s   zBaseThread.startN)r   r   )r   r   )r   r   )r   r   r	   r   r   propertyr   r    r"   r%   r&   r'   r
   r
   r
   r   r   #   s    




r   module_namestrr   r   c              
   C  sD   zt |  W n ty } z
d|  }t||d}~ww tj|  S )z;Imports a module given its name and returns a handle to it.zNo module named N)
__import__ImportErrorsysmodules)r)   eerrorr
   r
   r   load_moduleO   s   


r1   dotted_pathtype[Trick]c                 C  sx   |  d}t|dkrd|  d}t||d }d|dd }t|}t||r0t||S d| d| }t|)	a  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joinr1   r   getattrAttributeError)r2   dotted_path_splitr0   
klass_namer)   moduler
   r
   r   
load_classY   s   


r@   )r)   r*   r   r   )r2   r*   r   r3   )r   
__future__r   r-   r   typingr   typesr   watchdog.tricksr   	Exceptionr   r   r   r   r1   r@   r
   r
   r
   r   <module>   s    
,
