Ë
    ¹2Úi–  ã                   óŽ   — d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlZ G d„ d	e«      Z G d
„ de«      Z G d„ de«      Zy)zCFile wrappers for use as exchange data between views and responses.é    )ÚBytesIO)Úurlparse)ÚFile)Úforce_bytes)ÚBytesIteratorIONc                   ó¸   — e Zd ZdZdd„Zd„ Zd„ Zd„ Z eeee«      Z	dd„Z
d„ Zed	„ «       Zd
„ Zd„ Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zy)ÚStorageFilez–A file in a Django storage.

    This class looks like :py:class:`django.db.models.fields.files.FieldFile`,
    but unrelated to model instance.

    Nc                 ó.   — || _         || _        || _        y)zÄConstructor.

        storage:
          Some :py:class:`django.core.files.storage.Storage` instance.

        name:
          File identifier in storage, usually a filename as a string.

        N)ÚstorageÚnameÚfile)Úselfr   r   r   s       úP/var/www/html/acx/venv/lib/python3.12/site-packages/django_downloadview/files.pyÚ__init__zStorageFile.__init__   s   € ð ˆŒØˆŒ	Øˆ�	ó    c                 ó    — t        | d«      r| j                  €+| j                  j                  | j                  d«      | _        | j                  S )z&Getter for :py:attr:``file`` property.Ú_fileÚrb)Úhasattrr   r   Úopenr   ©r   s    r   Ú	_get_filezStorageFile._get_file#   s;   € ä�t˜WÔ%¨¯©Ð);ØŸ™×*Ñ*¨4¯9©9°dÓ;ˆDŒJØ�z‰zÐr   c                 ó   — || _         y)z&Setter for :py:attr:``file`` property.N©r   )r   r   s     r   Ú	_set_filezStorageFile._set_file)   s	   € àˆ�
