ó
pÁìVc           @   s‰  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z d  d l m Z d  d l	 m
 Z
 m Z d  d l m Z d  d l m Z d  d l m Z d  d l m Z d  d	 l m Z d a d d
 „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d a  d „  Z! d „  Z" d „  Z# d „  Z$ d „  Z% d d „ Z& d d „ Z' d „  Z( e) d d „ Z* e d „  ƒ Z+ d S(   iÿÿÿÿN(   t	   get_cache(   t   ContentFile(   t
   force_textt   smart_bytes(   t   SimpleLazyObject(   t   import_module(   t   settings(   t   default_storage(   t   get_mod_funcc         C   s-   t  j t |  ƒ ƒ j ƒ  } | r) | |  S| S(   N(   t   hashlibt   md5R   t	   hexdigest(   t	   plaintextt   lengtht   digest(    (    sf   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/cache.pyt   get_hexdigest   s    c         C   s   d t  |  ƒ S(   Ns   django_compressor.%s(   R   (   t   key(    (    sf   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/cache.pyt   simple_cachekey   s    c         C   s   d t  j ƒ  t |  ƒ f S(   Ns   django_compressor.%s.%s(   t   sockett   gethostnameR   (   R   (    (    sf   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/cache.pyt   socket_cachekey   s    c          O   s   t  d  k rr y. t t j ƒ \ } } t t | ƒ | ƒ a  Wqr t t f k
 rn } t d t j | f ƒ ‚ qr Xn  t  |  | Ž  S(   Ns)   Couldn't import cache key function %s: %s(	   t   _cachekey_funct   NoneR   R   t   COMPRESS_CACHE_KEY_FUNCTIONt   getattrR   t   AttributeErrort   ImportError(   t   argst   kwargst   mod_namet	   func_namet   e(    (    sf   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/cache.pyt   get_cachekey#   s    c         C   s   t  d t |  ƒ ƒ S(   Ns   mtime.%s(   R    R   (   t   filename(    (    sf   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/cache.pyt   get_mtime_cachekey0   s    c         C   s
   t  |  ƒ S(   N(   R   (   t   render_template_string(    (    sf   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/cache.pyt   get_offline_hexdigest4   s    c         C   s   t  d t |  ƒ ƒ S(   Ns
   offline.%s(   R    R$   (   t   source(    (    sf   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/cache.pyt   get_offline_cachekey8   s    c          C   s(   t  j j d ƒ }  t j j |  t  j ƒ S(   Nt   /(   R   t   COMPRESS_OUTPUT_DIRt   stript   ost   patht   joint   COMPRESS_OFFLINE_MANIFEST(   t
   output_dir(    (    sf   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/cache.pyt   get_offline_manifest_filename<   s    c          C   sj   t  d  k rf t ƒ  }  t j |  ƒ r] t j |  ƒ % } t j | j ƒ  j	 d ƒ ƒ a  Wd  QXqf i  a  n  t  S(   Nt   utf8(
   t   _offline_manifestR   R/   R   t   existst   opent   jsont   loadst   readt   decode(   R!   t   fp(    (    sf   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/cache.pyt   get_offline_manifestD   s    	'	c           C   s
   d  a d  S(   N(   R   R1   (    (    (    sf   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/cache.pyt   flush_offline_manifestP   s    c         C   sH   t  ƒ  } t j |  d d ƒj d ƒ } t j | t | ƒ ƒ t ƒ  d  S(   Nt   indenti   R0   (   R/   R4   t   dumpst   encodeR   t   saveR   R:   (   t   manifestR!   t   content(    (    sf   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/cache.pyt   write_offline_manifestU   s    	c         C   s   t  d |  j | | f ƒ S(   Ns   templatetag.%s.%s.%s(   R    t   cachekey(   t
   compressort   modet   kind(    (    sf   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/cache.pyt   get_templatetag_cachekey\   s    c         C   so   t  j r_ t |  ƒ } t j | ƒ } | d  k r[ t j j |  ƒ } t j	 | | t  j ƒ n  | St j j |  ƒ S(   N(
   R   t   COMPRESS_MTIME_DELAYR"   t   cachet   getR   R*   R+   t   getmtimet   set(   R!   R   t   mtime(    (    sf   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/cache.pyt	   get_mtimea   s    	i   c         C   sP   y. t  j j |  ƒ }  t t t |  ƒ ƒ ƒ } Wn t k
 rB d  SXt | | ƒ S(   N(	   R*   R+   t   realpatht   strt   intRM   t   OSErrorR   R   (   R!   R   RL   (    (    sf   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/cache.pyt   get_hashed_mtimel   s    c         C   sZ   y t  j j |  ƒ }  Wn t k
 r* d  SXt |  d ƒ  } t | j ƒ  | ƒ SWd  QXd  S(   Nt   rb(   R*   R+   RN   RQ   R   R3   R   R6   (   R!   R   t   file(    (    sf   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/cache.pyt   get_hashed_contentu   s    c         C   sk   t  j |  ƒ } | d  k r d  S| \ } } } t j ƒ  | k rg | rg t |  | d t d t j ƒd  S| S(   Nt	   refreshedt   timeout(   RH   RI   R   t   timet	   cache_sett   TrueR   t   COMPRESS_MINT_DELAY(   R   t
   packed_valt   valt   refresh_timeRV   (    (    sf   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/cache.pyt	   cache_get€   s    
c         C   sW   | d  k r t j } n  | t j ƒ  } | t j } | | | f } t j |  | | ƒ S(   N(   R   R   t   COMPRESS_REBUILD_TIMEOUTRX   R[   RH   RK   (   R   R]   RV   RW   R^   t   real_timeoutR\   (    (    sf   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/cache.pyRY   Ž   s    c           C   s   t  t j ƒ S(   N(   R    R   t   COMPRESS_CACHE_BACKEND(    (    (    sf   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/cache.pyt   <lambda>—   s    (,   R4   R	   R*   R   RX   t   django.core.cacheR    t   django.core.files.baseR   t   django.utils.encodingR   R   t   django.utils.functionalR   t   django.utils.importlibR   t   compressor.confR   t   compressor.storageR   t   compressor.utilsR   R   R   R   R   R   R    R"   R$   R&   R/   R1   R9   R:   RA   RF   RM   RR   RU   R_   t   FalseRY   RH   (    (    (    sf   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/cache.pyt   <module>   s@   															