3
ªôÁgÌ  ã               @   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 )%ÚFileé@   é   é
   Nc             C   s6   || _ |d krt|dd ƒ}|| _t|dƒr2|j| _d S )NÚnameÚmode)ÚfileÚgetattrr   Úhasattrr   )Úselfr   r   © r   úT/var/www/tester-filtro-web/env/lib/python3.6/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 )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jƒS  ttfk
rH   Y nX t | jdƒr–t | jdƒr–| jj	ƒ }| jj
dtjƒ | j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   sR   |p| j }y| jdƒ W n ttfk
r0   Y nX x| j|ƒ}|sDP |V  q4W d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   sz   d }xb| j ƒ D ]V}xP|jdƒD ]B}|rLt|ƒr@t|ƒ r@|V  n|| }d }t|ƒr\|V  q|}qW qW |d k	rv|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 )Nr   )r   r   r   r   Ú	__enter__f   s    zFile.__enter__c             C   s   | j ƒ  d S )N)Úclose)r   Úexc_typeÚ	exc_valueÚtbr   r   r   Ú__exit__i   s    zFile.__exit__c             C   sH   | j s| jdƒ n2| jr<tj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 jƒ  d S )N)r   r6   )r   r   r   r   r6   u   s    z
File.closei   i   )N)N)N)N)r   Ú
__module__Ú__qualname__r(   r   r   r   r   r   r   r   r,   r-   r4   r5   r:   r=   r6   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 )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   | j 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.closec             C   s   | j jdd ƒ | jj|ƒS )Nr   )Ú__dict__Úpopr   Úwrite)r   r+   r   r   r   rI      s    zContentFile.write)N)N)r   r?   r@   Ú__doc__r   r   r   r=   r6   rI   Ú__classcell__r   r   )r   r   rA   y   s   
rA   c             C   s   | j t| tƒrdndƒS )z9Return True if line (a text or bytestring) ends with ''.úó   )ÚendswithrB   rC   )r3   r   r   r   r/   ”   s    r/   c             C   s   | j t| tƒrdndƒS )z9Return True if line (a text or bytestring) ends with '
'.Ú
ó   
)rN   rB   rC   )r3   r   r   r   r1   ™   s    r1   c             C   s   | t | tƒrdndkS )z6Return True if line (a text or bytestring) equals '
'.rO   rP   )rB   rC   )r3   r   r   r   r0   ž   s    r0   )r    Úior   r   r   Zdjango.core.files.utilsr   Zdjango.utils.functionalr   r   rA   r/   r1   r0   r   r   r   r   Ú<module>   s   q