ó
ø¢TQc           @  sG  d  Z  d d l m 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   ImproperlyConfigured(   t   TemporaryUploadedFilet   InMemoryUploadedFile(   t	   importlib(   t   python_2_unicode_compatibleu   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__(    (    (    s8   ../Django//lib/python/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   (    (    s8   ../Django//lib/python/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   (    (    s8   ../Django//lib/python/django/core/files/uploadhandler.pyt   __str__&   s    	(   R	   R
   R   t   FalseR   R   (    (    (    s8   ../Django//lib/python/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   (    (    (    s8   ../Django//lib/python/django/core/files/uploadhandler.pyR   ,   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   (    (    (    s8   ../Django//lib/python/django/core/files/uploadhandler.pyR   2   s   t   FileUploadHandlerc           B  sW   e  Z d  Z d d
 Z d d „ Z d d „ Z d d „ Z d „  Z d „  Z	 d	 „  Z
 RS(   u3   
    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   (    (    s8   ../Django//lib/python/django/core/files/uploadhandler.pyR   ?   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(    (    s8   ../Django//lib/python/django/core/files/uploadhandler.pyt   handle_raw_inputF   s    c         C  s1   | |  _  | |  _ | |  _ | |  _ | |  _ 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   (    (    s8   ../Django//lib/python/django/core/files/uploadhandler.pyt   new_fileX   s
    				c         C  s   t  ƒ  ‚ d S(   u{   
        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(    (    s8   ../Django//lib/python/django/core/files/uploadhandler.pyt   receive_data_chunke   s    c         C  s   t  ƒ  ‚ 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.
        N(   R"   (   R   t	   file_size(    (    s8   ../Django//lib/python/django/core/files/uploadhandler.pyt   file_completel   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   (    (    s8   ../Django//lib/python/django/core/files/uploadhandler.pyt   upload_completeu   s    i   N(   R	   R
   R   t
   chunk_sizeR   R   R   R!   R%   R'   R(   (    (    (    s8   ../Django//lib/python/django/core/files/uploadhandler.pyR   9   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(    (    s8   ../Django//lib/python/django/core/files/uploadhandler.pyR   €   s    c         O  sA   t  t |  ƒ j | | | Ž t |  j |  j d |  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   t   file(   R   R   R,   R-   (    (    s8   ../Django//lib/python/django/core/files/uploadhandler.pyR!   ƒ   s    c         C  s   |  j  j | ƒ d  S(   N(   R.   t   write(   R   R#   R$   (    (    s8   ../Django//lib/python/django/core/files/uploadhandler.pyR%   Š   s    c         C  s#   |  j  j d ƒ | |  j  _ |  j  S(   Ni    (   R.   t   seekt   size(   R   R&   (    (    s8   ../Django//lib/python/django/core/files/uploadhandler.pyR'      s    (   R	   R
   R   R   R!   R%   R'   (    (    (    s8   ../Django//lib/python/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   (    (    s8   ../Django//lib/python/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-   (    (    s8   ../Django//lib/python/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$   (    (    s8   ../Django//lib/python/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(	   u:   
        Return a file object if we're activated.
        Ni    R.   R    t   nameR   R1   R   (   R4   R.   R0   R   R    R   R   R   (   R   R&   (    (    s8   ../Django//lib/python/django/core/files/uploadhandler.pyR'   ±   s    					N(   R	   R
   R   R   R   R!   R%   R'   (    (    (    s8   ../Django//lib/python/django/core/files/uploadhandler.pyR2   ’   s
   			c   	      O  sÍ   |  j  d ƒ } |  |  |  | d } } y t j | ƒ } WnE 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(   uê   
    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...>

    u   .i   u.   Error importing upload handler module %s: "%s"u`   Error importing upload handler module.Is FILE_UPLOAD_HANDLERS a correctly defined list or tuple?u9   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(    (    s8   ../Django//lib/python/django/core/files/uploadhandler.pyt   load_handlerÃ   s    	N(   R   t
   __future__R    t   ioR   t   django.confR   t   django.core.exceptionsR   t   django.core.files.uploadedfileR   R   t   django.utilsR   t   django.utils.encodingR   t   __all__t	   ExceptionR   R   R   R   t   objectR   R*   R2   RD   (    (    (    s8   ../Django//lib/python/django/core/files/uploadhandler.pyt   <module>   s&   C1