ó
TR¹Nc           @   sš   d  d l  Z  y d  d l m Z Wn! e k
 rC d  d l m Z n Xd  d l m Z m Z d  d l m Z d e f d „  ƒ  YZ	 d e	 f d „  ƒ  YZ
 d S(	   iÿÿÿÿN(   t   StringIO(   t	   smart_strt   smart_unicode(   t   FileProxyMixint   Filec           B   s·   e  Z d  d Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d	 „  Z
 d
 „  Z e e
 e ƒ Z d „  Z e e ƒ Z d d „ Z d d „ Z d „  Z d d „ Z d „  Z RS(   i@   i   i
   c         C   sL   | |  _  | d  k r* t | d d  ƒ } n  | |  _ t | d d  ƒ |  _ d  S(   Nt   namet   mode(   t   filet   Nonet   getattrR   R   (   t   selfR   R   (    (    sC   /home/panlixing/Python_Projects/gaeseries/django/core/files/base.pyt   __init__   s
    		c         C   s   t  |  j p d ƒ S(   Nt    (   R   R   (   R
   (    (    sC   /home/panlixing/Python_Projects/gaeseries/django/core/files/base.pyt   __str__   s    c         C   s   t  |  j p d ƒ S(   Nu    (   R   R   (   R
   (    (    sC   /home/panlixing/Python_Projects/gaeseries/django/core/files/base.pyt   __unicode__   s    c         C   s   d |  j  j |  p d f S(   Ns   <%s: %s>R   (   t	   __class__t   __name__(   R
   (    (    sC   /home/panlixing/Python_Projects/gaeseries/django/core/files/base.pyt   __repr__   s    c         C   s   t  |  j ƒ S(   N(   t   boolR   (   R
   (    (    sC   /home/panlixing/Python_Projects/gaeseries/django/core/files/base.pyt   __nonzero__   s    c         C   s   |  j  S(   N(   t   size(   R
   (    (    sC   /home/panlixing/Python_Projects/gaeseries/django/core/files/base.pyt   __len__    s    c         C   s   t  |  d ƒ sx t  |  j d ƒ r3 |  j j |  _ qx t j j |  j j ƒ ri t j j |  j j ƒ |  _ qx t	 d ƒ ‚ n  |  j S(   Nt   _sizeR   s$   Unable to determine the file's size.(
   t   hasattrR   R   R   t   ost   patht   existsR   t   getsizet   AttributeError(   R
   (    (    sC   /home/panlixing/Python_Projects/gaeseries/django/core/files/base.pyt	   _get_size#   s    c         C   s   | |  _  d  S(   N(   R   (   R
   R   (    (    sC   /home/panlixing/Python_Projects/gaeseries/django/core/files/base.pyt	   _set_size-   s    c         C   s   |  j  p |  j  j S(   N(   R   t   closed(   R
   (    (    sC   /home/panlixing/Python_Projects/gaeseries/django/core/files/base.pyt   _get_closed2   s    c         c   si   | s |  j  } n  t |  d ƒ r1 |  j d ƒ n  |  j } x( | d k rd |  j | ƒ V| | 8} q= Wd S(   sƒ   
        Read the file and yield chucks of ``chunk_size`` bytes (defaults to
        ``UploadedFile.DEFAULT_CHUNK_SIZE``).
        t   seeki    N(   t   DEFAULT_CHUNK_SIZER   R!   R   t   read(   R
   t
   chunk_sizet   counter(    (    sC   /home/panlixing/Python_Projects/gaeseries/django/core/files/base.pyt   chunks6   s    	c         C   s   | s |  j  } n  |  j | k S(   s÷   
        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.
        (   R"   R   (   R
   R$   (    (    sC   /home/panlixing/Python_Projects/gaeseries/django/core/files/base.pyt   multiple_chunksG   s    c         c   s‰   d  } xh |  j ƒ  D]Z } t | ƒ } xE | D]= } | rK | | } d  } n  | d d k rc | Vq, | } q, Wq W| d  k	 r… | Vn  d  S(   Niÿÿÿÿs   
s   (   s   
s   (   R   R&   R    (   R
   t   buffer_t   chunkt   chunk_buffert   line(    (    sC   /home/panlixing/Python_Projects/gaeseries/django/core/files/base.pyt   __iter__S   s    
	c         C   sh   |  j  s |  j d ƒ nK |  j rX t j j |  j ƒ rX t |  j | pL |  j ƒ |  _ n t	 d ƒ ‚ d  S(   Ni    s   The file cannot be reopened.(
   R   R!   R   R   R   R   t   openR   R   t
   ValueError(   R
   R   (    (    sC   /home/panlixing/Python_Projects/gaeseries/django/core/files/base.pyR-   h   s
    	!c         C   s   |  j  j ƒ  d  S(   N(   R   t   close(   R
   (    (    sC   /home/panlixing/Python_Projects/gaeseries/django/core/files/base.pyR/   p   s    i   N(   R   t
   __module__R"   R   R   R   R   R   R   R   R   R   t   propertyR   R    R   R&   R'   R,   R-   R/   (    (    (    sC   /home/panlixing/Python_Projects/gaeseries/django/core/files/base.pyR   
   s"   
						
			t   ContentFilec           B   s>   e  Z d  Z d „  Z d „  Z d „  Z d d „ Z d „  Z RS(   sU   
    A File-like object that takes just raw content, rather than an actual file.
    c         C   s;   | p	 d } t  t |  ƒ j t | ƒ ƒ t | ƒ |  _ d  S(   NR   (   t   superR2   R   R    t   lenR   (   R
   t   content(    (    sC   /home/panlixing/Python_Projects/gaeseries/django/core/files/base.pyR   w   s    c         C   s   d S(   Ns   Raw content(    (   R
   (    (    sC   /home/panlixing/Python_Projects/gaeseries/django/core/files/base.pyR   |   s    c         C   s   t  S(   N(   t   True(   R
   (    (    sC   /home/panlixing/Python_Projects/gaeseries/django/core/files/base.pyR      s    c         C   s   |  j  d ƒ d  S(   Ni    (   R!   (   R
   R   (    (    sC   /home/panlixing/Python_Projects/gaeseries/django/core/files/base.pyR-   ‚   s    c         C   s   d  S(   N(    (   R
   (    (    sC   /home/panlixing/Python_Projects/gaeseries/django/core/files/base.pyR/   …   s    N(	   R   R0   t   __doc__R   R   R   R   R-   R/   (    (    (    sC   /home/panlixing/Python_Projects/gaeseries/django/core/files/base.pyR2   s   s   			(   R   t	   cStringIOR    t   ImportErrort   django.utils.encodingR   R   t   django.core.files.utilsR   R   R2   (    (    (    sC   /home/panlixing/Python_Projects/gaeseries/django/core/files/base.pyt   <module>   s   i