o
    ^"<fR                     @   st   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	 G dd de
ZG dd	 d	eZG d
d deZdS )    N)file_move_safe)	smart_str)
FileObject)DEFAULT_PERMISSIONSc                   @   sB   e Zd ZdZdd Zdd ZdddZd	d
 Zdd Zdd Z	dS )StorageMixinz8
    Adds some useful methods to the Storage class.
    c                 C      t  )zA
        Returns true if name exists and is a directory.
        NotImplementedErrorselfname r   J/var/www/html/kck/venv/lib/python3.10/site-packages/filebrowser/storage.pyisdir      zStorageMixin.isdirc                 C   r   )zD
        Returns true if name exists and is a regular file.
        r   r
   r   r   r   isfile   r   zStorageMixin.isfileFc                 C   r   )z
        Moves safely a file from one location to another.

        If allow_ovewrite==False and new_file_name exists, raises an exception.
        r   r   old_file_namenew_file_nameallow_overwriter   r   r   move   s   zStorageMixin.movec                 C   r   )z]
        Creates all missing directories specified by name. Analogue to os.mkdirs().
        r   r
   r   r   r   makedirs%   r   zStorageMixin.makedirsc                 C   r   )z^
        Deletes a directory and everything it contains. Analogue to shutil.rmtree().
        r   r
   r   r   r   rmtree+   r   zStorageMixin.rmtreec                 C   r   )z&
        Sets file permission
        r   r
   r   r   r   setpermission1   r   zStorageMixin.setpermissionNF)
__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r   r   r      s    
r   c                   @   >   e Zd Zdd Zdd ZdddZdd	 Zd
d Zdd ZdS )FileSystemStorageMixinc                 C      t j| |S N)ospathr   r
   r   r   r   r   :      zFileSystemStorageMixin.isdirc                 C   r!   r"   )r#   r$   r   r
   r   r   r   r   =   r%   zFileSystemStorageMixin.isfileFc                 C   s   t | || |dd d S )NT)r   )r   r$   r   r   r   r   r   @   s   zFileSystemStorageMixin.movec                 C      t | | d S r"   )r#   r   r$   r
   r   r   r   r   C      zFileSystemStorageMixin.makedirsc                 C   r&   r"   )shutilr   r$   r
   r   r   r   r   F   r'   zFileSystemStorageMixin.rmtreec                 C   s"   t t|| dj}t|t d S )N)site)r   r   	path_fullr#   chmodr   )r   r   	full_pathr   r   r   r   I   s   z$FileSystemStorageMixin.setpermissionNr   )	r   r   r   r   r   r   r   r   r   r   r   r   r   r    8   s    
r    c                   @   r   )S3BotoStorageMixinc                 C   s
   |  |S r"   )existsr
   r   r   r   r   P   s   
zS3BotoStorageMixin.isfilec                 C   sJ   |sdS |  |rdS | | |}| j| |}|D ]} dS dS )NTF)r   _normalize_name_clean_namebucketlist_encode_namer   r   dirlistitemr   r   r   r   S   s   
zS3BotoStorageMixin.isdirFc                 C   s   |  |r|r| | nd| | | | |}| | | |}| j|| jj|}|s9d||f | | d S )Nz=The destination file '%s' exists and allow_overwrite is FalsezCouldn't copy '%s' to '%s')r.   deleter3   r/   r0   r1   copy_keyr   )r   r   r   r   old_key_namenew_key_namekr   r   r   r   e   s   
zS3BotoStorageMixin.movec                 C      d S r"   r   r
   r   r   r   r   w   s   zS3BotoStorageMixin.makedirsc                 C   s8   |  | |}| j| |}|D ]}|  qd S r"   )r/   r0   r1   r2   r3   r7   r4   r   r   r   r   z   s
   
zS3BotoStorageMixin.rmtreec                 C   r<   r"   r   r
   r   r   r   r      s   z S3BotoStorageMixin.setpermissionNr   )	r   r   r   r   r   r   r   r   r   r   r   r   r   r-   N   s    
r-   )r#   r(   django.core.files.mover   django.utils.encodingr   filebrowser.baser   filebrowser.settingsr   objectr   r    r-   r   r   r   r   <module>   s   ,