HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/django/core/files/__pycache__/storage.cpython-310.pyc
o

/�hB>�@s"ddlZddlZddlmZddlmZddlmZddlmZddl	m
Z
mZddlm
Z
ddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZmZddlm Z ddl!m"Z"dZ#Gdd�d�Z$eGdd�de$��Z%ddd�Z&Gdd�de�Z'e'�Z(dS)�N)�datetime)�urljoin)�settings)�SuspiciousFileOperation)�File�locks)�file_move_safe)�validate_file_name)�setting_changed)�timezone)�	safe_join��get_random_string)�deconstructible)�filepath_to_uri)�
LazyObject�cached_property)�
import_string��get_valid_filename)�Storage�FileSystemStorage�DefaultStorage�default_storage�get_storage_classc@s�eZdZdZd"dd�Zd#dd�Zdd	�Zd
d�Zd#dd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�ZdS)$rz�
    A base storage class, providing some default behaviors that all other
    storage systems can inherit or override, as necessary.
    �rbcCs|�||�S)z)Retrieve the specified file from storage.)�_open��self�name�mode�r!�;/usr/lib/python3/dist-packages/django/core/files/storage.py�open$szStorage.openNcCsd|dur|j}t|d�st||�}t|dd�|j||d�}t|dd�|�||�}t|dd�|S)z�
        Save 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.
        N�chunksT)�allow_relative_path)�
max_length)r�hasattrrr	�get_available_name�_save)rr�contentr&r!r!r"�save(s

