Ë
    ¹2Úiù   ã                   óš   — d Z ddlZ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
mZ ddlmZ d„ Zd„ Zd	„ Z G d
„ de«      Z G d„ de
«      Zy)z0:py:class:`django.http.HttpResponse` subclasses.é    N)Úquote)Úsettings)ÚHttpResponseÚStreamingHttpResponse)Ú	force_strc                 óþ   — t        | t        «      r| j                  d«      } t        | «      }t	        j
                  d|«      }|j                  dd«      }|j                  d«      }t        j                  dd|«      }|S )um  Return US-ASCII encoded ``value`` for Content-Disposition header.

    >>> print(encode_basename_ascii(u'Ã©Ã '))
    ea

    Spaces are converted to underscores.

    >>> print(encode_basename_ascii(' '))
    _

    Of course, ASCII values are not modified.

    >>> print(encode_basename_ascii('ea'))
    ea
    >>> print(encode_basename_ascii(b'ea'))
    ea

    zutf-8ÚNFKDÚasciiÚignorez[\s]Ú_)	Ú
isinstanceÚbytesÚdecodeÚstrÚunicodedataÚ	normalizeÚencodeÚreÚsub)ÚvalueÚascii_basenames     úS/var/www/html/acx/venv/lib/python3.12/site-packages/django_downloadview/response.pyÚencode_basename_asciir      sq   € ô& �%œÔØ—‘˜WÓ%ˆÜ˜“Z€NÜ ×*Ñ*¨6°>ÓB€NØ#×*Ñ*¨7°HÓ=€NØ#×*Ñ*¨7Ó3€NÜ—V‘V˜G S¨.Ó9€NØÐó    c                 ó*   — t        t        | «      «      S )uÅ   Return UTF-8 encoded ``value`` for use in Content-Disposition header.

    >>> print(encode_basename_utf8(u' .txt'))
    %20.txt

    >>> print(encode_basename_utf8(u'Ã©Ã '))
    %C3%A9%C3%A0

    )r   r   )r   s    r   Úencode_basename_utf8r   *   s   € ô ”˜5Ó!Ó"Ð"r   c                 óZ   — | syt        | «      }t        | «      }||k(  rd|› d�S d|› d|› �S )uú  Return value of ``Content-Disposition`` header with 'attachment'.

    >>> print(content_disposition('demo.txt'))
    attachment; filename="demo.txt"

    If filename is empty, only "attachment" is returned.

    >>> print(content_disposition(''))
    attachment

    If filename contains non US-ASCII characters, the returned value contains
    UTF-8 encoded filename and US-ASCII fallback.

    >>> print(content_disposition(u'Ã©.txt'))
    attachment; filename="e.txt"; filename*=UTF-8''%C3%A9.txt

    Ú
attachmentzattachment; filename="ú"z"; filename*=UTF-8'')r   r   )ÚfilenameÚascii_filenameÚutf8_filenames      r   Úcontent_dispositionr#   7   sT   € ñ$ ØÜ*¨8Ó4€NÜ(¨Ó2€MØ˜Ò&Ø'¨Ð'7°qÐ9Ð9ð % ^Ð$4ð 5 Ø -˜ð0ð	
r   c                   óh   ‡ — e Zd ZdZ	 	 	 	 	 	 d
ˆ fd„	Zed„ «       Zˆ fd„Zd„ Zd„ Z	d„ Z
d„ Zd	„ Zˆ xZS )ÚDownloadResponsea>  File download response (Django serves file, client downloads it).

    This is a specialization of :class:`django.http.StreamingHttpResponse`
    where :attr:`~django.http.StreamingHttpResponse.streaming_content` is a
    file wrapper.

    Constructor differs a bit from :class:`~django.http.response.HttpResponse`.

    Here are some highlights to understand internal mechanisms and motivations:

    * Let's start by quoting :pep:`3333` (WSGI specification):

          For large files, or for specialized uses of HTTP streaming,
          applications will usually return an iterator (often a
          generator-iterator) that produces the output in a block-by-block
          fashion.

    * Django WSGI handler (application implementation) returns response object
      (see :mod:`django.core.handlers.wsgi`).

    * :class:`django.http.HttpResponse` and subclasses are iterators.

    * In :class:`~django.http.StreamingHttpResponse`, the
      :meth:`~container.__iter__` implementation proxies to
      :attr:`~django.http.StreamingHttpResponse.streaming_content`.

    * In :class:`DownloadResponse` and subclasses, :attr:`streaming_content`
      is a :doc:`file wrapper </files>`. File wrapper is itself an iterator
      over actual file content, and it also encapsulates access to file
      attributes (size, name, ...).

    c                 óî   •— || _         t        t        | �  | j                   ||¬«       || _        || _        |s| d= || _        || _        | j                  j                  «       D ]  \  }}	|| vsŒ|	| |<   Œ y)a=  Constructor.

        :param content_type: Value for ``Content-Type`` header.
                             If ``None``, then mime-type and encoding will be
                             populated by the response (default implementation
                             uses :mod:`mimetypes`, based on file name).

        )Ústreaming_contentÚstatusÚcontent_typeúContent-TypeN)
