B
    ©0H[x  ã               @   sd   d dl Z d dlmZmZ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)ÚFileProxyMixinc               @   sš   e Zd ZdZd!dd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zee
eƒ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 krt|dd ƒ}|| _t|dƒr2|j| _d S )NÚnameÚmode)ÚfileÚgetattrr   Úhasattrr   )Úselfr	   r   © r   úZC:\Users\HIRONO~1\AppData\Local\Temp\pip-install-6bm3nxem\django\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 )N)Úsize)r   r   r   r   Ú__len__   s    zFile.__len__c          	   C   s¢   t | jdƒr| jjS t | jdƒrJytj | jj¡S  ttfk
rH   Y nX 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   Ú_get_size_from_underlying_file   s    

z#File._get_size_from_underlying_filec             C   s    t | dƒr| jS |  ¡ | _| jS )NÚ_size)r   r%   r$   )r   r   r   r   Ú	_get_size.   s    

zFile._get_sizec             C   s
   || _ d S )N)r%   )r   r   r   r   r   Ú	_set_size4   s    zFile._set_sizec          	   c   sR   |s
| j }y|  d¡ W n ttfk
r0   Y nX x|  |¡}|sDP |V  q4W dS )zƒ
        Read the file and yield chunks of ``chunk_size`` bytes (defaults to
        ``UploadedFile.DEFAULT_CHUNK_SIZE``).
        r   N)ÚDEFAULT_CHUNK_SIZEr   r"   r   Úread)r   Ú
chunk_sizeÚdatar   r   r   Úchunks9   s    
zFile.chunksc             C   s   |s
| j }| 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_chunksL   s    zFile.multiple_chunksc             c   sx   d }x`|   ¡ D ]T}xN| d¡D ]@}|rJt|ƒr>t|ƒs>|V  n|| }d }t|ƒrZ|V  q|}qW qW |d k	rt|V  d S )NT)r,   Ú
splitlinesÚendswith_crÚ	equals_lfÚendswith_lf)r   Zbuffer_ÚchunkÚliner   r   r   Ú__iter__X   s    zFile.__iter__c             C   s   | S )Nr   )r   r   r   r   Ú	__enter__s   s    zFile.__enter__c             C   s   |   ¡  d S )N)Úclose)r   Úexc_typeÚ	exc_valueÚtbr   r   r   Ú__exit__v   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=   y   s    z	File.openc             C   s   | j  ¡  d S )N)r	   r6   )r   r   r   r   r6   ‚   s    z
File.close)N)N)N)N)r   Ú
__module__Ú__qualname__r(   r   r   r   r   r   r$   r&   r'   Úpropertyr   r,   r-   r4   r5   r:   r=   r6   r   r   r   r   r      s"   




	r   c                   sD   e Zd ZdZd‡ fdd„	Zdd„ Zdd„ Zdd	d
„Zdd„ Z‡  Z	S )ÚContentFilezT
    A File-like object that take just raw content, rather than an actual file.
    Nc                s4   t |tƒrtnt}tƒ j||ƒ|d� t|ƒ| _d S )N)r   )Ú
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 )NTr   )r   r   r   r   r   ’   s    zContentFile.__bool__c             C   s   |   d¡ | S )Nr   )r   )r   r   r   r   r   r=   •   s    
zContentFile.openc             C   s   d S )Nr   )r   r   r   r   r6   ™   s    zContentFile.close)N)N)
r   r?   r@   Ú__doc__r   r   r   r=   r6   Ú__classcell__r   r   )r   r   rB   †   s   
rB   c             C   s   |   t| tƒrdnd¡S )z:Return True if line (a text or byte string) ends with ''.úó   )ÚendswithrC   rD   )r3   r   r   r   r/   �   s    r/   c             C   s   |   t| tƒrdnd¡S )z:Return True if line (a text or byte string) ends with '
'.Ú
ó   
)rL   rC   rD   )r3   r   r   r   r1   ¢   s    r1   c             C   s   | t | tƒrdndkS )z7Return True if line (a text or byte string) equals '
'.rM   rN   )rC   rD   )r3   r   r   r   r0   §   s    r0   )r   Úior   r   r   Zdjango.core.files.utilsr   r   rB   r/   r1   r0   r   r   r   r   Ú<module>   s   