zStorage.savecCst|�S)z�
        Return a filename, based on the provided filename, that's suitable for
        use in the target storage system.
        r�rrr!r!r"�get_valid_nameH�zStorage.get_valid_namecCsd|td�|fS)z�
        Return an alternative filename, by adding an underscore and a random 7
        character alphanumeric string (before the file extension, if one
        exists) to the filename.
        z%s_%s%s�r
)r�	file_root�file_extr!r!r"�get_alternative_nameOszStorage.get_alternative_namecCs�t|��dd�}tj�|�\}}dt�|�jvrtd|��t	|�tj�
|�\}}|�|�s7|rxt|�|krxtj�
||�||��}|durGq*t|�|}|dkrk|d|�}|s`td|��tj�
||�||��}|�|�s7|rxt|�|ks7|S)z�
        Return a filename that's free on the target storage system and
        available for new content to be written to.
        �\�/�..�'Detected path traversal attempt in '%s'Nrz�Storage can not find an available filename for "%s". Please make sure that the corresponding file field allows sufficient "max_length".)�str�replace�os�path�split�pathlib�PurePath�partsrr	�splitext�exists�len�joinr2)rrr&�dir_name�	file_namer0r1�
truncationr!r!r"r(Ws,���zStorage.get_available_namecCsXt|��dd�}tj�|�\}}dt�|�jvrtd|��tj�	tj�
||�|���S)z�
        Validate the filename by calling get_valid_name() and return a filename
        to be passed to the save() method.
        r3r4r5r6)r7r8r9r:r;r<r=r>r�normpathrBr-)r�filename�dirnamer!r!r"�generate_filenameys
zStorage.generate_filenamecC�td��)z�
        Return 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.
        z,This backend doesn't support absolute paths.��NotImplementedErrorr,r!r!r"r:�szStorage.pathcCrJ)zD
        Delete the specified file from the storage system.
        z4subclasses of Storage must provide a delete() methodrKr,r!r!r"�delete��zStorage.deletecCrJ)z�
        Return 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.
        z5subclasses of Storage must provide an exists() methodrKr,r!r!r"r@�r.zStorage.existscCrJ)z�
        List the contents of the specified path. Return a 2-tuple of lists:
        the first item being directories, the second item being files.
        z5subclasses of Storage must provide a listdir() methodrK)rr:r!r!r"�listdir�r.zStorage.listdircCrJ)zQ
        Return the total size, in bytes, of the file specified by name.
        z2subclasses of Storage must provide a size() methodrKr,r!r!r"�size�rNzStorage.sizecCrJ)zu
        Return an absolute URL where the file's contents can be accessed
        directly by a Web browser.
        z1subclasses of Storage must provide a url() methodrKr,r!r!r"�url�r.zStorage.urlcCrJ)z�
        Return the last accessed time (as a datetime) of the file specified by
        name. The datetime will be timezone-aware if USE_TZ=True.
        z?subclasses of Storage must provide a get_accessed_time() methodrKr,r!r!r"�get_accessed_time�r.zStorage.get_accessed_timecCrJ)z�
        Return the creation time (as a datetime) of the file specified by name.
        The datetime will be timezone-aware if USE_TZ=True.
        z>subclasses of Storage must provide a get_created_time() methodrKr,r!r!r"�get_created_time�r.zStorage.get_created_timecCrJ)z�
        Return the last modified time (as a datetime) of the file specified by
        name. The datetime will be timezone-aware if USE_TZ=True.
        z?subclasses of Storage must provide a get_modified_time() methodrKr,r!r!r"�get_modified_time�r.zStorage.get_modified_time�r�N)�__name__�
__module__�__qualname__�__doc__r#r+r-r2r(rIr:rMr@rOrPrQrRrSrTr!r!r!r"rs"

 
"rc@s�eZdZdZejejBejBeedd�BZ			d.dd�Z
dd�Zd	d
�Ze
dd��Ze
d
d��Ze
dd��Ze
dd��Ze
dd��Zd/dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�ZdS)0rz%
    Standard filesystem storage
    �O_BINARYrNcCs(||_||_||_||_t�|j�dSrV)�	_location�	_base_url�_file_permissions_mode�_directory_permissions_moder
�connect�_clear_cached_properties)r�location�base_url�file_permissions_mode�directory_permissions_moder!r!r"�__init__�s
zFileSystemStorage.__init__cKsz|dkr|j�dd�|j�dd�dS|dkr!|j�dd�dS|dkr.|j�dd�dS|d	kr;|j�d
d�dSdS)z$Reset setting based property values.�
MEDIA_ROOT�
base_locationNrb�	MEDIA_URLrc�FILE_UPLOAD_PERMISSIONSrd�!FILE_UPLOAD_DIRECTORY_PERMISSIONSre)�__dict__�pop)r�setting�kwargsr!r!r"ra�s�z*FileSystemStorage._clear_cached_propertiescCs|dur|S|SrVr!)r�valuernr!r!r"�_value_or_setting�sz#FileSystemStorage._value_or_settingcC�|�|jtj�SrV)rqr\rrg�rr!r!r"rh��zFileSystemStorage.base_locationcCstj�|j�SrV)r9r:�abspathrhrsr!r!r"rb�szFileSystemStorage.locationcCs4|jdur|j�d�s|jd7_|�|jtj�S)Nr4)r]�endswithrqrrirsr!r!r"rc�szFileSystemStorage.base_urlcCrrrV)rqr^rrjrsr!r!r"rd�rtz'FileSystemStorage.file_permissions_modecCrrrV)rqr_rrkrsr!r!r"re�rtz,FileSystemStorage.directory_permissions_modercCstt|�|�|��SrV)rr#r:rr!r!r"r�szFileSystemStorage._openc
	Cs�|�|�}tj�|�}z.|jdur1t�d|j@�}ztj||jdd�Wt�|�n
t�|�wtj|dd�Wn
tyFtd|��w	zit|d�rVt|�	�|�nZt�
||jd�}d}z;t�
|tj�|��D]}|dur�t|t�rydnd}	t�||	�}|�|�qlWt�|�|dur�|��nt�|�nt�|�|dur�|��wt�|�wWnty�|�|�}|�|�}YnwnqH|jdur�t�||j�tj�||j�}t|��d	d
�S)Ni�T)�exist_okz!%s exists and is not a directory.�temporary_file_pathi��wb�wtr3r4)r:r9rHre�umask�makedirs�FileExistsErrorr'rrxr#�
OS_OPEN_FLAGSr�lock�LOCK_EXr$�
isinstance�bytes�fdopen�write�unlock�closer(rd�chmod�relpathrbr7r8)
rrr*�	full_path�	directory�	old_umask�fd�_file�chunkr r!r!r"r)s\

��	
�


�
�
��
 zFileSystemStorage._savecCsX|sJd��|�|�}ztj�|�rt�|�WdSt�|�WdSty+YdSw)Nz-The name argument is not allowed to be empty.)r:r9�isdir�rmdir�remove�FileNotFoundErrorr,r!r!r"rMAs
�zFileSystemStorage.deletecC�tj�|�|��SrV)r9r:r@r,r!r!r"r@O�zFileSystemStorage.existscCsN|�|�}gg}}t�|�D]}|��r|�|j�q|�|j�q||fSrV)r:r9�scandir�is_dir�appendr)rr:�directories�files�entryr!r!r"rORs

zFileSystemStorage.listdircCst|j|�SrV)rrbr,r!r!r"r:\szFileSystemStorage.pathcCr�rV)r9r:�getsizer,r!r!r"rP_r�zFileSystemStorage.sizecCs8|jdur	td��t|�}|dur|�d�}t|j|�S)Nz&This file is not accessible via a URL.r4)rc�
ValueErrorr�lstripr)rrrQr!r!r"rQbs

zFileSystemStorage.urlcCs$tjr
t�|�jtjd�St�|�S)z�
        If timezone support is enabled, make an aware datetime object in UTC;
        otherwise make a naive one in the local timezone.
        )�tzinfo)r�USE_TZr�utcfromtimestampr8r�utc�
fromtimestamp)r�tsr!r!r"�_datetime_from_timestampjs
z*FileSystemStorage._datetime_from_timestampcC�|�tj�|�|���SrV)r�r9r:�getatimer,r!r!r"rRu�z#FileSystemStorage.get_accessed_timecCr�rV)r�r9r:�getctimer,r!r!r"rSxr�z"FileSystemStorage.get_created_timecCr�rV)r�r9r:�getmtimer,r!r!r"rT{r�z#FileSystemStorage.get_modified_time)NNNNrU)rWrXrYrZr9�O_WRONLY�O_CREAT�O_EXCL�getattrr~rfrarqrrhrbrcrdrerr)rMr@rOr:rPrQr�rRrSrTr!r!r!r"r�s<
�





A
rcCst|ptj�SrV)rr�DEFAULT_FILE_STORAGE)�import_pathr!r!r"r�rc@seZdZdd�ZdS)rcCst��|_dSrV)r�_wrappedrsr!r!r"�_setup�r�zDefaultStorage._setupN)rWrXrYr�r!r!r!r"r�srrV))r9r<r�urllib.parser�django.confr�django.core.exceptionsr�django.core.filesrr�django.core.files.mover�django.core.files.utilsr	�django.core.signalsr
�django.utilsr�django.utils._osr�django.utils.cryptor�django.utils.deconstructr�django.utils.encodingr�django.utils.functionalrr�django.utils.module_loadingr�django.utils.textr�__all__rrrrrr!r!r!r"�<module>s6-
8