ÚfileÚsuperr%   Ú__init__Úbasenamer   Úfile_mimetypeÚfile_encodingÚdefault_headersÚitems)ÚselfÚfile_instancer   r.   r(   r)   r/   r0   Úheaderr   Ú	__class__s             €r   r-   zDownloadResponse.__init__x   s’   ø€ ð( "ˆŒ	ÜÔ Ñ.Ø"Ÿi™i°À\ð 	/ô 	
ð !ˆŒð %ˆŒÙØ�^Ð$ð
 +ˆÔð
 +ˆÔð "×1Ñ1×7Ñ7Ó9ò 	%‰MˆF�EØ˜TÒ!Ø$��V’ñ	%r   c                 ó>  — 	 | j                   S # t        $ r… i }| j                  «       |d<   	 | j                  j                  |d<   n# t        t
        f$ r Y nw xY w| j                  r| j                  «       }t        |«      |d<   || _         | j                   cY S w xY w)am  Return dictionary of automatically-computed headers.

        Uses an internal ``_default_headers`` cache.
        Default values are computed if only cache hasn't been set.

        ``Content-Disposition`` header is encoded according to `RFC 5987
        <http://tools.ietf.org/html/rfc5987>`_. See also
        http://stackoverflow.com/questions/93551/.

        r*   zContent-LengthzContent-Disposition)	Ú_default_headersÚAttributeErrorÚget_content_typer+   ÚsizeÚNotImplementedErrorr   Úget_basenamer#   )r3   Úheadersr.   s      r   r1   z DownloadResponse.default_headers«   s£   € ð	)Ø×(Ñ(Ð(øÜò 	)ØˆGØ&*×&;Ñ&;Ó&=ˆG�NÑ#ðØ,0¯I©I¯N©N�Ð(Ò)øÜ"Ô$7Ð8ò Ùðúà�ŠØ×,Ñ,Ó.�Ü1DÀXÓ1N�Ð-Ñ.Ø$+ˆDÔ!Ø×(Ñ(Ò(ð	)ús3   ‚ ŽB­AÁBÁAÁBÁAÁA BÂBc                 ó(   •— t         t        | �  «       S )zÕReturn iterable of (header, value).

        This method is called by http handlers just before WSGI's
        start_response() is called... but it is not called by
        django.test.ClientHandler! :'(

        )r,   r%   r2   )r3   r6   s    €r   r2   zDownloadResponse.itemsÆ   s   ø€ ô Ô% tÑ2Ó4Ð4r   c                 ó˜   — | j                   r| j                   S t        j                  j                  | j                  j                  «      S )zReturn basename.)r.   ÚosÚpathr+   Úname©r3   s    r   r=   zDownloadResponse.get_basenameÐ   s0   € à�=Š=Ø—=‘=Ð ä—7‘7×#Ñ# D§I¡I§N¡NÓ3Ð3r   c                 ó”   — 	 | j                   j                  S # t        $ r& | j                  «       › d| j	                  «       › �cY S w xY w)z:Return a suitable "Content-Type" header for ``self.file``.z
; charset=)r+   r)   r9   Úget_mime_typeÚget_charsetrD   s    r   r:   z!DownloadResponse.get_content_type×   sN   € ð	KØ—9‘9×)Ñ)Ð)øÜò 	KØ×(Ñ(Ó*Ð+¨:°d×6FÑ6FÓ6HÐ5IÐJÒJð	Kús   ‚ ˜,AÁAc                 ó’   — | j                   �| j                   S d}| j                  «       }t        j                  |«      \  }}|xs |S )zReturn mime-type of the file.zapplication/octet-stream)r/   r=   Ú	mimetypesÚ
guess_type)r3   Údefault_mime_typer.   Ú	mime_typeÚencodings        r   rF   zDownloadResponse.get_mime_typeÞ   sO   € à×ÑÐ)Ø×%Ñ%Ð%Ø6ÐØ×$Ñ$Ó&ˆÜ'×2Ñ2°8Ó<Ñˆ	�8ØÒ-Ð-Ð-r   c                 ó†   — | j                   �| j                   S | j                  «       }t        j                  |«      \  }}|S )z%Return encoding of the file to serve.)r0   r=   rI   rJ   )r3   r.   rL   rM   s       r   Úget_encodingzDownloadResponse.get_encodingç   sB   € à×ÑÐ)Ø×%Ñ%Ð%Ø×$Ñ$Ó&ˆÜ'×2Ñ2°8Ó<Ñˆ	�8Øˆr   c                 ó"   — t         j                  S )z(Return the charset of the file to serve.)r   ÚDEFAULT_CHARSETrD   s    r   rG   zDownloadResponse.get_charsetï   s   € ä×'Ñ'Ð'r   )TNéÈ   NNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r-   Úpropertyr1   r2   r=   r:   rF   rO   rG   Ú__classcell__)r6   s   @r   r%   r%   V   sV   ø„ ñðH ØØØØØõ1%ðf ñ)ó ð)ô45ò4òKò.òö(r   r%   c                   ó   — e Zd ZdZy)ÚProxiedDownloadResponsezéBase class for internal redirect download responses.

    This base class makes it possible to identify several types of specific
    responses such as
    :py:class:`~django_downloadview.nginx.response.XAccelRedirectResponse`.

    N)rS   rT   rU   rV   © r   r   rZ   rZ   ô   s   „ òr   rZ   )rV   rI   rA   r   r   Úurllib.parser   Údjango.confr   Údjango.httpr   r   Údjango.utils.encodingr   r   r   r#   r%   rZ   r[   r   r   ú<module>r`      sK   ðÙ 6Û Û 	Û 	Û Ý å  ß ;Ý +òò:
#ò
ô>[(Ð,ô [(ô|˜lõ r   