r   c                 ó   — | ` y)z'Deleter for :py:attr:``file`` property.Nr   r   s    r   Ú	_del_filezStorageFile._del_file-   s   € à‰Jr   c                 óN   — | j                   j                  | j                  |«      S )zƒRetrieves the specified file from storage and return open() result.

        Proxy to self.storage.open(self.name, mode).

        )r   r   r   )r   Úmodes     r   r   zStorageFile.open4   s   € ð �|‰|× Ñ  §¡¨DÓ1Ð1r   c                 óN   — | j                   j                  | j                  |«      S )zºSaves new content to the file.

        Proxy to self.storage.save(self.name).

        The content should be a proper File object, ready to be read from the
        beginning.

        )r   Úsaver   ©r   Úcontents     r   r!   zStorageFile.save<   s   € ð �|‰|× Ñ  §¡¨GÓ4Ð4r   c                 óL   — | j                   j                  | j                  «      S )zóReturn a local filesystem path which is suitable for open().

        Proxy to self.storage.path(self.name).

        May raise NotImplementedError if storage doesn't support file access
        with Python's built-in open() function

        )r   Úpathr   r   s    r   r%   zStorageFile.pathG   s   € ð �|‰|× Ñ  §¡Ó+Ð+r   c                 óL   — | j                   j                  | j                  «      S )znDelete the specified file from the storage system.

        Proxy to self.storage.delete(self.name).

        )r   Údeleter   r   s    r   r'   zStorageFile.deleteS   ó   € ð �|‰|×"Ñ" 4§9¡9Ó-Ð-r   c                 óL   — | j                   j                  | j                  «      S )z�Return True if file already exists in the storage system.

        If False, then the name is available for a new file.

        )r   Úexistsr   r   s    r   r*   zStorageFile.exists[   r(   r   c                 óL   — | j                   j                  | j                  «      S )zgReturn the total size, in bytes, of the file.

        Proxy to self.storage.size(self.name).

        )r   Úsizer   r   s    r   r,   zStorageFile.sizec   s   € ð �|‰|× Ñ  §¡Ó+Ð+r   c                 óL   — | j                   j                  | j                  «      S )zzReturn an absolute URL where the file's contents can be accessed.

        Proxy to self.storage.url(self.name).

        )r   Úurlr   r   s    r   r.   zStorageFile.urll   s   € ð �|‰|×Ñ §	¡	Ó*Ð*r   c                 ó¶   — 	 | j                   j                  | j                  «      S # t        $ r( | j                   j	                  | j                  «      cY S w xY w)z‚Return the last accessed time (as datetime object) of the file.

        Proxy to self.storage.accessed_time(self.name).

        )r   Úget_accessed_timer   ÚAttributeErrorÚaccessed_timer   s    r   r2   zStorageFile.accessed_timeu   óH   € ð	9Ø—<‘<×1Ñ1°$·)±)Ó<Ð<øÜò 	9Ø—<‘<×-Ñ-¨d¯i©iÓ8Ò8ð	9úó   ‚$' §.AÁAc                 ó¶   — 	 | j                   j                  | j                  «      S # t        $ r( | j                   j	                  | j                  «      cY S w xY w)z|Return the creation time (as datetime object) of the file.

        Proxy to self.storage.created_time(self.name).

        )r   Úget_created_timer   r1   Úcreated_timer   s    r   r7   zStorageFile.created_time�   sH   € ð	8Ø—<‘<×0Ñ0°·±Ó;Ð;øÜò 	8Ø—<‘<×,Ñ,¨T¯Y©YÓ7Ò7ð	8úr4   c                 ó¶   — 	 | j                   j                  | j                  «      S # t        $ r( | j                   j	                  | j                  «      cY S w xY w)z†Return the last modification time (as datetime object) of the file.

        Proxy to self.storage.modified_time(self.name).

        )r   Úget_modified_timer   r1   Úmodified_timer   s    r   r:   zStorageFile.modified_time�   r3   r4   ©N)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   Úpropertyr   r   r!   r%   r'   r*   r,   r.   r2   r7   r:   © r   r   r	   r	      s·   „ ñóòòòñ
 �I˜y¨)Ó4€Dó2ò	5ð ñ	,ó ð	,ò.ò.ð ñ,ó ð,ð ñ+ó ð+ð ñ	9ó ð	9ð ñ	8ó ð	8ð ñ	9ó ñ	9r   r	   c                   óL   ‡ — e Zd ZdZdˆ fd„	Zd„ Zˆ fd„Z eee«      Zd„ Z	ˆ xZ
S )ÚVirtualFilez&Wrapper for files that live in memory.c                 óP   •— t         t        | �  ||«       || _        |�|| _        yy)z Constructor.

        file:
          File object. Typically an io.StringIO.

        name:
          File basename.

        url:
          File URL.

        N)ÚsuperrC   r   r.   Ú_size)r   r   r   r.   r,   Ú	__class__s        €r   r   zVirtualFile.__init__�   s/   ø€ ô 	Œk˜4Ñ)¨$°Ô5ØˆŒØÐØˆD�Jð r   c                 óø   — 	 | j                   S # t        $ rb 	 | j                  j                  | _         n7# t        $ r+ t	        | j                  j                  «       «      | _         Y nw xY wY | j                   S w xY wr;   )rF   r1   r   r,   ÚlenÚgetvaluer   s    r   Ú	_get_sizezVirtualFile._get_size¯   sf   € ð	7Ø—:‘:ÐøÜò 	7ð7Ø!ŸY™YŸ^™^�•
øÜ!ò 7Ü  §¡×!3Ñ!3Ó!5Ó6�–
ð7ûà�z‰zÐð	7ús/   ‚ Ž	A9˜4³A9´1A(Á%A9Á'A(Á(A9Á8A9c                 ó*   •— t         t        | �  |«      S r;   )rE   rC   Ú	_set_size)r   ÚvaluerG   s     €r   rM   zVirtualFile._set_size¹   s   ø€ Ü”[ $Ñ1°%Ó8Ð8r   c              #   ó¬   K  — d}| j                  «       D ]4  }t        t        |«      «      }|D ]  }|r||z   }d}|d   dv r|–— Œ|}Œ Œ6 |�|–— yy­w)z{Same as ``File.__iter__()`` but using ``force_bytes()``.

        See https://code.djangoproject.com/ticket/21321

        Néÿÿÿÿ)ú
ú)Úchunksr   r   )r   Úbuffer_ÚchunkÚchunk_bufferÚlines        r   Ú__iter__zVirtualFile.__iter__¾   s{   è ø€ ð ˆØ—[‘[“]ò 	#ˆEÜ"¤;¨uÓ#5Ó6ˆLà$ò 
#�ÙØ" T™>�DØ"�Gð ˜‘8˜|Ñ+Ø“Jà"‘Gñ
#ð	#ð ÐØ‹Mð ùs   ‚AA)NÚ rY   N)r<   r=   r>   r?   r   rK   rM   r@   r,   rX   Ú__classcell__)rG   s   @r   rC   rC   š   s(   ø„ Ù0õò$ô9ñ �I˜yÓ)€Dör   rC   c                   ór   — e Zd ZdZej
                  ddfd„Zed„ «       Zed„ «       Z	ed„ «       Z
ed„ «       Zy)	ÚHTTPFilez³Wrapper for files that live on remote HTTP servers.

    Acts as a proxy.

    Uses https://pypi.python.org/pypi/requests.

    Always sets "stream=True" in requests kwargs.

    rY   c                 ó  — || _         || _        |€]t        |«      }|j                  r4|j                  j	                  d«      j                  dd«      d   | _        n|j                  | _        n|| _        d|d<   || _        y )Nú/é   rP   TÚstream)	Úrequest_factoryr.   r   r%   ÚstripÚrsplitr   ÚnetlocÚrequest_kwargs)r   ra   r.   r   ÚkwargsÚpartss         r   r   zHTTPFile.__init__ä   sr   € Ø.ˆÔØˆŒØˆ<Ü˜S“MˆEØ�zŠzØ!ŸJ™J×,Ñ,¨SÓ1×8Ñ8¸¸aÓ@ÀÑD�•	à!ŸL™L�•	àˆDŒIØˆˆxÑØ$ˆÕr   c                 óª   — 	 | j                   S # t        $ r;  | j                  | j                  fi | j                  ¤Ž| _         | j                   cY S w xY wr;   )Ú_requestr1   ra   r.   re   r   s    r   ÚrequestzHTTPFile.requestò   sM   € ð	!Ø—=‘=Ð øÜò 	!Ø0˜D×0Ñ0°·±ÑQ¸T×=PÑ=PÑQˆDŒMØ—=‘=Ò ð	!úó   ‚ ŽAAÁAc                 óª   — 	 | j                   S # t        $ r; | j                  j                  d¬«      }t	        |«      | _         | j                   cY S w xY w)NF)Údecode_unicode)r   r1   rj   Úiter_contentr   r"   s     r   r   zHTTPFile.fileú   sM   € ð	Ø—:‘:ÐøÜò 	Ø—l‘l×/Ñ/¸uÐ/ÓEˆGÜ(¨Ó1ˆDŒJØ—:‘:Òð	úrk   c                 ó4   — | j                   j                  d   S )zjReturn the total size, in bytes, of the file.

        Reads response's "content-length" header.

        zContent-Length©rj   Úheadersr   s    r   r,   zHTTPFile.size  s   € ð �|‰|×#Ñ#Ð$4Ñ5Ð5r   c                 ó4   — | j                   j                  d   S )z9Return content type of the file (from original response).zContent-Typerp   r   s    r   Úcontent_typezHTTPFile.content_type  s   € ð �|‰|×#Ñ# NÑ3Ð3r   N)r<   r=   r>   r?   ÚrequestsÚgetr   r@   rj   r   r,   rs   rA   r   r   r\   r\   Ù   si   „ ñð (0§|¡|¸À"ó %ð ñ!ó ð!ð ñó ðð ñ6ó ð6ð ñ4ó ñ4r   r\   )r?   Úior   Úurllib.parser   Údjango.core.files.baser   Údjango.utils.encodingr   Údjango_downloadview.ior   rt   r	   rC   r\   rA   r   r   ú<module>r{      sB   ðÙ IÝ Ý !å 'Ý -å 2ã ôJ9�$ô J9ôZ<�$ô <ô~64ˆtõ 64r   