
v^                 @   s   d  d l  Z  d  d l m Z m Z m Z d  d l m Z d  d l m Z Gd d   d e  Z	 Gd 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   sO   | |  _  | d  k r' t | d d   } | |  _ t | d  rK | j |  _ d  S)Nnamemode)filegetattrr   hasattrr   )selfr   r    r   8/tmp/pip-build-8lau8j11/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 St  |  j d  rc y t j j |  j j  SWn t t f k
 rb Yn Xt  |  j d  r t  |  j d  r |  j j	   } |  j j
 d t j  |  j j	   } |  j j
 |  | St 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   sa   | p |  j  } y |  j d  Wn t t f k
 r: Yn Xx |  j |  } | sT P| Vq> Wd 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   s   d  } x |  j    D]q } xh | j d  D]W } | rf t |  rV t |  rV | Vn
 | | } d  } t |  rz | Vq) | } q) Wq W| d  k	 r | 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  nK |  j rX t j j |  j  rX t |  j | pL |  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   )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                   sj   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	   S)ContentFilezU
    A File-like object that takes just raw content, rather than an actual file.
    Nc                sJ   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)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)
r   r?   r@   __doc__r   r   r   r=   r6   rI   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 ''.s   )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 '
'.
s   
)rL   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 '
'.rM   s   
)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