
    g                        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e      Z G d	 d
e      Z G d dej                        ZddZ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_CHECKING)
ModuleType)Trickc                      e Zd Zy)UnsupportedLibcErrorN)__name__
__module____qualname__     L/var/www/openai/venv/lib/python3.12/site-packages/watchdog/utils/__init__.pyr   r      s    r   r   c                      e Zd ZdZy)WatchdogShutdownErrorz=Semantic exception used to signal an external shutdown event.N)r	   r
   r   __doc__r   r   r   r   r      s    Gr   r   c                  R    e Zd ZdZd
dZedd       ZddZd
dZd
dZ	d
dZ
d
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__&   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_running2   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_stop6       r   c                X    | j                   j                          | j                          y)zSignals the thread to stop.N)r   setr&   r   s    r   stopzBaseThread.stop=   s     !r   c                     y)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   s    r   on_thread_startzBaseThread.on_thread_startB   r'   r   c                b    | j                          t        j                  j                  |        y r    )r,   r   r   startr   s    r   r.   zBaseThread.startJ   s"    t$r   N)returnNone)r/   zthreading.Event)r/   bool)r	   r
   r   r   r   propertyr!   r$   r&   r*   r,   r.   r   r   r   r   r   #   s7    ;0 # #0
%r   r   c                    	 t        |        t        j                  |    S # t        $ r}d|  }t        |      |d}~ww xY w)z;Imports a module given its name and returns a handle to it.zNo module named N)
__import__ImportErrorsysmodules)module_nameeerrors      r   load_moduler;   O   sK    (; ;;{##  (";-0% a'(s     	?:?c                    | j                  d      }t        |      dk  rd|  d}t        |      |d   }dj                  |dd       }t	        |      }t        ||      rt        ||      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joinr;   r   getattrAttributeError)dotted_pathdotted_path_splitr:   
klass_namer8   modules         r   
load_classrJ   Y   s    * $))#.
"%k]2]^"2&J((,Sb12K%Fvz"vz**k]"A*NE

r   )r8   strr/   r   )rF   rK   r/   ztype[Trick])r   
__future__r   r6   r   typingr   typesr   watchdog.tricksr   	Exceptionr   r   r   r   r;   rJ   r   r   r   <module>rQ      sX    # 
    %	9 	HI H)%!! )%X$! r   