
*VNc           @   s   d  d l  Z  d  d l Z d Z e  j j d  r9 d Z n  d Z d Z d Z d Z	 d Z
 d	 Z d
 Z d Z d Z d Z d Z d Z d Z d Z d Z d	 Z d
 Z d   Z d d  Z d e f d     YZ d d d     YZ d   Z e d k r e   n  d S(   iNi    t   MonitorDebugi   i   i   i   i   i   i   i   i	   c           C   s
   t  j   S(   N(   t   _gamint   Errno(    (    (    s%   /usr/lib/pymodules/python2.7/gamin.pyt
   GaminErrno"   s    c         C   s   |  d  k r t j   }  n  |  t k r0 d } n |  t k rE d } no |  t k rZ d } nZ |  t k ro d } nE |  t k r d } n0 |  t k r d } n |  t	 k r d } n d } | S(	   Ns   bad argument errors   filename errors   connection errors   authentication errors   memory allocation errors   unimplemented part errors   interrupted system callt    (
   t   NoneR   R   t   GAM_ARGt   GAM_FILEt   GAM_CONNECTt   GAM_AUTHt   GAM_MEMt   GAM_UNIMPLEMt   GAM_INTR(   t   errt   msg(    (    s%   /usr/lib/pymodules/python2.7/gamin.pyt   GaminErrmsg%   s$    							t   GaminExceptionc           B   s   e  Z d    Z d   Z RS(   c         C   s&   t  j |   | |  _ t   |  _ d  S(   N(   t	   Exceptiont   __init__t   valueR   t   errno(   t   selfR   (    (    s%   /usr/lib/pymodules/python2.7/gamin.pyR   ;   s    	c         C   s=   t  |  j  } | d k r0 t |  j  d | St |  j  S(   NR   s   : (   R   R   t   reprR   (   R   t   str(    (    s%   /usr/lib/pymodules/python2.7/gamin.pyt   __str__@   s    (   t   __name__t
   __module__R   R   (    (    (    s%   /usr/lib/pymodules/python2.7/gamin.pyR   :   s   	t   WatchMonitorc           B   s   e  Z d  Z d d d     YZ d   Z d   Z d   Z d d  Z d   Z	 d d  Z
 d d	  Z d
   Z d   Z d   Z d   Z d   Z d   Z RS(   s|  This is a wrapper for a FAM connection. It uses a single connection
       to the gamin server, over a socket. Use get_fd() to get the file
       descriptor which allows to plug it in an usual event loop. The
       watch_directory(), watch_file() and stop_watch() are direct mapping
       to the FAM API. The event raised are also a direct mapping of the
       FAM API events.t   WatchObjectc           B   s&   e  Z d d   Z d   Z d   Z RS(   c         C   s  | |  _  | |  _ | |  _ | |  _ | |  _ | d k rs t j |  j | |   } | d k  r t d |   q n | d k r t j |  j | |   } | d k  r t d |   q nF | d k r t j	 |  j | |   } | d k  r t d |   q n  | |  _
 d  S(   Ni   i    s   Failed to monitor directory %ss   Failed to monitor file %sis   Failed to debug %s(   t   monitort   callbackt   datat   patht   _WatchObject__mon_noR   t   MonitorDirectoryR   t   MonitorFileR    t   _WatchObject__req_no(   R   R   t   mon_noR    t   dirR   R   t   ret(    (    s%   /usr/lib/pymodules/python2.7/gamin.pyR   O   s*    					c         C   s   y< |  j  d  k r+ |  j | | |  j   n |  j | |  Wn d d  l } | j   n X| t k r y |  j j j |   Wq d GHq Xn  d  S(   Nis%   gamin failed to remove from cancelled(	   R   R   R   t	   tracebackt	   print_exct   GAMAcknowledgeR   t	   cancelledt   remove(   R   R    t   eventR(   (    (    s%   /usr/lib/pymodules/python2.7/gamin.pyt   _internal_callbackf   s    c         C   sd   t  j |  j |  j  } | d k  r: t d |  j   n  y |  j j j |   Wn d GHn Xd  S(   Ni    s   Failed to stop monitor on %ss)   gamin cancel() failed to add to cancelled(	   R   t   MonitorCancelR!   R$   R   R    R   R+   t   append(   R   R'   (    (    s%   /usr/lib/pymodules/python2.7/gamin.pyt   cancely   s    N(   R   R   R   R   R.   R1   (    (    (    s%   /usr/lib/pymodules/python2.7/gamin.pyR   N   s   	c         C   s   t  j   |  _ |  j d k  r- t d   n  i  |  _ t  j |  j  |  _ |  j d k  ry t  j |  j  t d   n  g  |  _ d  S(   Ni    s   Failed to connect to gam_servers   Failed to get file descriptor(	   R   t   MonitorConnectt   _WatchMonitor__noR   t   objectst   GetFdt   _WatchMonitor__fdt   MonitorCloseR+   (   R   (    (    s%   /usr/lib/pymodules/python2.7/gamin.pyR      s    	c         C   s   |  j    d  S(   N(   t
   disconnect(   R   (    (    s%   /usr/lib/pymodules/python2.7/gamin.pyt   __del__   s    c           C   s   t  d   d  S(   Ns   Already disconnected(   R   (    (    (    s%   /usr/lib/pymodules/python2.7/gamin.pyt   __raise_disconnected   s    c         C   s^   t  d k r d  S|  j d k  r, |  j   n  |  j |  |  j | d | |  } | |  j d <| S(   Ni    it   debug(   t   has_debug_apiR3   t!   _WatchMonitor__raise_disconnectedR   R4   (   R   R   R   R   t   obj(    (    s%   /usr/lib/pymodules/python2.7/gamin.pyt   _debug_object   s    !c         C   s/   |  j  d k r" t j |  j   n  d |  _  d  S(   Ni    i(   R3   R   R7   (   R   (    (    s%   /usr/lib/pymodules/python2.7/gamin.pyR8      s    c         C   s   |  j  d k  r |  j   n  t j j |  } |  j |  |  j  | d | |  } |  j j |  rx |  j | j |  n | g |  j | <| S(   Ni    i   (	   R3   R=   t   osR    t   abspathR   R4   t   has_keyR0   (   R   t	   directoryR   R   R>   (    (    s%   /usr/lib/pymodules/python2.7/gamin.pyt   watch_directory   s    !c         C   s   |  j  d k  r |  j   n  t j j |  } |  j |  |  j  | d | |  } |  j j |  rx |  j | j |  n | g |  j | <| S(   Ni    (	   R3   R=   R@   R    RA   R   R4   RB   R0   (   R   t   fileR   R   R>   (    (    s%   /usr/lib/pymodules/python2.7/gamin.pyt
   watch_file   s    !c         C   s)   |  j  d k  r d  St j |  j   } | S(   Ni    (   R3   R   t   MonitorNoExists(   R   R'   (    (    s%   /usr/lib/pymodules/python2.7/gamin.pyt	   no_exists   s    c         C   s|   |  j  d k  r d  St j j |  } y |  j | } Wn t d |   n Xx | D] } | j   qW Wg  |  j | <d  S(   Ni    s   Resource %s is not monitored(   R3   R@   R    RA   R4   R   R1   (   R   R    t   listR>   (    (    s%   /usr/lib/pymodules/python2.7/gamin.pyt
   stop_watch   s    c         C   s#   |  j  d k  r |  j   n  |  j S(   Ni    (   R3   R=   R6   (   R   (    (    s%   /usr/lib/pymodules/python2.7/gamin.pyt   get_fd   s    c         C   sM   |  j  d k  r |  j   n  t j |  j   } | d k  rI t d   n  | S(   Ni    s   Failed to check pending events(   R3   R=   R   t   EventPendingR   (   R   R'   (    (    s%   /usr/lib/pymodules/python2.7/gamin.pyt   event_pending   s    c         C   sM   |  j  d k  r |  j   n  t j |  j   } | d k  rI t d   n  | S(   Ni    s   Failed to process one event(   R3   R=   R   t   ProcessOneEventR   (   R   R'   (    (    s%   /usr/lib/pymodules/python2.7/gamin.pyt   handle_one_event   s    c         C   sM   |  j  d k  r |  j   n  t j |  j   } | d k  rI t d   n  | S(   Ni    s   Failed to process events(   R3   R=   R   t   ProcessEventsR   (   R   R'   (    (    s%   /usr/lib/pymodules/python2.7/gamin.pyt   handle_events   s    (    N(   R   R   t   __doc__R   R   R9   R=   R   R?   R8   RD   RF   RH   RJ   RK   RM   RO   RQ   (    (    (    s%   /usr/lib/pymodules/python2.7/gamin.pyR   F   s   5									c          C   s   d   }  t    } d GH| j d |   d d  l } | j d  d G| j   GH| j   } d G| GH| d k r | j   } d	 | GH| j   } d
 | GHn  d GH| j d  d GH~ d  S(   Nc         S   s   d |  | f GHd  S(   Ns   Got callback: %s, %s(    (   R    R-   (    (    s%   /usr/lib/pymodules/python2.7/gamin.pyR      s    s   watching current directoryt   .ii   s   fd: s	   pending: i    s   processed %d events   processed %d remaining eventss   stop watching current directoryt   disconnecting(	   R   RD   t   timet   sleepRK   RM   RO   RQ   RJ   (   R   t   monRU   R'   (    (    s%   /usr/lib/pymodules/python2.7/gamin.pyt   run_unit_tests   s$    				t   __main__(    (   R   t   os.pathR@   R<   t   __dict__RB   t
   GAMChangedt
   GAMDeletedt   GAMStartExecutingt   GAMStopExecutingt
   GAMCreatedt   GAMMovedR*   t	   GAMExistst   GAMEndExistt   GAM_OKR   R   R   R	   R
   R   R   R   R   R   R   R   R   RX   R   (    (    (    s%   /usr/lib/pymodules/python2.7/gamin.pyt   <module>   s8   			