
 XU                 @   s   d  d l  m Z d  d l Z d  d l m Z m Z m Z d  d l m Z d  d l	 m
 Z
 d  d l m Z m Z m Z m Z e Gd d   d e   Z e Gd	 d
   d
 e   Z d d   Z d d   Z d d   Z d S)    )unicode_literalsN)BytesIOStringIOUnsupportedOperation)FileProxyMixin)six)force_bytes	force_strpython_2_unicode_compatible
smart_textc               @   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 d d   Z e e e  Z d d   Z 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))File@      
   Nc             C   sU   | |  _  | d  k r* t | d d   } n  | |  _ t | d  rQ | j |  _ n  d  S)Nnamemode)filegetattrr   hasattrr   )selfr   r    r   D/home/ubuntu/projects/ifolica/build/django/django/core/files/base.py__init__   s    		zFile.__init__c             C   s   t  |  j p d  S)N )r   r   )r   r   r   r   __str__   s    zFile.__str__c             C   s    t  d |  j j |  p d f  S)Nz<%s: %s>None)r	   	__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   t  |   j |   S)N)typer    )r   r   r   r   __nonzero__"   s    zFile.__nonzero__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  rf y t j j |  j j  SWqf t t f k
 rb Yqf Xn  t  |  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   _get_size_from_underlying_file(   s    
$z#File._get_size_from_underlying_filec             C   s,   t  |  d  r |  j S|  j   |  _ |  j S)N_size)r   r0   r/   )r   r   r   r   	_get_size8   s    zFile._get_sizec             C   s   | |  _  d  S)N)r0   )r   r#   r   r   r   	_set_size>   s    zFile._set_sizec             C   s   |  j  p |  j  j S)N)r   closed)r   r   r   r   _get_closedC   s    zFile._get_closedc             c   sg   | s |  j  } n  y |  j d  Wn t t f k
 r= Yn Xx" |  j |  } | sZ Pn  | VqA Wd 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   chunksG   s    zFile.chunksc             C   s   | s |  j  } n  |  j | k S)z
        Returns ``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.
        )r5   r#   )r   r7   r   r   r   multiple_chunksZ   s    zFile.multiple_chunksc             c   s   d  } x |  j    D]t } xk | j d  D]Z } | ri t |  rV t |  rV | Vn
 | | } d  } n  t |  r} | Vq) | } q) Wq W| d  k	 r | Vn  d  S)NT)r9   
splitlinesendswith_cr	equals_lfendswith_lf)r   Zbuffer_chunkliner   r   r   __iter__f   s    
	zFile.__iter__c             C   s   |  S)Nr   )r   r   r   r   	__enter__   s    zFile.__enter__c             C   s   |  j    d  S)N)close)r   exc_type	exc_valuetbr   r   r   __exit__   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   d  S)Nr   zThe file cannot be reopened.)
r3   r&   r   r'   r(   existsopenr   r   
ValueError)r   r   r   r   r   rI      s
    	!z	File.openc             C   s   |  j  j   d  S)N)r   rC   )r   r   r   r   rC      s    z
File.closei   i   )r   
__module____qualname__r5   r   r   r   r    r"   r$   r/   r1   r2   propertyr#   r4   r3   r9   r:   rA   rB   rG   rI   rC   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
   Z d d d  Z d d   Z	   S)ContentFilezU
    A File-like object that takes just raw content, rather than an actual file.
    Nc                sq   t  j r* t | t  j  r! t n t } n t } t |  } t t |   j	 | |  d | t
 |  |  _ d  S)Nr   )r   PY3
isinstance	text_typer   r   r   superrN   r   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   t  |   j |   S)N)r!   r    )r   r   r   r   r"      s    zContentFile.__nonzero__c             C   s   |  j  d  d  S)Nr   )r&   )r   r   r   r   r   rI      s    zContentFile.openc             C   s   d  S)Nr   )r   r   r   r   rC      s    zContentFile.close)
r   rK   rL   __doc__r   r   r    r"   rI   rC   r   r   )r   r   rN      s   	rN   c             C   s%   |  j  t |  t j  r d n d  S)zD
    Return True if line (a text or byte string) ends with ''.
    s   )endswithrP   r   rQ   )r@   r   r   r   r<      s    r<   c             C   s%   |  j  t |  t j  r d n d  S)zD
    Return True if line (a text or byte string) ends with '
'.
    
s   
)rW   rP   r   rQ   )r@   r   r   r   r>      s    r>   c             C   s"   |  t  |  t j  r d n d k S)zA
    Return True if line (a text or byte string) equals '
'.
    rX   s   
)rP   r   rQ   )r@   r   r   r   r=      s    r=   )
__future__r   r'   ior   r   r   Zdjango.core.files.utilsr   Zdjango.utilsr   Zdjango.utils.encodingr   r	   r
   r   r   rN   r<   r>   r=   r   r   r   r   <module>   s   "