ó
pÁìVc           @  sê   d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l m Z d  d l Z d  d l m Z m	 Z	 d  d l
 m Z m Z d  d l m Z d e f d „  ƒ  YZ e d	 „  ƒ Z d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ e ƒ  Z d S(   iÿÿÿÿ(   t   unicode_literalsN(   t   datetime(   t   FileSystemStoraget   get_storage_class(   t
   LazyObjectt   SimpleLazyObject(   t   settingst   CompressorFileStoragec           B  sJ   e  Z d  Z d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   u³   
    Standard file system storage for files handled by django-compressor.

    The defaults for ``location`` and ``base_url`` are ``COMPRESS_ROOT`` and
    ``COMPRESS_URL``.

    c         O  sS   | d  k r t j } n  | d  k r0 t j } n  t t |  ƒ j | | | | Ž d  S(   N(   t   NoneR   t   COMPRESS_ROOTt   COMPRESS_URLt   superR   t   __init__(   t   selft   locationt   base_urlt   argst   kwargs(    (    sh   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/storage.pyR      s    c         C  s"   t  j t j j |  j | ƒ ƒ ƒ S(   N(   R   t   fromtimestampt   ost   patht   getatime(   R   t   name(    (    sh   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/storage.pyt   accessed_time   s    c         C  s"   t  j t j j |  j | ƒ ƒ ƒ S(   N(   R   R   R   R   t   getctime(   R   R   (    (    sh   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/storage.pyt   created_time!   s    c         C  s"   t  j t j j |  j | ƒ ƒ ƒ S(   N(   R   R   R   R   t   getmtime(   R   R   (    (    sh   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/storage.pyt   modified_time$   s    c         C  s#   |  j  | ƒ r |  j | ƒ n  | S(   u6   
        Deletes the given file if it exists.
        (   t   existst   delete(   R   R   (    (    sh   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/storage.pyt   get_available_name'   s    c         C  sL   y t  t |  ƒ j | ƒ Wn+ t k
 rG } | j t j k rH ‚  qH n Xd S(   uƒ   
        Handle deletion race condition present in Django prior to 1.4
        https://code.djangoproject.com/ticket/16108
        N(   R   R   R   t   OSErrort   errnot   ENOENT(   R   R   t   e(    (    sh   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/storage.pyR   /   s
    N(
   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R   (    (    (    sh   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/storage.pyR      s   				c           C  s   t  d ƒ ƒ  S(   Nu(   compressor.storage.CompressorFileStorage(   R   (    (    (    sh   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/storage.pyt   <lambda><   s    t   GzipCompressorFileStoragec           B  s   e  Z d  Z d „  Z RS(   us   
    The standard compressor file system storage that gzips storage files
    additionally to the usual files.
    c         C  sÏ   t  t |  ƒ j | | ƒ } |  j | ƒ } d | } t | d ƒ } t | d ƒ } z) t j d | ƒ } | j | j ƒ  ƒ Wd  | j	 ƒ  | j	 ƒ  t
 j
 ƒ  } t j | | | f ƒ t j | | | f ƒ X| S(   Nu   %s.gzu   rbu   wbt   fileobj(   R   R'   t   saveR   t   opent   gzipt   GzipFilet   writet   readt   closet   timeR   t   utime(   R   t   filenamet   contentt	   orig_patht   compressed_patht   f_int   f_outt   stamp(    (    sh   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/storage.pyR)   D   s    


(   R#   R$   R%   R)   (    (    (    sh   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/storage.pyR'   ?   s   t   DefaultStoragec           B  s   e  Z d  „  Z RS(   c         C  s   t  t j ƒ ƒ  |  _ d  S(   N(   R   R   t   COMPRESS_STORAGEt   _wrapped(   R   (    (    sh   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/storage.pyt   _setup]   s    (   R#   R$   R<   (    (    (    sh   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/storage.pyR9   \   s   (   t
   __future__R    R    R+   R   R   R0   t   django.core.files.storageR   R   t   django.utils.functionalR   R   t   compressor.confR   R   t   compressor_file_storageR'   R9   t   default_storage(    (    (    sh   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/storage.pyt   <module>   s   -