o
    *Î®c‚  ã                   @   sZ   d Z ddlZddlZG dd„ deƒZG dd„ deƒZG dd„ dejƒZd	d
„ Z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:

é    Nc                   @   s   e Zd ZdS )ÚUnsupportedLibcN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú>/tmp/pip-target-vg8gfxp4/lib/python/watchdog/utils/__init__.pyr   %   s    r   c                   @   s   e Zd ZdZdS )ÚWatchdogShutdownzG
    Semantic exception used to signal an external shutdown event.
    N)r   r   r   Ú__doc__r   r   r   r   r   )   s    r   c                   @   sL   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dS )Ú
BaseThreadz3 Convenience class for creating stoppable threads. c                 C   sR   t j | ¡ t| dƒrd| _n|  d¡ t  ¡ | _t| jdƒs'| jj| j_	d S d S )NÚdaemonTÚis_set)
Ú	threadingÚThreadÚ__init__Úhasattrr   Ú	setDaemonÚEventÚ_stopped_eventÚisSetr   ©Úselfr   r   r   r   3   s   


ÿzBaseThread.__init__c                 C   s   | j S ©N)r   r   r   r   r   Ústopped_event>   s   zBaseThread.stopped_eventc                 C   s   | j  ¡  S )z6Determines whether the thread should continue running.)r   r   r   r   r   r   Úshould_keep_runningB   s   zBaseThread.should_keep_runningc                 C   ó   dS )z³Override 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_stopF   s   zBaseThread.on_thread_stopc                 C   s   | j  ¡  |  ¡  dS )zSignals the thread to stop.N)r   Úsetr   r   r   r   r   ÚstopN   s   
zBaseThread.stopc                 C   r   )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   r   r   r   Úon_thread_startS   s   zBaseThread.on_thread_startc                 C   s   |   ¡  tj | ¡ d S r   )r   r   r   Ústartr   r   r   r   r   \   s   zBaseThread.startN)r   r   r   r	   r   Úpropertyr   r   r   r   r   r   r   r   r   r   r
   0   s    
	r
   c                 C   s2   zt | ƒ W n ty   td|  ƒ‚w tj|  S )z;Imports a module given its name and returns a handle to it.zNo module named %s)Ú
__import__ÚImportErrorÚsysÚmodules)Úmodule_namer   r   r   Úload_modulea   s   ÿ
r&   c                 C   sl   |   d¡}t|ƒdkr0|d }d |dd… ¡}t|ƒ}t||ƒr(t||ƒ}|S td||f ƒ‚t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.
    Ú.é   éÿÿÿÿNz*Module %s does not have class attribute %sz@Dotted module path %s must contain a module name and a classname)ÚsplitÚlenÚjoinr&   r   ÚgetattrÚAttributeErrorÚ
ValueError)Údotted_pathÚdotted_path_splitÚ
klass_namer%   ÚmoduleÚklassr   r   r   Ú
load_classj   s   


ÿÿr5   )
r	   r#   r   Ú	Exceptionr   r   r   r
   r&   r5   r   r   r   r   Ú<module>   s   1	