o
    ˜¨ÊhË  ã                   @   sp   d dl Z d dlmZmZmZ d dlmZ d dlmZ G dd„ deƒZ	G dd„ de	ƒZ
d	d
„ Zdd„ Zdd„ ZdS )é    N)ÚBytesIOÚStringIOÚUnsupportedOperation)ÚFileProxyMixin)Úcached_propertyc                   @   s„   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zdd„ Ze	dd„ ƒZ
ddd„Zddd„Zdd„ Zdd„ Zdd„ Zddd„Zdd„ ZdS )ÚFilei   Nc                 C   s:   || _ |d u rt|dd ƒ}|| _t|dƒr|j| _d S d S )NÚnameÚmode)ÚfileÚgetattrr   Úhasattrr	   )Úselfr
   r   © r   úH/var/www/html/env/lib/python3.10/site-packages/django/core/files/base.pyÚ__init__   s   
ÿzFile.__init__c                 C   s
   | j pdS )NÚ ©r   ©r   r   r   r   Ú__str__   ó   
zFile.__str__c                 C   s   d| j j| pdf S )Nz<%s: %s>ÚNone)Ú	__class__Ú__name__r   r   r   r   Ú__repr__   s   zFile.__repr__c                 C   s
   t | jƒS ©N)Úboolr   r   r   r   r   Ú__bool__   r   zFile.__bool__c                 C   s   | j S r   )Úsizer   r   r   r   Ú__len__   s   zFile.__len__c              	   C   sž   t | jdƒr
| jjS t | jdƒr%z	tj | jj¡W S  ttfy$   Y nw t | jdƒrKt | jdƒrK| j 	¡ }| j 
dtj¡ | j 	¡ }| j 
|¡ |S tdƒ‚)Nr   r   ÚtellÚseekr   z$Unable to determine the file's size.)r   r
   r   ÚosÚpathÚgetsizer   ÚOSErrorÚ	TypeErrorr   r    ÚSEEK_ENDÚAttributeError)r   Úposr   r   r   r   r      s   ÿ

z	File.sizec              	   c   sN   � |p| j }z|  d¡ W n ttfy   Y nw 	 |  |¡}|s#dS |V  q)z{
        Read the file and yield chunks of ``chunk_size`` bytes (defaults to
        ``File.DEFAULT_CHUNK_SIZE``).
        r   TN)ÚDEFAULT_CHUNK_SIZEr    r'   r   Úread)r   Ú
chunk_sizeÚdatar   r   r   Úchunks0   s   €
ÿ
üzFile.chunksc                 C   s   | j |p| jkS )zö
        Return ``True`` if you can expect multiple chunks.

        NB: If a particular file representation is in memory, subclasses should
        always return ``False`` -- there's no good reason to read from memory in
        chunks.
        )r   r)   )r   r+   r   r   r   Úmultiple_chunksA   s   zFile.multiple_chunksc                 c   sv   � d }|   ¡ D ](}| d¡D ] }|r$t|ƒrt|ƒs|V  n|| }d }t|ƒr,|V  q|}qq|d ur9|V  d S d S ©NT)r-   Ú
splitlinesÚendswith_crÚ	equals_lfÚendswith_lf)r   Úbuffer_ÚchunkÚliner   r   r   Ú__iter__K   s    €î
ÿzFile.__iter__c                 C   s   | S r   r   r   r   r   r   Ú	__enter__f   ó   zFile.__enter__c                 C   s   |   ¡  d S r   )Úclose)r   Úexc_typeÚ	exc_valueÚtbr   r   r   Ú__exit__i   s   zFile.__exit__c                 C   sH   | j s
|  d¡ | S | jr tj | j¡r t| j|p| jƒ| _| S t	dƒ‚)Nr   zThe file cannot be reopened.)
Úclosedr    r   r!   r"   ÚexistsÚopenr	   r
   Ú
ValueError©r   r	   r   r   r   rA   l   s   
üÿz	File.openc                 C   s   | j  ¡  d S r   )r
   r:   r   r   r   r   r:   u   s   z
File.closer   )r   Ú
__module__Ú__qualname__r)   r   r   r   r   r   r   r   r-   r.   r7   r8   r>   rA   r:   r   r   r   r   r      s     





	r   c                       sL   e Zd ZdZd‡ fdd„	Zdd„ Zdd„ Zdd	d
„Zdd„ Zdd„ Z	‡  Z
S )ÚContentFilezU
    A File-like object that takes just raw content, rather than an actual file.
    Nc                    s4   t |tƒrtnt}tƒ j||ƒ|d� t|ƒ| _d S )Nr   )Ú
isinstanceÚstrr   r   Úsuperr   Úlenr   )r   Úcontentr   Ústream_class©r   r   r   r   ~   s   zContentFile.__init__c                 C   ó   dS )NzRaw contentr   r   r   r   r   r   ƒ   r9   zContentFile.__str__c                 C   rN   r/   r   r   r   r   r   r   †   r9   zContentFile.__bool__c                 C   s   |   d¡ | S )Nr   )r    rC   r   r   r   rA   ‰   s   
zContentFile.openc                 C   s   d S r   r   r   r   r   r   r:   �   r9   zContentFile.closec                 C   s   | j  dd ¡ | j |¡S )Nr   )Ú__dict__Úpopr
   Úwrite)r   r,   r   r   r   rQ   �   s   zContentFile.writer   )r   rD   rE   Ú__doc__r   r   r   rA   r:   rQ   Ú__classcell__r   r   rM   r   rF   y   s    
rF   c                 C   ó   |   t| tƒr
d¡S d¡S )z9Return True if line (a text or bytestring) ends with ''.úó   ©ÚendswithrG   rH   ©r6   r   r   r   r1   •   ó   r1   c                 C   rT   )z9Return True if line (a text or bytestring) ends with '
'.Ú
ó   
rW   rY   r   r   r   r3   š   rZ   r3   c                 C   s   | t | tƒr	dkS dkS )z6Return True if line (a text or bytestring) equals '
'.r[   r\   )rG   rH   rY   r   r   r   r2   Ÿ   s   r2   )r!   Úior   r   r   Údjango.core.files.utilsr   Údjango.utils.functionalr   r   rF   r1   r3   r2   r   r   r   r   Ú<module>   s    q