
    g                         d Z ddlZddlmZ ddlmZ ddlmZmZ ddl	m
Z
 g dZ G d d	e      Z G d
 de      Z G d de      Z G d de      Z G d d      Z G d de      Z G d de      Zd Zy)zH
Base file upload handler classes, and the built-in concrete subclasses
    N)BytesIO)settings)InMemoryUploadedFileTemporaryUploadedFileimport_string)UploadFileException
StopUploadSkipFileFileUploadHandlerTemporaryFileUploadHandlerMemoryFileUploadHandlerload_handlerStopFutureHandlersc                       e Zd ZdZy)r	   z6
    Any error having to do with uploading files.
    N__name__
__module____qualname____doc__     w/var/www/python.vincentserveurtest.ovh/public_html/venv/lib/python3.12/site-packages/django/core/files/uploadhandler.pyr	   r	           	r   r	   c                       e Zd ZdZddZd Zy)r
   z=
    This exception is raised when an upload must abort.
    c                     || _         y)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   s     r   __init__zStopUpload.__init__%   s     !1r   c                     | j                   ryy)Nz StopUpload: Halt current upload.z,StopUpload: Consume request data, then halt.r   r   s    r   __str__zStopUpload.__str__-   s      5Ar   N)F)r   r   r   r   r    r#   r   r   r   r
   r
       s    1Br   r
   c                       e Zd ZdZy)r   zX
    This exception is raised by an upload handler that wants to skip a given file.
    Nr   r   r   r   r   r   4   r   r   r   c                       e Zd ZdZy)r   z
    Upload handlers that have handled a file and do not want future handlers to
    run should raise this exception instead of returning None.
    Nr   r   r   r   r   r   <   s    
 	r   r   c                   J    e Zd ZdZdZddZ	 ddZ	 	 ddZd Zd Z	d	 Z
d
 Zy)r   z3
    Base class for streaming upload handlers.
    i   Nc                 X    d | _         d | _        d | _        d | _        d | _        || _        y N)	file_namecontent_typecontent_lengthcharsetcontent_type_extrarequest)r   r.   s     r   r    zFileUploadHandler.__init__L   s/     ""&r   c                      y)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encodings         r   handle_raw_inputz"FileUploadHandler.handle_raw_inputT   s    $ 	r   c                 X    || _         || _        || _        || _        || _        || _        y)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   r7   r)   r*   r+   r,   r-   s          r   new_filezFileUploadHandler.new_fileh   s1     %"(,"4r   c                     t        d      )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() methodNotImplementedErrorr   raw_datastarts      r   receive_data_chunkz$FileUploadHandler.receive_data_chunk~   s    
 "X
 	
r   c                     t        d      )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() methodr:   r   	file_sizes     r   file_completezFileUploadHandler.file_complete   s     "S
 	
r   c                      y)z
        Signal that the upload is complete. Subclasses should perform cleanup
        that is necessary for this handler.
        Nr   r"   s    r   upload_completez!FileUploadHandler.upload_complete       
 	r   c                      y)z
        Signal that the upload was interrupted. Subclasses should perform
        cleanup that is necessary for this handler.
        Nr   r"   s    r   upload_interruptedz$FileUploadHandler.upload_interrupted   rF   r   r(   )NN)r   r   r   r   
chunk_sizer    r5   r8   r?   rC   rE   rH   r   r   r   r   r   E   s@     J DH4 5,
	
r   r   c                   4     e Zd ZdZ fdZd Zd Zd Z xZS )r   zA
    Upload handler that streams data into a temporary file.
    c                     t        |   |i | t        | j                  | j                  d| j
                  | j                        | _        y)zK
        Create the file object to append to as data is coming in.
        r   N)superr8   r   r)   r*   r,   r-   filer   argskwargs	__class__s      r   r8   z#TemporaryFileUploadHandler.new_file   sB     	$)&))NND--q$,,@W@W
	r   c                 :    | j                   j                  |       y r(   )rM   writer<   s      r   r?   z-TemporaryFileUploadHandler.receive_data_chunk   s    		!r   c                 r    | j                   j                  d       || j                   _        | j                   S )Nr   )rM   seeksizerA   s     r   rC   z(TemporaryFileUploadHandler.file_complete   s'    		q"		yyr   c                     t        | d      rK| j                  j                         }	 | j                  j                          t	        j
                  |       y y # t        $ r Y y w xY w)NrM   )hasattrrM   temporary_file_pathcloseosremoveFileNotFoundError)r   temp_locations     r   rH   z-TemporaryFileUploadHandler.upload_interrupted   sV    4  II99;M		!		-(	 !
 % s   /A 	A%$A%)	r   r   r   r   r8   r?   rC   rH   __classcell__rQ   s   @r   r   r      s    
"
r   r   c                   8     e Zd ZdZ	 ddZ fdZd Zd Z xZS )r   zS
    File upload handler to stream uploads into memory (used for small files).
    c                 4    |t         j                  k  | _        y)zf
        Use the content_length to signal whether or not this handler should be
        used.
        N)r   FILE_UPLOAD_MAX_MEMORY_SIZE	activatedr0   s         r   r5   z(MemoryFileUploadHandler.handle_raw_input   s     (8+O+OOr   c                 n    t        |   |i | | j                  rt               | _        t               y r(   )rL   r8   rd   r   rM   r   rN   s      r   r8   z MemoryFileUploadHandler.new_file   s3    $)&)>>	DI$&& r   c                 V    | j                   r| j                  j                  |       y|S )z!Add the data to the BytesIO file.N)rd   rM   rS   r<   s      r   r?   z*MemoryFileUploadHandler.receive_data_chunk   s    >>IIOOH%Or   c           	          | j                   sy| j                  j                  d       t        | j                  | j                  | j
                  | j                  || j                  | j                        S )z2Return a file object if this handler is activated.Nr   )rM   r7   namer*   rV   r,   r-   )	rd   rM   rU   r   r7   r)   r*   r,   r-   rA   s     r   rC   z%MemoryFileUploadHandler.file_complete   sZ    ~~		q#**LL#66
 	
r   r(   )	r   r   r   r   r5   r8   r?   rC   r_   r`   s   @r   r   r      s$    
 DH	P'
r   r   c                 $     t        |       |i |S )al  
    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   )pathrO   rP   s      r   r   r      s     =///r   )r   r[   ior   django.confr   django.core.files.uploadedfiler   r   django.utils.module_loadingr   __all__	Exceptionr	   r
   r   r   r   r   r   r   r   r   r   <module>rq      s    
    V 5		) 	B$ B(	" 		, 	Y Yx!2 @+
/ +
\0r   