ó
®â0_c           @   s¬  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 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 m Z d  d
 l m Z d  d l m Z d  d l m Z d  d l m Z 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 Z& d e' f d „  ƒ  YZ( d „  Z) e d e( f d „  ƒ  Yƒ Z* d d „ Z, d e f d „  ƒ  YZ- e- ƒ  Z. d S(   iÿÿÿÿN(   t   datetime(   t   settings(   t   SuspiciousFileOperation(   t   Filet   locks(   t   file_move_safe(   t   setting_changed(   t   timezone(   t   abspathut	   safe_join(   t   get_random_string(   t   deconstructible(   t   RemovedInDjango20Warning(   t   filepath_to_urit
   force_text(   t
   LazyObjectt   cached_property(   t   import_string(   t   urljoin(   t   get_valid_filenamet   Storaget   FileSystemStoraget   DefaultStoraget   default_storagec           B   s°   e  Z d  Z d d „ Z d d „ Z d „  Z d 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 RS(   sŠ   
    A base storage class, providing some default behaviors that all other
    storage systems can inherit or override, as necessary.
    t   rbc         C   s   |  j  | | ƒ S(   s<   
        Retrieves the specified file from storage.
        (   t   _open(   t   selft   namet   mode(    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyt   open"   s    c         C   s^   | d k r | j } n  t | d ƒ s9 t | | ƒ } n  |  j | d | ƒ} |  j | | ƒ S(   sÂ   
        Saves new content to the file specified by name. The content should be
        a proper File object or any python file-like object, ready to be read
        from the beginning.
        t   chunkst
   max_lengthN(   t   NoneR   t   hasattrR   t   get_available_namet   _save(   R   R   t   contentR   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyt   save(   s    c         C   s
   t  | ƒ S(   sƒ   
        Returns a filename, based on the provided filename, that's suitable for
        use in the target storage system.
        (   R   (   R   R   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyt   get_valid_name:   s    c         C   s  t  j j | ƒ \ } } t  j j | ƒ \ } } xÐ |  j | ƒ sZ | rt | ƒ | k rt  j j | d | t d ƒ | f ƒ } | d k r” q3 n  t | ƒ | } | d k r3 | |  } | sÔ t	 d | ƒ ‚ n  t  j j | d | t d ƒ | f ƒ } q3 q3 W| S(   s†   
        Returns a filename that's free on the target storage system, and
        available for new content to be written to.
        s   %s_%s%si   i    s‡   Storage can not find an available filename for "%s". Please make sure that the corresponding file field allows sufficient "max_length".N(
   t   ost   patht   splitt   splitextt   existst   lent   joinR
   R    R   (   R   R   R   t   dir_namet	   file_namet	   file_roott   file_extt
   truncation(    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyR"   A   s    *(/c         C   s@   t  j j | ƒ \ } } t  j j t  j j | |  j | ƒ ƒ ƒ S(   s„   
        Validate the filename by calling get_valid_name() and return a filename
        to be passed to the save() method.
        (   R'   R(   R)   t   normpathR-   R&   (   R   t   filenamet   dirname(    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyt   generate_filename`   s    c         C   s   t  d ƒ ‚ d S(   sâ   
        Returns a local filesystem path where the file can be retrieved using
        Python's built-in open() function. Storage systems that can't be
        accessed using open() should *not* implement this method.
        s,   This backend doesn't support absolute paths.N(   t   NotImplementedError(   R   R   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyR(   i   s    c         C   s   t  d ƒ ‚ d S(   sE   
        Deletes the specified file from the storage system.
        s4   subclasses of Storage must provide a delete() methodN(   R7   (   R   R   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyt   deletet   s    c         C   s   t  d ƒ ‚ d S(   s¥   
        Returns True if a file referenced by the given name already exists in the
        storage system, or False if the name is available for a new file.
        s5   subclasses of Storage must provide an exists() methodN(   R7   (   R   R   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyR+   z   s    c         C   s   t  d ƒ ‚ d S(   s    
        Lists the contents of the specified path, returning a 2-tuple of lists;
        the first item being directories, the second item being files.
        s5   subclasses of Storage must provide a listdir() methodN(   R7   (   R   R(   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyt   listdir   s    c         C   s   t  d ƒ ‚ d S(   sR   
        Returns the total size, in bytes, of the file specified by name.
        s2   subclasses of Storage must provide a size() methodN(   R7   (   R   R   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyt   sizeˆ   s    c         C   s   t  d ƒ ‚ d S(   sv   
        Returns an absolute URL where the file's contents can be accessed
        directly by a Web browser.
        s1   subclasses of Storage must provide a url() methodN(   R7   (   R   R   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyt   urlŽ   s    c         C   s&   t  j d t d d ƒt d ƒ ‚ d S(   s™   
        Returns the last accessed time (as datetime object) of the file
        specified by name. Deprecated: use get_accessed_time() instead.
        sF   Storage.accessed_time() is deprecated in favor of get_accessed_time().t
   stackleveli   s<   subclasses of Storage must provide an accessed_time() methodN(   t   warningst   warnR   R7   (   R   R   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyt   accessed_time•   s
    c         C   s&   t  j d t d d ƒt d ƒ ‚ d S(   s“   
        Returns the creation time (as datetime object) of the file
        specified by name. Deprecated: use get_created_time() instead.
        sD   Storage.created_time() is deprecated in favor of get_created_time().R<   i   s:   subclasses of Storage must provide a created_time() methodN(   R=   R>   R   R7   (   R   R   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyt   created_time¡   s
    c         C   s&   t  j d t d d ƒt d ƒ ‚ d S(   s™   
        Returns the last modified time (as datetime object) of the file
        specified by name. Deprecated: use get_modified_time() instead.
        sF   Storage.modified_time() is deprecated in favor of get_modified_time().R<   i   s;   subclasses of Storage must provide a modified_time() methodN(   R=   R>   R   R7   (   R   R   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyt   modified_time­   s
    c         C   s/   t  j d t d d ƒ|  j | ƒ } t | ƒ S(   sš   
        Return the last accessed time (as a datetime) of the file specified by
        name. The datetime will be timezone-aware if USE_TZ=True.
        s]   Storage.accessed_time() is deprecated. Storage backends should implement get_accessed_time().R<   i   (   R=   R>   R   R?   t   _possibly_make_aware(   R   R   t   dt(    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyt   get_accessed_time¹   s    c         C   s/   t  j d t d d ƒ|  j | ƒ } t | ƒ S(   s•   
        Return the creation time (as a datetime) of the file specified by name.
        The datetime will be timezone-aware if USE_TZ=True.
        s[   Storage.created_time() is deprecated. Storage backends should implement get_created_time().R<   i   (   R=   R>   R   R@   RB   (   R   R   RC   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyt   get_created_timeÉ   s    c         C   s/   t  j d t d d ƒ|  j | ƒ } t | ƒ S(   sš   
        Return the last modified time (as a datetime) of the file specified by
        name. The datetime will be timezone-aware if USE_TZ=True.
        s]   Storage.modified_time() is deprecated. Storage backends should implement get_modified_time().R<   i   (   R=   R>   R   RA   RB   (   R   R   RC   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyt   get_modified_timeÙ   s    N(   t   __name__t
   __module__t   __doc__R   R    R%   R&   R"   R6   R(   R8   R+   R9   R:   R;   R?   R@   RA   RD   RE   RF   (    (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyR      s$   														c         C   s9   t  j r1 t j ƒ  } t j |  | ƒ j t j ƒ S|  Sd S(   sa   
    Convert a datetime object in the local timezone to aware
    in UTC, if USE_TZ is True.
    N(   R   t   USE_TZR   t   get_default_timezonet
   make_awaret
   astimezonet   utc(   RC   t   tz(    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyRB   ê   s    	c           B   s
  e  Z d  Z d d d d d „ Z d „  Z d „  Z e d „  ƒ Z e d „  ƒ Z	 e d „  ƒ Z
 e d „  ƒ Z e d „  ƒ Z d	 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 RS(   s%   
    Standard filesystem storage
    c         C   s8   | |  _  | |  _ | |  _ | |  _ t j |  j ƒ d  S(   N(   t	   _locationt	   _base_urlt   _file_permissions_modet   _directory_permissions_modeR   t   connectt   _clear_cached_properties(   R   t   locationt   base_urlt   file_permissions_modet   directory_permissions_mode(    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyt   __init__þ   s
    				c         K   sŸ   | d k r5 |  j  j d d
 ƒ |  j  j d d
 ƒ nf | d k rW |  j  j d d
 ƒ nD | d k ry |  j  j d d
 ƒ n" | d k r› |  j  j d	 d
 ƒ n  d
 S(   s$   Reset setting based property values.t
   MEDIA_ROOTt   base_locationRV   t	   MEDIA_URLRW   t   FILE_UPLOAD_PERMISSIONSRX   t!   FILE_UPLOAD_DIRECTORY_PERMISSIONSRY   N(   t   __dict__t   popR    (   R   t   settingt   kwargs(    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyRU     s    c         C   s   | d  k r | S| S(   N(   R    (   R   t   valueRb   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyt   _value_or_setting  s    c         C   s   |  j  |  j t j ƒ S(   N(   Re   RP   R   R[   (   R   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyR\     s    c         C   s   t  |  j ƒ S(   N(   R   R\   (   R   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyRV     s    c         C   sJ   |  j  d  k	 r4 |  j  j d ƒ r4 |  j  d 7_  n  |  j |  j  t j ƒ S(   Nt   /(   RQ   R    t   endswithRe   R   R]   (   R   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyRW     s    "c         C   s   |  j  |  j t j ƒ S(   N(   Re   RR   R   R^   (   R   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyRX   #  s    c         C   s   |  j  |  j t j ƒ S(   N(   Re   RS   R   R_   (   R   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyRY   '  s    R   c         C   s   t  t |  j | ƒ | ƒ ƒ S(   N(   R   R   R(   (   R   R   R   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyR   +  s    c         C   s‘  |  j  | ƒ } t j  j | ƒ } t j  j | ƒ s¾ yZ |  j d  k	 r t j d ƒ } z t j | |  j ƒ Wd  t j | ƒ Xn t j | ƒ Wq¾ t k
 rº } | j	 t	 j
 k r» ‚  q» q¾ Xn  t j  j | ƒ sã t d | ƒ ‚ n  xpt rUyt | d ƒ rt | j ƒ  | ƒ nð t j t j Bt j Bt t d d ƒ B} t j | | d ƒ } d  }	 zw t j | t j ƒ x] | j ƒ  D]O }
 |	 d  k r»t |
 t ƒ r d n d } t j | | ƒ }	 n  |	 j |
 ƒ qyWWd  t j | ƒ |	 d  k	 rö|	 j ƒ  n t j | ƒ XWnI t k
 rP} | j	 t	 j
 k rJ|  j  | ƒ } |  j  | ƒ } qR‚  qæ XPqæ W|  j! d  k	 r{t j" | |  j! ƒ n  t# | j$ d d	 ƒ ƒ S(
   Ni    s!   %s exists and is not a directory.t   temporary_file_patht   O_BINARYi¶  t   wbt   wts   \Rf   (%   R(   R'   R5   R+   RY   R    t   umaskt   makedirst   OSErrort   errnot   EEXISTt   isdirt   IOErrort   TrueR!   R   Rh   t   O_WRONLYt   O_CREATt   O_EXCLt   getattrR   R   t   lockt   LOCK_EXR   t
   isinstancet   bytest   fdopent   writet   unlockt   closeR"   RX   t   chmodR   t   replace(   R   R   R$   t	   full_patht	   directoryt	   old_umaskt   et   flagst   fdt   _filet   chunkR   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyR#   .  sV    	c         C   sd   | s t  d ƒ ‚ |  j | ƒ } y t j | ƒ Wn+ t k
 r_ } | j t j k r` ‚  q` n Xd  S(   Ns-   The name argument is not allowed to be empty.(   t   AssertionErrorR(   R'   t   removeRn   Ro   t   ENOENT(   R   R   R…   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyR8   {  s    c         C   s   t  j j |  j | ƒ ƒ S(   N(   R'   R(   R+   (   R   R   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyR+   ‡  s    c         C   s~   |  j  | ƒ } g  g  } } xU t j | ƒ D]D } t j  j t j  j | | ƒ ƒ rc | j | ƒ q, | j | ƒ q, W| | f S(   N(   R(   R'   R9   Rq   R-   t   append(   R   R(   t   directoriest   filest   entry(    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyR9   Š  s    !c         C   s   t  |  j | ƒ S(   N(   R	   RV   (   R   R   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyR(   ”  s    c         C   s   t  j j |  j | ƒ ƒ S(   N(   R'   R(   t   getsize(   R   R   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyR:   —  s    c         C   sX   |  j  d  k r t d ƒ ‚ n  t | ƒ } | d  k	 rH | j d ƒ } n  t |  j  | ƒ S(   Ns&   This file is not accessible via a URL.Rf   (   RW   R    t
   ValueErrorR   t   lstripR   (   R   R   R;   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyR;   š  s    c         C   s8   t  j d t d d ƒt j t j j |  j | ƒ ƒ ƒ S(   NsP   FileSystemStorage.accessed_time() is deprecated in favor of get_accessed_time().R<   i   (   R=   R>   R   R    t   fromtimestampR'   R(   t   getatime(   R   R   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyR?   ¢  s
    c         C   s8   t  j d t d d ƒt j t j j |  j | ƒ ƒ ƒ S(   NsN   FileSystemStorage.created_time() is deprecated in favor of get_created_time().R<   i   (   R=   R>   R   R    R”   R'   R(   t   getctime(   R   R   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyR@   «  s
    c         C   s8   t  j d t d d ƒt j t j j |  j | ƒ ƒ ƒ S(   NsP   FileSystemStorage.modified_time() is deprecated in favor of get_modified_time().R<   i   (   R=   R>   R   R    R”   R'   R(   t   getmtime(   R   R   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyRA   ´  s
    c         C   s6   t  j r% t j | ƒ j d t j ƒ St j | ƒ Sd S(   s‘   
        If timezone support is enabled, make an aware datetime object in UTC;
        otherwise make a naive one in the local timezone.
        t   tzinfoN(   R   RJ   R    t   utcfromtimestampR   R   RN   R”   (   R   t   ts(    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyt   _datetime_from_timestamp½  s    	c         C   s"   |  j  t j j |  j | ƒ ƒ ƒ S(   N(   R›   R'   R(   R•   (   R   R   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyRD   È  s    c         C   s"   |  j  t j j |  j | ƒ ƒ ƒ S(   N(   R›   R'   R(   R–   (   R   R   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyRE   Ë  s    c         C   s"   |  j  t j j |  j | ƒ ƒ ƒ S(   N(   R›   R'   R(   R—   (   R   R   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyRF   Î  s    N(   RG   RH   RI   R    RZ   RU   Re   R   R\   RV   RW   RX   RY   R   R#   R8   R+   R9   R(   R:   R;   R?   R@   RA   R›   RD   RE   RF   (    (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyR   ø   s2   				M			
												c         C   s   t  |  p t j ƒ S(   N(   R   R   t   DEFAULT_FILE_STORAGE(   t   import_path(    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyt   get_storage_classÒ  s    c           B   s   e  Z d  „  Z RS(   c         C   s   t  ƒ  ƒ  |  _ d  S(   N(   Rž   t   _wrapped(   R   (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyt   _setup×  s    (   RG   RH   R    (    (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyR   Ö  s   (   R   R   R   R   (/   Ro   R'   R=   R    t   django.confR   t   django.core.exceptionsR   t   django.core.filesR   R   t   django.core.files.moveR   t   django.core.signalsR   t   django.utilsR   t   django.utils._osR   R	   t   django.utils.cryptoR
   t   django.utils.deconstructR   t   django.utils.deprecationR   t   django.utils.encodingR   R   t   django.utils.functionalR   R   t   django.utils.module_loadingR   t#   django.utils.six.moves.urllib.parseR   t   django.utils.textR   t   __all__t   objectR   RB   R   R    Rž   R   R   (    (    (    s;   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/storage.pyt   <module>   s4   Ñ	Ù