OwlCyberSecurity - MANAGER
Edit File: base.cpython-39.pyc
a ���e � @ s^ d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm Z d dl mZ G dd� d�ZdS ) � N)�SuspiciousFileOperation)�File)�validate_file_name��get_random_string��get_valid_filenamec @ s� e Zd ZdZd"dd�Zd#dd�Zdd � Zd d� Zd$dd �Zdd� Z dd� Z dd� Zdd� Zdd� Z dd� Zdd� Zdd� Zdd� Zd d!� ZdS )%�Storagez� A base storage class, providing some default behaviors that all other storage systems can inherit or override, as necessary. �rbc C s | � ||�S )z)Retrieve the specified file from storage.)�_open)�self�name�mode� r �_/home/gouroczh/virtualenv/pat/3.9/lib/python3.9/site-packages/django/core/files/storage/base.py�open s zStorage.openNc C sL |du r|j }t|d�s"t||�}| j||d�}| �||�}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�chunks)� max_lengthT)Zallow_relative_path)r �hasattrr �get_available_nameZ_saver )r r �contentr r r r �save s zStorage.savec C s t |�S )z� Return a filename, based on the provided filename, that's suitable for use in the target storage system. r �r r r r r �get_valid_name- s zStorage.get_valid_namec C s d|t d�|f S )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_name4 s zStorage.get_alternative_namec C s� t |��dd�}tj�|�\}}dt�|�jv r<td| ��t |� tj� |�\}}| �|�sn|r�t|�|kr�tj� || �||��}|du r�qTt|�| }|dkrT|d| � }|s�td| ��tj� || �||��}qT|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'Nr z�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�partsr r �splitext�exists�len�joinr )r r r �dir_name� file_namer r Z truncationr r r r <