ó
TR¹Nc           @   s-  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 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  d
 l m Z d Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d d „ Z d e f d „  ƒ  YZ e ƒ  Z d S(   iÿÿÿÿN(   t   settings(   t   ImproperlyConfiguredt   SuspiciousOperation(   t   lockst   File(   t   file_move_safe(   t   force_unicode(   t
   LazyObject(   t   import_module(   t   get_valid_filename(   t	   safe_joint   Storaget   FileSystemStoraget   DefaultStoraget   default_storagec           B   sn   e  Z d  Z d d 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  | | ƒ } | r< t | j | | j f i  ƒ | _ n  | S(   s¢   
        Retrieves the specified file from storage, using the optional mixin
        class to customize what features are available on the File returned.
        (   t   _opent   typet   __name__t	   __class__(   t   selft   namet   modet   mixint   file(    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/files/storage.pyt   open   s    $c         C   sO   | d k r | j } n  |  j | ƒ } |  j | | ƒ } t | j d d ƒ ƒ S(   s›   
        Saves new content to the file specified by name. The content should be a
        proper File object, ready to be read from the beginning.
        s   \t   /N(   t   NoneR   t   get_available_namet   _saveR   t   replace(   R   R   t   content(    (    sF   /home/panlixing/Python_Projects/gaeseries/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   (    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/files/storage.pyt   get_valid_name7   s    c         C   s   t  j j | ƒ \ } } t  j j | ƒ \ } } t j d ƒ } x; |  j | ƒ r| t  j j | d | | j ƒ  | f ƒ } qB W| S(   s†   
        Returns a filename that's free on the target storage system, and
        available for new content to be written to.
        i   s   %s_%s%s(	   t   ost   patht   splitt   splitextt	   itertoolst   countt   existst   joint   next(   R   R   t   dir_namet	   file_namet	   file_roott   file_extR'   (    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/files/storage.pyR   >   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   (    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/files/storage.pyR#   O   s    c         C   s   t  ƒ  ‚ d S(   sE   
        Deletes the specified file from the storage system.
        N(   R/   (   R   R   (    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/files/storage.pyt   deleteZ   s    c         C   s   t  ƒ  ‚ d S(   s¤   
        Returns True if a file referened by the given name already exists in the
        storage system, or False if the name is available for a new file.
        N(   R/   (   R   R   (    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/files/storage.pyR(   `   s    c         C   s   t  ƒ  ‚ 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.
        N(   R/   (   R   R#   (    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/files/storage.pyt   listdirg   s    c         C   s   t  ƒ  ‚ d S(   sR   
        Returns the total size, in bytes, of the file specified by name.
        N(   R/   (   R   R   (    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/files/storage.pyt   sizen   s    c         C   s   t  ƒ  ‚ d S(   sv   
        Returns an absolute URL where the file's contents can be accessed
        directly by a web browser.
        N(   R/   (   R   R   (    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/files/storage.pyt   urlt   s    N(   R   t
   __module__t   __doc__R   R   R    R!   R   R#   R0   R(   R1   R2   R3   (    (    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/files/storage.pyR      s   								c           B   sh   e  Z d  Z d d d „ Z d d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z RS(   s%   
    Standard filesystem storage
    c         C   sR   | d  k r t j } n  | d  k r0 t j } n  t j j | ƒ |  _ | |  _ d  S(   N(	   R   R    t
   MEDIA_ROOTt	   MEDIA_URLR"   R#   t   abspatht   locationt   base_url(   R   R9   R:   (    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/files/storage.pyt   __init__€   s    R   c         C   s   t  t |  j | ƒ | ƒ ƒ S(   N(   R   R   R#   (   R   R   R   (    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/files/storage.pyR   ˆ   s    c         C   s­  |  j  | ƒ } t j  j | ƒ } t j  j | ƒ sC t j | ƒ n% t j  j | ƒ sh t d | ƒ ‚ n  xt rƒyÂ t | d ƒ r£ t	 | j
 ƒ  | ƒ | j ƒ  n t j | t j t j Bt j Bt t d d ƒ Bƒ } z> t j | t j ƒ x$ | j ƒ  D] } t j | | ƒ qù WWd  t j | ƒ t j | ƒ XWnI t k
 r~} | j t j k rx|  j | ƒ } |  j  | ƒ } q€‚  qk XPqk Wt j d  k	 r©t j | t j ƒ n  | S(   Ns!   %s exists and is not a directory.t   temporary_file_patht   O_BINARYi    (   R#   R"   t   dirnameR(   t   makedirst   isdirt   IOErrort   Truet   hasattrR   R<   t   closeR   t   O_WRONLYt   O_CREATt   O_EXCLt   getattrR   t   lockt   LOCK_EXt   chunkst   writet   unlockt   OSErrort   errnot   EEXISTR   R    t   FILE_UPLOAD_PERMISSIONSR   t   chmod(   R   R   R   t	   full_patht	   directoryt   fdt   chunkt   e(    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/files/storage.pyR   ‹   s6    	3c         C   s5   |  j  | ƒ } t j  j | ƒ r1 t j | ƒ n  d  S(   N(   R#   R"   R(   t   remove(   R   R   (    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/files/storage.pyR0   ½   s    c         C   s   t  j j |  j | ƒ ƒ S(   N(   R"   R#   R(   (   R   R   (    (    sF   /home/panlixing/Python_Projects/gaeseries/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"   R1   R@   R)   t   append(   R   R#   t   directoriest   filest   entry(    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/files/storage.pyR1   Æ   s    !c         C   sJ   y t  |  j | ƒ } Wn! t k
 r9 t d | ƒ ‚ n Xt j j | ƒ S(   Ns    Attempted access to '%s' denied.(   R
   R9   t
   ValueErrorR   R"   R#   t   normpath(   R   R   R#   (    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/files/storage.pyR#   Ð   s
    c         C   s   t  j j |  j | ƒ ƒ S(   N(   R"   R#   t   getsize(   R   R   (    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/files/storage.pyR2   ×   s    c         C   s=   |  j  d  k r t d ƒ ‚ n  t j |  j  | ƒ j d d ƒ S(   Ns&   This file is not accessible via a URL.s   \R   (   R:   R   R]   t   urlparset   urljoinR   (   R   R   (    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/files/storage.pyR3   Ú   s    N(   R   R4   R5   R   R;   R   R   R0   R(   R1   R#   R2   R3   (    (    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/files/storage.pyR   {   s   	2			
		c         C   sã   |  d  k r t j }  n  y |  j d ƒ } Wn! t k
 rN t d |  ƒ ‚ n X|  |  |  | d } } y t | ƒ } Wn) t k
 r£ } t d | | f ƒ ‚ n Xy t | | ƒ SWn' t	 k
 rÞ t d | | f ƒ ‚ n Xd  S(   Nt   .s   %s isn't a storage module.i   s'   Error importing storage module %s: "%s"s1   Storage module "%s" does not define a "%s" class.(
   R   R    t   DEFAULT_FILE_STORAGEt   rindexR]   R   R   t   ImportErrorRH   t   AttributeError(   t   import_patht   dott   modulet	   classnamet   modRW   (    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/files/storage.pyt   get_storage_classß   s    c           B   s   e  Z d  „  Z RS(   c         C   s   t  ƒ  ƒ  |  _ d  S(   N(   Rl   t   _wrapped(   R   (    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/files/storage.pyt   _setupñ   s    (   R   R4   Rn   (    (    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/files/storage.pyR   ð   s   (   s   Storages   FileSystemStorages   DefaultStorages   default_storage(    R"   RO   R`   R&   t   django.confR    t   django.core.exceptionsR   R   t   django.core.filesR   R   t   django.core.files.moveR   t   django.utils.encodingR   t   django.utils.functionalR   t   django.utils.importlibR   t   django.utils.textR	   t   django.utils._osR
   t   __all__t   objectR   R   R   Rl   R   R   (    (    (    sF   /home/panlixing/Python_Projects/gaeseries/django/core/files/storage.pyt   <module>   s$   id