
    Evg                        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dS )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dS )r	   z6
    Any error having to do with uploading files.
    N__name__
__module____qualname____doc__     \/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/django/core/files/uploadhandler.pyr	   r	                	Dr   r	   c                        e Zd ZdZddZd ZdS )r
   z=
    This exception is raised when an upload must abort.
    Fc                     || _         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   s     r   __init__zStopUpload.__init__%   s     !1r   c                     | j         rdS dS )Nz StopUpload: Halt current upload.z,StopUpload: Consume request data, then halt.r   r   s    r   __str__zStopUpload.__str__-   s      	B55AAr   N)F)r   r   r   r   r    r#   r   r   r   r
   r
       sF         1 1 1 1B B B B Br   r
   c                       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.
    Nr   r   r   r   r   r   4   r   r   r   c                       e Zd ZdZdS )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         
 	Dr   r   c                   L    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dS )r   z3
    Base class for streaming upload handlers.
    i   Nc                 Z    d | _         d | _        d | _        d | _        d | _        || _        d S N)	file_namecontent_typecontent_lengthcharsetcontent_type_extrarequest)r   r.   s     r   r    zFileUploadHandler.__init__L   s3     ""&r   c                     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encodings         r   handle_raw_inputz"FileUploadHandler.handle_raw_inputT   s	    $ 	r   c                 Z    || _         || _        || _        || _        || _        || _        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   r7   r)   r*   r+   r,   r-   s          r   new_filezFileUploadHandler.new_fileh   s7     %"(,"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                     dS )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                     dS )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 5 5 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                      j        |i | t          | j        | j        d| j        | j                  | _        dS )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   sK     	$)&))))ND-q$,@W
 
			r   c                 :    | j                             |           d S r(   )rM   writer<   s      r   r?   z-TemporaryFileUploadHandler.receive_data_chunk   s    	!!!!!r   c                 \    | j                             d           || j         _        | j         S )Nr   )rM   seeksizerA   s     r   rC   z(TemporaryFileUploadHandler.file_complete   s'    	q"	yr   c                     t          | d          rZ| j                                        }	 | j                                         t	          j        |           d S # t          $ r Y d S w xY wd S )NrM   )hasattrrM   temporary_file_pathcloseosremoveFileNotFoundError)r   temp_locations     r   rH   z-TemporaryFileUploadHandler.upload_interrupted   s    4   	 I99;;M	!!!	-((((($   	 	s   -A 
A('A()	r   r   r   r   r8   r?   rC   rH   __classcell__rQ   s   @r   r   r      so         
 
 
 
 
" " "  
      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).
    Nc                 0    |t           j        k    | _        dS )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r   c                      t                      j        |i | | j        r!t                      | _        t                      d S r(   )rL   r8   rd   r   rM   r   rN   s      r   r8   z MemoryFileUploadHandler.new_file   sJ    $)&)))> 	'		DI$&&&	' 	'r   c                 L    | j         r| j                            |           dS |S )z!Add the data to the BytesIO file.N)rd   rM   rS   r<   s      r   r?   z*MemoryFileUploadHandler.receive_data_chunk   s+    > 	IOOH%%%%%Or   c           	          | j         sdS | 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   s_    ~ 	F	q#*L#6
 
 
 	
r   r(   )	r   r   r   r   r5   r8   r?   rC   r_   r`   s   @r   r   r      s         
 DH	P 	P 	P 	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 V V V V V V V 5 5 5 5 5 5	 	 		 	 	 	 	) 	 	 	B B B B B$ B B B(	 	 	 	 	" 	 	 		 	 	 	 	, 	 	 	Y Y Y Y Y Y Y Yx    !2   @+
 +
 +
 +
 +
/ +
 +
 +
\0 0 0 0 0r   