î
ªÍ XÜ  ã               @   s:  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 Gd d „  d e ƒ Z e Gd d	 „  d	 e ƒ ƒ Z Gd d
 „  d
 e ƒ Z Gd d „  d e ƒ Z Gd d „  d e ƒ Z Gd d „  d e ƒ Z Gd d „  d e ƒ Z d d „  Z d S)zH
Base file upload handler classes, and the built-in concrete subclasses
é    )Úunicode_literals)ÚBytesIO)Úsettings)ÚInMemoryUploadedFileÚTemporaryUploadedFile)Úpython_2_unicode_compatible)Úimport_stringÚUploadFileExceptionÚ
StopUploadÚSkipFileÚFileUploadHandlerÚTemporaryFileUploadHandlerÚMemoryFileUploadHandlerÚload_handlerÚStopFutureHandlersc               @   s   e  Z d  Z d Z d S)r	   z6
    Any error having to do with uploading files.
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   úM/home/ubuntu/projects/ifolica/build/django/django/core/files/uploadhandler.pyr	      s   c               @   s1   e  Z d  Z d Z d d d „ Z d d „  Z d S)r
   z=
    This exception is raised when an upload must abort.
    Fc             C   s   | |  _  d S)zÒ
        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)Úconnection_reset)Úselfr   r   r   r   Ú__init__#   s    zStopUpload.__init__c             C   s   |  j  r d Sd Sd  S)Nz StopUpload: Halt current upload.z,StopUpload: Consume request data, then halt.)r   )r   r   r   r   Ú__str__+   s    	zStopUpload.__str__N)r   r   r   r   r   r   r   r   r   r   r
      s   c               @   s   e  Z d  Z d Z d S)r   zX
    This exception is raised by an upload handler that wants to skip a given file.
    N)r   r   r   r   r   r   r   r   r   2   s   c               @   s   e  Z d  Z d Z d S)r   z“
    Upload handers that have handled a file and do not want future handlers to
    run should raise this exception instead of returning None.
    N)r   r   r   r   r   r   r   r   r   9   s   c               @   sp   e  Z d  Z d Z d Z d d d „ Z d d d	 „ Z d d d
 d „ Z d d „  Z d d „  Z	 d d „  Z
 d S)r   z3
    Base class for streaming upload handlers.
    é@   é   é
   Nc             C   s:   d  |  _  d  |  _ d  |  _ d  |  _ d  |  _ | |  _ d  S)N)Ú	file_nameÚcontent_typeÚcontent_lengthÚcharsetÚcontent_type_extraÚrequest)r   r#   r   r   r   r   G   s    					zFileUploadHandler.__init__c             C   s   d S)aÆ  
        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 '--'.
        Nr   )r   Ú
input_dataÚMETAr    ÚboundaryÚencodingr   r   r   Úhandle_raw_inputO   s    z"FileUploadHandler.handle_raw_inputc             C   s:   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ d S)z½
        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)Ú
field_namer   r   r    r!   r"   )r   r)   r   r   r    r!   r"   r   r   r   Únew_filea   s    					zFileUploadHandler.new_filec             C   s   t  d ƒ ‚ d S)z{
        Receive data from the streamed upload parser. ``start`` is the position
        in the file of the chunk.
        zJsubclasses of FileUploadHandler must provide a receive_data_chunk() methodN)ÚNotImplementedError)r   Úraw_dataÚstartr   r   r   Úreceive_data_chunko   s    z$FileUploadHandler.receive_data_chunkc             C   s   t  d ƒ ‚ d S)zÆ
        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.
        zEsubclasses of FileUploadHandler must provide a file_complete() methodN)r+   )r   Ú	file_sizer   r   r   Úfile_completev   s    zFileUploadHandler.file_completec             C   s   d S)zƒ
        Signal that the upload is complete. Subclasses should perform cleanup
        that is necessary for this handler.
        Nr   )r   r   r   r   Úupload_complete   s    z!FileUploadHandler.upload_completei   i   )r   r   r   r   Ú
chunk_sizer   r(   r*   r.   r0   r1   r   r   r   r   r   A   s   	c                   sR   e  Z d  Z d Z ‡  f d d †  Z ‡  f d d †  Z d d „  Z d d	 „  Z ‡  S)
r   zA
    Upload handler that streams data into a temporary file.
    c                s   t  t |  ƒ j | | Ž  d  S)N)Úsuperr   r   )r   ÚargsÚkwargs)Ú	__class__r   r   r   ‹   s    z#TemporaryFileUploadHandler.__init__c                sD   t  t |  ƒ j | | Ž  t |  j |  j d |  j |  j ƒ |  _ d S)zK
        Create the file object to append to as data is coming in.
        r   N)	r3   r   r*   r   r   r   r!   r"   Úfile)r   r4   r5   )r6   r   r   r*   Ž   s    z#TemporaryFileUploadHandler.new_filec             C   s   |  j  j | ƒ d  S)N)r7   Úwrite)r   r,   r-   r   r   r   r.   •   s    z-TemporaryFileUploadHandler.receive_data_chunkc             C   s#   |  j  j d ƒ | |  j  _ |  j  S)Nr   )r7   ÚseekÚsize)r   r/   r   r   r   r0   ˜   s    z(TemporaryFileUploadHandler.file_complete)r   r   r   r   r   r*   r.   r0   r   r   )r6   r   r   ‡   s
   c                   sO   e  Z d  Z d Z d d d „ Z ‡  f d d †  Z d d „  Z d	 d
 „  Z ‡  S)r   zS
    File upload handler to stream uploads into memory (used for small files).
    Nc             C   s(   | t  j k r d |  _ n	 d |  _ d S)z`
        Use the content_length to signal whether or not this handler should be in use.
        FTN)r   ZFILE_UPLOAD_MAX_MEMORY_SIZEÚ	activated)r   r$   r%   r    r&   r'   r   r   r   r(   £   s    z(MemoryFileUploadHandler.handle_raw_inputc                s>   t  t |  ƒ j | | Ž  |  j r: t ƒ  |  _ t ƒ  ‚ n  d  S)N)r3   r   r*   r;   r   r7   r   )r   r4   r5   )r6   r   r   r*   ®   s    	z MemoryFileUploadHandler.new_filec             C   s$   |  j  r |  j j | ƒ n | Sd S)z3
        Add the data to the BytesIO file.
        N)r;   r7   r8   )r   r,   r-   r   r   r   r.   ´   s    	z*MemoryFileUploadHandler.receive_data_chunkc             C   s`   |  j  s d S|  j j d ƒ t d |  j d |  j d |  j d |  j d | d |  j d	 |  j ƒ S)
z:
        Return a file object if we're activated.
        Nr   r7   r)   Únamer   r:   r!   r"   )	r;   r7   r9   r   r)   r   r   r!   r"   )r   r/   r   r   r   r0   ½   s    						z%MemoryFileUploadHandler.file_complete)r   r   r   r   r(   r*   r.   r0   r   r   )r6   r   r   ž   s
   	c             O   s   t  |  ƒ | | Ž  S)a=  
    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   )Úpathr4   r5   r   r   r   r   Ð   s    
N)r   Ú
__future__r   Úior   Zdjango.confr   Zdjango.core.files.uploadedfiler   r   Zdjango.utils.encodingr   Zdjango.utils.module_loadingr   Ú__all__Ú	Exceptionr	   r
   r   r   Úobjectr   r   r   r   r   r   r   r   Ú<module>   s$   		F2