
     +h                         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	 d dl
mZ d ZddZd	 Zd
 Zd Zd Zd Zd Z G d de	          ZdS )    N)settings)ImproperlyConfigured)SuspiciousFileOperation)FileProxyMixin)force_bytesc                 N    t          | t                    r| S t          |           S )z5Wrap Django's force_bytes to pass through bytearrays.)
isinstance	bytearrayr   )contents    R/var/www/html/e360mart/e360mart_env/lib/python3.11/site-packages/storages/utils.pyto_bytesr      s'    '9%% w    c                 .    t          t          | |          S )z
    Helper function to get a Django setting by name. If setting doesn't exists
    it will return a default.

    :param name: Name of setting
    :type name: str
    :param default: Value if setting is unfound
    :returns: Setting's value
    )getattrr   )namedefaults     r   settingr      s     8T7+++r   c                    t          | t          j                  rt          |           } t	          j        |                               dd          }|                     d          r|                    d          s|dz  }|dk    rd}|S )z
    Normalize the name.

    Includes cleaning up Windows style paths, ensuring an ending trailing slash,
    and coercing from pathlib.PurePath.
    \/. )r	   pathlibPurePathstr	posixpathnormpathreplaceendswith)r   
clean_names     r   r    r    !   s     $()) 4yy #D))11$<<J }}S *"5"5c":": c
 S
r   c                    | }|                     d          }t          |          }|dz   }|D ]N}t          j        t          j        ||                    }|                    d          s	|dz   |k    r|dz  }|}O||k    r|dz  }t          |          }|                    |          r||         dk    rt          d          |	                    d          S )a  
    A version of django.utils._os.safe_join for S3 paths.

    Joins one or more path components to the base path component
    intelligently. Returns a normalized version of the final path.

    The final path must be located inside of the base path component
    (otherwise a ValueError is raised).

    Paths outside the base path indicate a possible security
    sensitive operation.
    r   z=the joined path is located outside of the base path component)
rstriplistr   r   joinr   len
startswith
ValueErrorlstrip)basepaths	base_path
final_pathpath_final_pathbase_path_lens          r   	safe_joinr0   ;   s    I  %%IKKESJ ! !(
D)I)IJJ== 	s!2j!@!@3K 

Yc
 	NNM  ++ 
z-/HC/O/OK
 
 	
 S!!!r   c                     | j                             d          rM| j                             d          }t          d                    | j        j        | j         |                    d S )Nr   zL{}.location cannot begin with a leading slash. Found '{}'. Use '{}' instead.)locationr&   r(   r   format	__class____name__)storagecorrects     r   check_locationr8   a   ss    ""3'' 
"))#.."f!*  		
 	
 		

 
r   c                 Z    | D ]'}t           j                            |          }|r|c S (dS )zP
    Look up for names in environment. Returns the first element
    found.
    N)osenvironget)namesr   values      r   
lookup_envr?   p   sF    
   
t$$ 	LLL	 r   c                    |t          |           |k    r| S t          j                            |           \  }}t          j                            |          \  }}t          |           |z
  }|d |          }|st          d| z            t          j                            |d                    ||                    S )NzStorage tried to truncate away entire filename "%s". Please make sure that the corresponding file field allows sufficient "max_length".z{}{})r%   r:   r-   splitsplitextr   r$   r3   )r   
max_lengthdir_name	file_name	file_rootfile_ext
truncations          r   get_available_overwrite_namerI   {   s    SYY*44 '----Hi'**955IxTZ'J,J;,'I 
%.045
 
 	

 7<<&--	8"D"DEEEr   c                 L    t          | d           p|                                 S )Nseekable)hasattrrK   )file_objects    r   is_seekablerN      s&    {J///I;3G3G3I3IIr   c                   ,    e Zd ZdZddZd Zd Zd ZdS )ReadBytesWrapperzS
    A wrapper for a file-like object, that makes read() always returns bytes.
    Nc                 H    || _         |pt          |dd          pd| _        dS )a   
        :param file: The file-like object to wrap.
        :param encoding: Specify the encoding to use when file.read() returns strings.
            If not provided will default to file.encoding, of if that's not available,
            to utf-8.
        encodingNzutf-8)filer   	_encoding)selfrS   rR   s      r   __init__zReadBytesWrapper.__init__   s,     	!OWT:t%D%DOr   c                      | j         j        |i |}t          |t                    s|                    | j                  }|S N)rS   readr	   bytesencoderT   )rU   argskwargsr   s       r   rY   zReadBytesWrapper.read   sD     $).$1&11'5)) 	5nnT^44Gr   c                 8    | j                                          d S rX   )rS   closerU   s    r   r_   zReadBytesWrapper.close   s    	r   c                     dS )NT r`   s    r   readablezReadBytesWrapper.readable   s    tr   rX   )r5   
__module____qualname____doc__rV   rY   r_   rc   rb   r   r   rP   rP      sc         P P P P        r   rP   rX   )r:   r   r   django.confr   django.core.exceptionsr   r   django.core.files.utilsr   django.utils.encodingr   r   r   r    r0   r8   r?   rI   rN   rP   rb   r   r   <module>rk      s5   				                  7 7 7 7 7 7 : : : : : : 2 2 2 2 2 2 - - - - - -     
, 
, 
, 
,  4#" #" #"L
 
 
  F F F&J J J    ~     r   