Ë
    ¹2Úi   ã                   ó~   — d Z ddlZddlmZmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ  G d„ d	e«      Z G d
„ dee«      Zy)zVBase material for download views: :class:`DownloadMixin` and
:class:`BaseDownloadView`é    N)ÚHttp404ÚHttpResponseNotModified)ÚView)Úwas_modified_since)Ú
exceptions)ÚDownloadResponsec                   óZ   — e Zd ZdZeZdZdZdZdZ	d„ Z
d„ Zd„ Zd„ Zd„ Zd	„ Zd
„ Zd„ Zd„ Zy)ÚDownloadMixina¬  Placeholders and base implementation to create file download views.

    .. note::

       This class does not inherit from
       :py:class:`django.views.generic.base.View`.

    The :py:meth:`get_file` method is a placeholder subclasses must implement.
    Base implementation raises ``NotImplementedError``.

    Other methods provide a base implementation that use the file wrapper
    returned by :py:meth:`get_file`.

    TNc                 ó   — t        «       ‚)z�Return a file wrapper instance.

        Raises :class:`~django_downloadview.exceptions.FileNotFound` if file
        does not exist.

        )ÚNotImplementedError©Úselfs    úU/var/www/html/acx/venv/lib/python3.12/site-packages/django_downloadview/views/base.pyÚget_filezDownloadMixin.get_file?   s   € ô "Ó#Ð#ó    c                 ó   — | j                   S )zcReturn :attr:`basename`.

        Override this method if you need more dynamic basename.

        )Úbasenamer   s    r   Úget_basenamezDownloadMixin.get_basenameH   ó   € ð �}‰}Ðr   c                 ó   — | j                   S )zdReturn :attr:`mimetype`.

        Override this method if you need more dynamic mime type.

        )Úmimetyper   s    r   Úget_mimetypezDownloadMixin.get_mimetypeP   r   r   c                 ó   — | j                   S )zcReturn :attr:`encoding`.

        Override this method if you need more dynamic encoding.

        )Úencodingr   s    r   Úget_encodingzDownloadMixin.get_encodingX   r   r   c                 ó0  — 	 |j                  |«      S # t        t        f$ rs 	 t        j                  |j
                  j                  «       «      }|j                  }t        |||«      cY S # t        t        f$ r}t        d|«       Y d}~Y yd}~ww xY ww xY w)a¤  Return True if ``file_instance`` was modified after ``since``.

        Uses file wrapper's ``was_modified_since`` if available, with value of
        ``since`` as positional argument.

        Else, fallbacks to default implementation, which uses
        :py:func:`django.views.static.was_modified_since`.

        Django's ``was_modified_since`` function needs a datetime and a size.
        It is passed ``modified_time`` and ``size`` attributes from file
        wrapper. If file wrapper does not support these attributes
        (``AttributeError`` or ``NotImplementedError`` is raised), then
        the file is considered as modified and ``True`` is returned.

        z	!=======!NT)	r   ÚAttributeErrorr   ÚcalendarÚtimegmÚmodified_timeÚutctimetupleÚsizeÚprint)r   Úfile_instanceÚsinceÚmodification_timer"   Úes         r   r   z DownloadMixin.was_modified_since`   s›   € ð 	JØ ×3Ñ3°EÓ:Ð:øÜÔ 3Ð4ò 
	Jð	JÜ$,§O¡OØ!×/Ñ/×<Ñ<Ó>ó%Ð!ð %×)Ñ)�ô
 *¨%Ð1BÀDÓIÒIøô	 #Ô$7Ð8ò Ü�k 1Ô%Ýûðúð
	Jús2   ‚ “B£9A+ÁBÁ+BÁ:BÂBÂBÂBc                 ó   — t        |i |¤ŽS )z=Return :class:`django.http.HttpResponseNotModified` instance.)r   )r   Úresponse_argsÚresponse_kwargss      r   Únot_modified_responsez#DownloadMixin.not_modified_response~   s   € ä&¨ÐI¸ÑIÐIr   c                 óZ  — |j                  d| j                  «       |j                  d| j                  «       |j                  d| j                  «       «       |j                  d| j	                  «       «       |j                  d| j                  «       «        | j                  |i |¤Ž}|S )z?Return :class:`~django_downloadview.response.DownloadResponse`.r$   Ú
attachmentr   Úfile_mimetypeÚfile_encoding)Ú
setdefaultr$   r-   r   r   r   Úresponse_class)r   r)   r*   Úresponses       r   Údownload_responsezDownloadMixin.download_response‚   s“   € à×"Ñ" ?°D×4FÑ4FÔGØ×"Ñ" <°·±ÔAØ×"Ñ" :¨t×/@Ñ/@Ó/BÔCØ×"Ñ" ?°D×4EÑ4EÓ4GÔHØ×"Ñ" ?°D×4EÑ4EÓ4GÔHØ&�4×&Ñ&¨ÐI¸ÑIˆØˆr   c                 ó   — t        «       ‚)zRaise Http404.)r   r   s    r   Úfile_not_found_responsez%DownloadMixin.file_not_found_responseŒ   s	   € ä‹iˆr   c                 óP  — 	 | j                  «       | _        | j
                  j                  j                  dd«      }|�.| j                  | j                  |«      s | j                  di |¤ŽS  | j                  |i |¤ŽS # t        j                  $ r | j	                  «       cY S w xY w)ap  Return "download" response (if everything is ok).

        Return :meth:`file_not_found_response` if file does not exist.

        Respects the "HTTP_IF_MODIFIED_SINCE" header if any. In that case, uses
        :py:meth:`was_modified_since` and :py:meth:`not_modified_response`.

        Else, uses :py:meth:`download_response` to return a download response.

        ÚHTTP_IF_MODIFIED_SINCEN© )r   r$   r   ÚFileNotFoundr5   ÚrequestÚMETAÚgetr   r+   r3   )r   r)   r*   r%   s       r   Úrender_to_responsez DownloadMixin.render_to_response�   s¤   € ð	2Ø!%§¡£ˆDÔð —‘×!Ñ!×%Ñ%Ð&>ÀÓEˆØÐØ×*Ñ*¨4×+=Ñ+=¸uÔEØ1�t×1Ñ1ÑD°OÑDÐDà%ˆt×%Ñ% }ÐH¸ÑHÐHøô ×&Ñ&ò 	2Ø×/Ñ/Ó1Ò1ð	2ús   ‚A? Á?#B%Â$B%)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r1   r-   r   r   r   r   r   r   r   r   r+   r3   r5   r=   r8   r   r   r
   r
      sZ   „ ñð  &€Nð$ €Jð €Hð
 €Hð
 €Hò$òòòòJò<JòòóIr   r
   c                   ó   — e Zd ZdZd„ Zy)ÚBaseDownloadViewz:A base :class:`DownloadMixin` that implements :meth:`get`.c                 ó"   — | j                  «       S )z#Handle GET requests: stream a file.)r=   )r   r:   ÚargsÚkwargss       r   r<   zBaseDownloadView.get«   s   € à×&Ñ&Ó(Ð(r   N)r>   r?   r@   rA   r<   r8   r   r   rC   rC   ¨   s
   „ ÙDó)r   rC   )rA   r   Údjango.httpr   r   Údjango.views.generic.baser   Údjango.views.staticr   Údjango_downloadviewr   Údjango_downloadview.responser   Úobjectr
   rC   r8   r   r   ú<module>rM      s;   ðñã ç 8Ý *Ý 2å *Ý 9ôXI�Fô XIôv)�} dõ )r   