a
    LcòfË  ã                   @   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   s6   || _ |d u rt|dd ƒ}|| _t|dƒr2|j| _d S )NÚnameÚmode)ÚfileÚgetattrr   Úhasattrr	   )Úselfr
   r   © r   úS/home/httpd/docs/test/DocsMgr/lib/python3.9/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__   s    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__   s    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ƒrJztj | jj¡W S  ttfyH   Y n0 t | jdƒr–t | jdƒr–| j 	¡ }| j 
dtj¡ | j 	¡ }| j 
|¡ |S tdƒ‚d S )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   sL   |p| j }z|  d¡ W n ttfy.   Y n0 |  |¡}|s@qH|V  q0dS )z{
        Read the file and yield chunks of ``chunk_size`` bytes (defaults to
        ``File.DEFAULT_CHUNK_SIZE``).
        r   N)Ú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   sp   d }|   ¡ D ]P}| d¡D ]@}|rFt|ƒr:t|ƒs:|V  n|| }d }t|ƒrV|V  q|}qq|d url|V  d S ©NT)r,   Ú
splitlinesÚendswith_crÚ	equals_lfÚendswith_lf)r   Zbuffer_ÚchunkÚliner   r   r   Ú__iter__K   s    zFile.__iter__c                 C   s   | S r   r   r   r   r   r   Ú	__enter__f   s    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¡ n2| jr<tj | j¡r<t| j|p4| jƒ| _nt	dƒ‚| S )Nr   zThe file cannot be reopened.)
Úclosedr   r   r    r!   ÚexistsÚopenr	   r
   Ú
ValueError©r   r	   r   r   r   r>   l   s    z	File.openc                 C   s   | j  ¡  d S r   )r
   r7   r   r   r   r   r7   u   s    z
File.close)N)N)N)N)r   Ú
__module__Ú__qualname__r(   r   r   r   r   r   r   r   r,   r-   r5   r6   r;   r>   r7   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   Zstream_class©r   r   r   r   ~   s    zContentFile.__init__c                 C   s   dS )NzRaw contentr   r   r   r   r   r   ƒ   s    zContentFile.__str__c                 C   s   dS r.   r   r   r   r   r   r   †   s    zContentFile.__bool__c                 C   s   |   d¡ | S )Nr   )r   r@   r   r   r   r>   ‰   s    
zContentFile.openc                 C   s   d S r   r   r   r   r   r   r7   �   s    zContentFile.closec                 C   s   | j  dd ¡ | j |¡S )Nr   )Ú__dict__Úpopr
   Úwrite)r   r+   r   r   r   rL   �   s    zContentFile.write)N)N)r   rA   rB   Ú__doc__r   r   r   r>   r7   rL   Ú__classcell__r   r   rI   r   rC   y   s   
rC   c                 C   s   |   t| tƒrdnd¡S )z9Return True if line (a text or bytestring) ends with ''.úó   ©ÚendswithrD   rE   ©r4   r   r   r   r0   •   s    r0   c                 C   s   |   t| tƒrdnd¡S )z9Return True if line (a text or bytestring) ends with '
'.Ú
ó   
rQ   rS   r   r   r   r2   š   s    r2   c                 C   s   | t | tƒrdndkS )z6Return True if line (a text or bytestring) equals '
'.rT   rU   )rD   rE   rS   r   r   r   r1   Ÿ   s    r1   )r    Úior   r   r   Zdjango.core.files.utilsr   Zdjango.utils.functionalr   r   rC   r0   r2   r1   r   r   r   r   Ú<module>   s   q