ó
TR¹Nc           @   sI  d  Z  y d d l m Z Wn! e k
 r= d d l m Z n Xd d l m Z d d l m Z d d l m	 Z	 m
 Z
 d d l m Z d d d	 d
 d d d d g Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e f d „  ƒ  YZ d e f d „  ƒ  YZ d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d S(   sH   
Base file upload handler classes, and the built-in concrete subclasses
iÿÿÿÿ(   t   StringIO(   t   settings(   t   ImproperlyConfigured(   t   TemporaryUploadedFilet   InMemoryUploadedFile(   t	   importlibt   UploadFileExceptiont
   StopUploadt   SkipFilet   FileUploadHandlert   TemporaryFileUploadHandlert   MemoryFileUploadHandlert   load_handlert   StopFutureHandlersc           B   s   e  Z d  Z RS(   s6   
    Any error having to do with uploading files.
    (   t   __name__t
   __module__t   __doc__(    (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/files/uploadhandler.pyR      s   c           B   s#   e  Z d  Z e d „ Z d „  Z RS(   s=   
    This exception is raised when an upload must abort.
    c         C   s   | |  _  d S(   sÒ   
        If ``connection_reset`` is ``True``, Django knows will halt the upload
        without consuming the rest of the upload. This will cause the browser to
        show a "connection reset" error.
        N(   t   connection_reset(   t   selfR   (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/files/uploadhandler.pyt   __init__   s    c         C   s   |  j  r d Sd Sd  S(   Nu    StopUpload: Halt current upload.u,   StopUpload: Consume request data, then halt.(   R   (   R   (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/files/uploadhandler.pyt   __unicode__%   s    	(   R   R   R   t   FalseR   R   (    (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/files/uploadhandler.pyR      s   c           B   s   e  Z d  Z RS(   sX   
    This exception is raised by an upload handler that wants to skip a given file.
    (   R   R   R   (    (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/files/uploadhandler.pyR   +   s   c           B   s   e  Z d  Z RS(   s“   
    Upload handers that have handled a file and do not want future handlers to
    run should raise this exception instead of returning None.
    (   R   R   R   (    (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/files/uploadhandler.pyR   1   s   c           B   sZ   e  Z d  Z d d
 Z d d „ Z d d „ Z d d d „ Z d „  Z d „  Z	 d	 „  Z
 RS(   s3   
    Base class for streaming upload handlers.
    i@   i   i
   c         C   s1   d  |  _ d  |  _ d  |  _ d  |  _ | |  _ d  S(   N(   t   Nonet	   file_namet   content_typet   content_lengtht   charsett   request(   R   R   (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/files/uploadhandler.pyR   >   s
    				c         C   s   d S(   sÆ  
        Handle the raw input from the client.

        Parameters:

            :input_data:
                An object that supports reading via .read().
            :META:
                ``request.META``.
            :content_length:
                The (integer) value of the Content-Length header from the
                client.
            :boundary: The boundary from the Content-Type header. Be sure to
                prepend two '--'.
        N(    (   R   t
   input_datat   METAR   t   boundaryt   encoding(    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/files/uploadhandler.pyt   handle_raw_inputE   s    c         C   sO   | |  _  | |  _ | |  _ | |  _ | |  _ | d k rB i  } n  | |  _ d S(   s½   
        Signal that a new file has been started.

        Warning: As with any data from the client, you should not trust
        content_length (and sometimes won't even get it).
        N(   t
   field_nameR   R   R   R   R   t   content_type_extra(   R   R!   R   R   R   R   R"   (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/files/uploadhandler.pyt   new_fileW   s    						c         C   s   t  ƒ  ‚ d S(   s{   
        Receive data from the streamed upload parser. ``start`` is the position
        in the file of the chunk.
        N(   t   NotImplementedError(   R   t   raw_datat   start(    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/files/uploadhandler.pyt   receive_data_chunkh   s    c         C   s   t  ƒ  ‚ d S(   sË   
        Signal that a file has completed. File size corresponds to the actual
        size accumulated by all the chunks.

        Subclasses must should return a valid ``UploadedFile`` object.
        N(   R$   (   R   t	   file_size(    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/files/uploadhandler.pyt   file_completeo   s    c         C   s   d S(   sƒ   
        Signal that the upload is complete. Subclasses should perform cleanup
        that is necessary for this handler.
        N(    (   R   (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/files/uploadhandler.pyt   upload_completex   s    i   N(   R   R   R   t
   chunk_sizeR   R   R    R#   R'   R)   R*   (    (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/files/uploadhandler.pyR	   8   s   
			c           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   sA   
    Upload handler that streams data into a temporary file.
    c         O   s   t  t |  ƒ j | | Ž  d  S(   N(   t   superR
   R   (   R   t   argst   kwargs(    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/files/uploadhandler.pyR   ƒ   s    c         O   sA   t  t |  ƒ j | | | Ž t |  j |  j d |  j ƒ |  _ d S(   sK   
        Create the file object to append to as data is coming in.
        i    N(   R,   R
   R#   R   R   R   R   t   file(   R   R   R-   R.   (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/files/uploadhandler.pyR#   †   s    c         C   s   |  j  j | ƒ d  S(   N(   R/   t   write(   R   R%   R&   (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/files/uploadhandler.pyR'      s    c         C   s#   |  j  j d ƒ | |  j  _ |  j  S(   Ni    (   R/   t   seekt   size(   R   R(   (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/files/uploadhandler.pyR)      s    (   R   R   R   R   R#   R'   R)   (    (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/files/uploadhandler.pyR
      s
   			c           B   s5   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z RS(   sS   
    File upload handler to stream uploads into memory (used for small files).
    c         C   s(   | t  j k r t |  _ n	 t |  _ d S(   s`   
        Use the content_length to signal whether or not this handler should be in use.
        N(   R   t   FILE_UPLOAD_MAX_MEMORY_SIZER   t	   activatedt   True(   R   R   R   R   R   R   (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/files/uploadhandler.pyR    š   s    c         O   s>   t  t |  ƒ j | | Ž  |  j r: t ƒ  |  _ t ƒ  ‚ n  d  S(   N(   R,   R   R#   R4   R    R/   R   (   R   R-   R.   (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/files/uploadhandler.pyR#   ¥   s    	c         C   s$   |  j  r |  j j | ƒ n | Sd S(   s4   
        Add the data to the StringIO file.
        N(   R4   R/   R0   (   R   R%   R&   (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/files/uploadhandler.pyR'   «   s    	c         C   sW   |  j  s d S|  j j d ƒ t d |  j d |  j d |  j d |  j d | d |  j ƒ S(	   s:   
        Return a file object if we're activated.
        Ni    R/   R!   t   nameR   R2   R   (   R4   R/   R1   R   R!   R   R   R   (   R   R(   (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/files/uploadhandler.pyR)   ´   s    					N(   R   R   R   R   R    R#   R'   R)   (    (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/files/uploadhandler.pyR   •   s
   			c   	      O   sÏ   |  j  d ƒ } |  |  |  | d } } y t j | ƒ } WnG t k
 rf } t d | | f ƒ ‚ n t k
 r„ } t d ƒ ‚ n Xy t | | ƒ } Wn' t k
 rÁ t d | | f ƒ ‚ n X| | | Ž  S(   sê   
    Given a path to a handler, return an instance of that handler.

    E.g.::
        >>> load_handler('django.core.files.uploadhandler.TemporaryFileUploadHandler', request)
        <TemporaryFileUploadHandler object at 0x...>

    t   .i   s.   Error importing upload handler module %s: "%s"sa   Error importing upload handler module. Is FILE_UPLOAD_HANDLERS a correctly defined list or tuple?s9   Module "%s" does not define a "%s" upload handler backend(   t   rfindR   t   import_modulet   ImportErrorR   t
   ValueErrort   getattrt   AttributeError(	   t   pathR-   R.   t   it   modulet   attrt   modt   et   cls(    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/files/uploadhandler.pyR   Æ   s    	N(   R   t	   cStringIOR    R:   t   django.confR   t   django.core.exceptionsR   t   django.core.files.uploadedfileR   R   t   django.utilsR   t   __all__t	   ExceptionR   R   R   R   t   objectR	   R
   R   R   (    (    (    sL   /home/panlixing/Python_Projects/gaeseries/django/core/files/uploadhandler.pyt   <module>   s&   G1