ó
®â0_c           @  s7  d  Z  d d l m Z d d l m Z d d l m Z d d l m Z m	 Z	 d d l
 m Z d d l m Z d d	 d
 d d d d d g Z d e f d „  ƒ  YZ e d e f d „  ƒ  Yƒ 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 „  Z d S(    uH   
Base file upload handler classes, and the built-in concrete subclasses
iÿÿÿÿ(   t   unicode_literals(   t   BytesIO(   t   settings(   t   InMemoryUploadedFilet   TemporaryUploadedFile(   t   python_2_unicode_compatible(   t   import_stringu   UploadFileExceptionu
   StopUploadu   SkipFileu   FileUploadHandleru   TemporaryFileUploadHandleru   MemoryFileUploadHandleru   load_handleru   StopFutureHandlerst   UploadFileExceptionc           B  s   e  Z d  Z RS(   u6   
    Any error having to do with uploading files.
    (   t   __name__t
   __module__t   __doc__(    (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/uploadhandler.pyR      s   t
   StopUploadc           B  s#   e  Z d  Z e d „ Z d „  Z RS(   u=   
    This exception is raised when an upload must abort.
    c         C  s   | |  _  d S(   uÒ   
        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   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/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   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/uploadhandler.pyt   __str__+   s    	(   R   R	   R
   t   FalseR   R   (    (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/uploadhandler.pyR      s   t   SkipFilec           B  s   e  Z d  Z RS(   uX   
    This exception is raised by an upload handler that wants to skip a given file.
    (   R   R	   R
   (    (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/uploadhandler.pyR   2   s   t   StopFutureHandlersc           B  s   e  Z d  Z RS(   u“   
    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
   (    (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/uploadhandler.pyR   9   s   t   FileUploadHandlerc           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(   u3   
    Base class for streaming upload handlers.
    i@   i   i
   c         C  s:   d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ | |  _ d  S(   N(   t   Nonet	   file_namet   content_typet   content_lengtht   charsett   content_type_extrat   request(   R   R   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/uploadhandler.pyR   G   s    					c         C  s   d S(   uÆ  
        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(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/uploadhandler.pyt   handle_raw_inputO   s    c         C  s:   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ d S(   u½   
        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   (   R   R    R   R   R   R   R   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/uploadhandler.pyt   new_filea   s    					c         C  s   t  d ƒ ‚ d S(   u{   
        Receive data from the streamed upload parser. ``start`` is the position
        in the file of the chunk.
        uJ   subclasses of FileUploadHandler must provide a receive_data_chunk() methodN(   t   NotImplementedError(   R   t   raw_datat   start(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/uploadhandler.pyt   receive_data_chunko   s    c         C  s   t  d ƒ ‚ d S(   uÆ   
        Signal that a file has completed. File size corresponds to the actual
        size accumulated by all the chunks.

        Subclasses should return a valid ``UploadedFile`` object.
        uE   subclasses of FileUploadHandler must provide a file_complete() methodN(   R"   (   R   t	   file_size(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/uploadhandler.pyt   file_completev   s    c         C  s   d S(   uƒ   
        Signal that the upload is complete. Subclasses should perform cleanup
        that is necessary for this handler.
        N(    (   R   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/uploadhandler.pyt   upload_complete   s    i   N(   R   R	   R
   t
   chunk_sizeR   R   R   R!   R%   R'   R(   (    (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/uploadhandler.pyR   A   s   
			t   TemporaryFileUploadHandlerc           B  s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   uA   
    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(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/uploadhandler.pyR   ‹   s    c         O  sD   t  t |  ƒ j | | Ž  t |  j |  j d |  j |  j ƒ |  _ d S(   uK   
        Create the file object to append to as data is coming in.
        i    N(	   R+   R*   R!   R   R   R   R   R   t   file(   R   R,   R-   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/uploadhandler.pyR!   Ž   s    c         C  s   |  j  j | ƒ d  S(   N(   R.   t   write(   R   R#   R$   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/uploadhandler.pyR%   •   s    c         C  s#   |  j  j d ƒ | |  j  _ |  j  S(   Ni    (   R.   t   seekt   size(   R   R&   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/uploadhandler.pyR'   ˜   s    (   R   R	   R
   R   R!   R%   R'   (    (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/uploadhandler.pyR*   ‡   s
   			t   MemoryFileUploadHandlerc           B  s5   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z RS(   uS   
    File upload handler to stream uploads into memory (used for small files).
    c         C  s(   | t  j k r t |  _ n	 t |  _ d S(   u`   
        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   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/uploadhandler.pyR   £   s    c         O  s>   t  t |  ƒ j | | Ž  |  j r: t ƒ  |  _ t ƒ  ‚ n  d  S(   N(   R+   R2   R!   R4   R   R.   R   (   R   R,   R-   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/uploadhandler.pyR!   ®   s    	c         C  s$   |  j  r |  j j | ƒ n | Sd S(   u3   
        Add the data to the BytesIO file.
        N(   R4   R.   R/   (   R   R#   R$   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/uploadhandler.pyR%   ´   s    	c         C  s`   |  j  s d S|  j j d ƒ t d |  j d |  j d |  j d |  j d | d |  j d	 |  j ƒ S(
   u:   
        Return a file object if we're activated.
        Ni    R.   R    t   nameR   R1   R   R   (	   R4   R.   R0   R   R    R   R   R   R   (   R   R&   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/uploadhandler.pyR'   ½   s    						N(   R   R	   R
   R   R   R!   R%   R'   (    (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/uploadhandler.pyR2   ž   s
   			c         O  s   t  |  ƒ | | Ž  S(   u=  
    Given a path to a handler, return an instance of that handler.

    E.g.::
        >>> from django.http import HttpRequest
        >>> request = HttpRequest()
        >>> load_handler('django.core.files.uploadhandler.TemporaryFileUploadHandler', request)
        <TemporaryFileUploadHandler object at 0x...>
    (   R   (   t   pathR,   R-   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/uploadhandler.pyt   load_handlerÐ   s    
N(   R
   t
   __future__R    t   ioR   t   django.confR   t   django.core.files.uploadedfileR   R   t   django.utils.encodingR   t   django.utils.module_loadingR   t   __all__t	   ExceptionR   R   R   R   t   objectR   R*   R2   R8   (    (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/uploadhandler.pyt   <module>   s$   		F2