
    "d                     n    d Z ddlmZ ddlZddlZddlZ ej                  e      ZddZ	 G d de
      Zy)zThe filesystem watcher api.    )absolute_importNc                       fd}|S )zRetry a function or method n times before raising an exception.

    :param n: Number of times to retry
    :param interval: Time to sleep before attempts
    c                 H     t        j                          fd       }|S )Nc                  |    d}	 	  | i |S # t         $ r# |dz  }|k  r t        j                         Y nw xY w9)Nr      )	Exceptiontimesleep)argskwargsattemptsfnintervalns      5/usr/lib/python3/dist-packages/qtsass/watchers/api.pyattemptz(retry.<locals>.decorate.<locals>.attempt   sS    H)t.v..  )MHH}JJx(	) s    )::)	functoolswraps)r   r   r   r   s   ` r   decoratezretry.<locals>.decorate   s%    				) 
		)      )r   r   r   s   `` r   retryr      s     Or   c                   j    e Zd ZdZddZd Zd Zd Zd Z e	d      d	        Z
d
 Zd Zd Zd Zd Zy)Watchera  Watcher base class.

    Watchers monitor a file or directory and call the on_change method when a
    change occurs. The on_change method should trigger the compiler function
    passed in during construction and dispatch the result to all connected
    callbacks.

    Watcher implementations must inherit from this base class. Subclasses
    should perform any setup required in the setup method, rather than
    overriding __init__.
    Nc                     || _         || _        |xs d| _        |xs i | _        t	               | _        t        | _        | j                          y)z3Store initialization values and call Watcher.setup.r   N)
_watch_dir	_compiler_args_kwargsset
_callbacks_logsetup)self	watch_dircompilerr   r   s        r   __init__zWatcher.__init__?   s?    #!ZR
|%	

r   c                     t         S )zPerform any setup required here.

        Rather than implement __init__, subclasses can perform any setup in
        this method.
        NotImplementedr$   s    r   r#   zWatcher.setupI   s
     r   c                     t         S )zStart this Watcher.r)   r+   s    r   startzWatcher.startQ       r   c                     t         S )zStop this Watcher.r)   r+   s    r   stopzWatcher.stopU   r.   r   c                     t         S )z Wait for this Watcher to finish.r)   r+   s    r   joinzWatcher.joinY   r.   r      c                     | j                   j                  d| j                  | j                  | j                          | j                  | j                  i | j                  S )zCall the Watcher's compiler.zCompiling sass...%s(*%s, **%s))r"   debugr   r   r   r+   s    r   compilezWatcher.compile]   sL     			,NNJJLL		
 t~~tzz:T\\::r   c                     | j                   j                  d       	 | j                         }| j                  |       y# t        $ r | j                   j	                  d       Y yw xY w)z>Compile and dispatch the resulting css to connected callbacks.zCompiling and dispatching....zFailed to compile...N)r"   r5   r6   r   	exceptiondispatch)r$   csss     r   compile_and_dispatchzWatcher.compile_and_dispatchh   sX    		78	,,.C
 	c	  	II 67	s   ? $A&%A&c                 l    | j                   j                  d       | j                  D ]
  } ||        y)z$Dispatch css to connected callbacks.zDispatching callbacks...N)r"   r5   r!   )r$   r:   callbacks      r   r9   zWatcher.dispatcht   s-    		23 	HSM	r   c                 Z    | j                   j                  d       | j                          y)aw  Call when a change is detected.

        Subclasses must call this method when they detect a change. Subclasses
        may also override this method in order to manually compile and dispatch
        callbacks. For example, a Qt implementation may use signals and slots
        to ensure that compiling and executing callbacks happens in the main
        GUI thread.
        zChange detected...N)r"   r5   r;   r+   s    r   	on_changezWatcher.on_changez   s!     			,-!!#r   c                 r    | j                   j                  d|       | j                  j                  |       y)zConnect a callback to this Watcher.

        All callbacks are called when a change is detected. Callbacks are
        passed the compiled css.
        zConnecting callback: %sN)r"   r5   r!   addr$   r   s     r   connectzWatcher.connect   s)     			126Br   c                 r    | j                   j                  d|       | j                  j                  |       y)z(Disconnect a callback from this Watcher.zDisconnecting callback: %sN)r"   r5   r!   discardrB   s     r   
disconnectzWatcher.disconnect   s'    		4b9#r   )NN)__name__
__module____qualname____doc__r'   r#   r-   r0   r2   r   r6   r;   r9   r?   rC   rF   r   r   r   r   r   2   sQ    
 1X; ;

$ $r   r   )g?)rJ   
__future__r   r   loggingr	   	getLoggerrG   r"   r   objectr   r   r   r   <module>rO      sA    " '    w"4`$f `$r   