ó
éÐLac           @   se   d  d l  m Z d  d l m Z d  d l Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ e ƒ  Z d S(   iÿÿÿÿ(   t   dirname(   t   ObserverNt   CacheManagerc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s|  
        A naive cache implementation for listdir and digest_file

        The listdir_cache is just a giant list of PkgFile objects, and
        for simplicity it is invalidated anytime a modification occurs
        within the directory it represents. If we were smarter about
        the way that the listdir data structure were created/stored,
        then we could do more granular invalidation. In practice, this
        is good enough for now.

        The digest_cache exists on a per-file basis, because computing
        hashes on large files can get expensive, and it's very easy to
        invalidate specific filenames.
    c         C   sh   i  |  _  i  |  _ t ƒ  |  _ |  j j ƒ  t ƒ  |  _ t j ƒ  |  _	 t j ƒ  |  _
 t j ƒ  |  _ d  S(   N(   t   listdir_cachet   digest_cacheR   t   observert   startt   sett   watchedt	   threadingt   Lockt
   watch_lockt   digest_lockt   listdir_lock(   t   self(    (    sK   /var/www/html/packages/venv/lib/python3.8/site-packages/pypiserver/cache.pyt   __init__   s    		c      
   C   s†   |  j  w y |  j | SWn` t k
 r{ |  j $ | |  j k rR |  j | ƒ n  Wd  QXt | | ƒ ƒ } | |  j | <| SXWd  QXd  S(   N(   R   R   t   KeyErrorR   R   t   _watcht   list(   R   t   roott   impl_fnt   v(    (    sK   /var/www/html/packages/venv/lib/python3.8/site-packages/pypiserver/cache.pyt   listdir0   s    

c      
   C   sÆ   |  j  · y |  j | } Wn& t k
 rC |  j j | i  ƒ } n Xy | | SWnL t k
 rž t | ƒ } |  j $ | |  j k r• |  j | ƒ n  Wd  QXn X| | | ƒ } | | | <| SWd  QXd  S(   N(   R   R   R   t
   setdefaultR    R   R   R   (   R   t   fpatht	   hash_algoR   t   cacheR   R   (    (    sK   /var/www/html/packages/venv/lib/python3.8/site-packages/pypiserver/cache.pyt   digest_file>   s    


c         C   s6   |  j  j | ƒ |  j j t |  | ƒ | d t ƒd  S(   Nt	   recursive(   R   t   addR   t   schedulet   _EventHandlert   True(   R   R   (    (    sK   /var/www/html/packages/venv/lib/python3.8/site-packages/pypiserver/cache.pyR   T   s    (   t   __name__t
   __module__t   __doc__R   R   R   R   (    (    (    sK   /var/www/html/packages/venv/lib/python3.8/site-packages/pypiserver/cache.pyR      s
   			R   c           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   | |  _  | |  _ d  S(   N(   R   R   (   R   R   R   (    (    sK   /var/www/html/packages/venv/lib/python3.8/site-packages/pypiserver/cache.pyR   Z   s    	c      
   C   sÙ   |  j  } | j r d S| j  | j j |  j d ƒ Wd QXg  } | j d k rt | j | j	 ƒ | j | j
 ƒ n | j | j	 ƒ | j F x> | j j ƒ  D]- \ } } x | D] } | j | d ƒ q± Wqž WWd QXd S(   s   Called by watchdog observerNt   moved(   R   t   is_directoryR   R   t   popR   t   Nonet
   event_typet   appendt   src_patht	   dest_pathR   R   t   items(   R   t   eventR   t   pathst   _t   subcachet   path(    (    sK   /var/www/html/packages/venv/lib/python3.8/site-packages/pypiserver/cache.pyt   dispatch^   s    		

(   R!   R"   R   R2   (    (    (    sK   /var/www/html/packages/venv/lib/python3.8/site-packages/pypiserver/cache.pyR   X   s   	(	   t   os.pathR    t   watchdog.observersR   R	   t   objectR   R   t   cache_manager(    (    (    sK   /var/www/html/packages/venv/lib/python3.8/site-packages/pypiserver/cache.pyt   <module>   s
   M 