o
    h"                     @   sT   d dl Zd dlmZ dZdeeeZdd Z	e	dd Z
						dd
dZdS )    N)
guess_type)r         .c                    s(   g   fdd} fdd}||_ |S )Nc                      s    s     d S )Nr   )append _cachedfnr   V/var/www/html/ndineBlogger/venv/lib/python3.10/site-packages/wagtail/utils/sendfile.py
_decorated   s   z_lazy_load.<locals>._decoratedc                      s    r
     sd S d S )N)popr   )r	   r   r   clear   s   z_lazy_load.<locals>.clear)r   )r
   r   r   r   r   r   
_lazy_load   s
   r   c                  C   sJ   ddl m}  ddlm} ddlm} t|dd }|s|d| |}|jS )Nr   )import_module)settings)ImproperlyConfiguredSENDFILE_BACKENDz-You must specify a value for SENDFILE_BACKEND)	importlibr   django.confr   django.core.exceptionsr   getattrsendfile)r   r   r   backendmoduler   r   r   _get_sendfile   s   r   Fc                 C   s  |pt  }tj|sddlm} |d| t|\}	}
|du r(|	r&|	}nd}|| ||d}|r5dg}ndg}|du rBtj|}|rtdd	lm	} dd
l
m} ||}||}|d|  ||krtddlm} ||}|d|  d||d< tj||d< ||d< |p|
|d< |S )aQ  
    create a response to send file using backend configured in SENDFILE_BACKEND

    If attachment is True the content-disposition header will be set.
    This will typically prompt the user to download the file, rather
    than view it.  The content-disposition filename depends on the
    value of attachment_filename:

        None (default): Same as filename
        False: No content-disposition filename
        String: Value used as filename

    If no mimetype or encoding are specified, then they will be guessed via the
    filename (using the standard python mimetypes module)
    r   )Http404z"%s" does not existNzapplication/octet-stream)mimetype
attachmentinline)	force_str)string_to_asciizfilename="%s")quotezfilename*=UTF-8''%sz; zContent-DispositionzContent-lengthzContent-TypezContent-Encoding)r   ospathexistsdjango.httpr   r   basenamedjango.utils.encodingr    wagtail.coreutilsr!   r   urllib.parser"   joingetsize)requestfilenamer   attachment_filenamer   encodingr   	_sendfiler   guessed_mimetypeguessed_encodingresponsepartsr    r!   ascii_filenamer"   quoted_filenamer   r   r   r   )   s<   
r   )FNNNN)os.pathr#   	mimetypesr   VERSIONr+   mapstr__version__r   r   r   r   r   r   r   <module>   s   
