
    h                         S r SSKrSSKJr  SSKJr  SSKJrJr  SSK	J
r
  / SQr " S S	\5      r " S
 S\5      r " S S\5      r " S S\5      r " S S5      r " S S\5      r " S S\5      rS rg)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                       \ rS rSrSrSrg)r	      z.
Any error having to do with uploading files.
 N__name__
__module____qualname____firstlineno____doc____static_attributes__r       Q/var/www/html/env/lib/python3.13/site-packages/django/core/files/uploadhandler.pyr	   r	           	r   r	   c                   (    \ rS rSrSrSS jrS rSrg)r
       z5
This exception is raised when an upload must abort.
c                     Xl         g)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__StopUpload.__init__%   s
     !1r   c                 (    U R                   (       a  gg)Nz StopUpload: Halt current upload.z,StopUpload: Consume request data, then halt.r!   r#   s    r   __str__StopUpload.__str__-   s      5Ar   r!   N)F)r   r   r   r   r   r$   r(   r   r   r   r   r
   r
       s    1Br   r
   c                       \ rS rSrSrSrg)r   4   zP
This exception is raised by an upload handler that wants to skip a given file.
r   Nr   r   r   r   r   r   4   r   r   r   c                       \ rS rSrSrSrg)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.
r   Nr   r   r   r   r   r   <   s    
 	r   r   c                   X    \ rS rSrSrSrSS jr SS jr  SS jrS r	S	 r
S
 rS rSrg)r   E   z+
Base class for streaming upload handlers.
i   Nc                 V    S U l         S U l        S U l        S U l        S U l        Xl        g N)	file_namecontent_typecontent_lengthcharsetcontent_type_extrarequest)r#   r7   s     r   r$   FileUploadHandler.__init__L   s-     ""&r   c                     g)af  
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METAr4   boundaryencodings         r   handle_raw_input"FileUploadHandler.handle_raw_inputT   s    $ 	r   c                 L    Xl         X l        X0l        X@l        XPl        X`l        g)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_namer2   r3   r4   r5   r6   )r#   rB   r2   r3   r4   r5   r6   s          r   new_fileFileUploadHandler.new_fileh   s%     %"(,"4r   c                     [        S5      e)zc
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_chunk$FileUploadHandler.receive_data_chunk~   s    
 "X
 	
r   c                     [        S5      e)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() methodrF   r#   	file_sizes     r   file_completeFileUploadHandler.file_complete   s     "S
 	
r   c                     g)zk
Signal that the upload is complete. Subclasses should perform cleanup
that is necessary for this handler.
Nr   r'   s    r   upload_complete!FileUploadHandler.upload_complete       
 	r   c                     g)zo
Signal that the upload was interrupted. Subclasses should perform
cleanup that is necessary for this handler.
Nr   r'   s    r   upload_interrupted$FileUploadHandler.upload_interrupted   rU   r   )r5   r4   r3   r6   rB   r2   r7   r1   )NN)r   r   r   r   r   
chunk_sizer$   r?   rC   rK   rP   rS   rW   r   r   r   r   r   r   E   s@     J DH4 5,
	
r   r   c                   >   ^  \ rS rSrSrU 4S jrS rS rS rSr	U =r
$ )r      z9
Upload handler that streams data into a temporary file.
c                    > [         TU ]  " U0 UD6  [        U R                  U R                  SU R
                  U R                  5      U l        g)z;
Create the file object to append to as data is coming in.
r   N)superrC   r   r2   r3   r5   r6   filer#   argskwargs	__class__s      r   rC   #TemporaryFileUploadHandler.new_file   sB     	$)&))NND--q$,,@W@W
	r   c                 :    U R                   R                  U5        g r1   )r^   writerH   s      r   rK   -TemporaryFileUploadHandler.receive_data_chunk   s    		!r   c                 p    U R                   R                  S5        XR                   l        U R                   $ )Nr   )r^   seeksizerN   s     r   rP   (TemporaryFileUploadHandler.file_complete   s%    		q"		yyr   c                     [        U S5      (       aL  U R                  R                  5       n U R                  R                  5         [        R
                  " U5        g g ! [         a     g f = f)Nr^   )hasattrr^   temporary_file_pathcloseosremoveFileNotFoundError)r#   temp_locations     r   rW   -TemporaryFileUploadHandler.upload_interrupted   sY    4   II99;M		!		-(	 !
 % s   0A 
A,+A,)r^   )r   r   r   r   r   rC   rK   rP   rW   r   __classcell__rb   s   @r   r   r      s!    
"
 r   r   c                   D   ^  \ rS rSrSr SS jrU 4S jrS rS rSr	U =r
$ )	r      zK
File upload handler to stream uploads into memory (used for small files).
c                 4    U[         R                  :*  U l        g)zN
Use the content_length to signal whether or not this handler should be
used.
N)r   FILE_UPLOAD_MAX_MEMORY_SIZE	activatedr:   s         r   r?   (MemoryFileUploadHandler.handle_raw_input   s     (8+O+OOr   c                 z   > [         TU ]  " U0 UD6  U R                  (       a  [        5       U l        [        5       eg r1   )r]   rC   rz   r   r^   r   r_   s      r   rC    MemoryFileUploadHandler.new_file   s3    $)&)>>	DI$&& r   c                 `    U R                   (       a  U R                  R                  U5        gU$ )z!Add the data to the BytesIO file.N)rz   r^   re   rH   s      r   rK   *MemoryFileUploadHandler.receive_data_chunk   s    >>IIOOH%Or   c           
          U R                   (       d  gU R                  R                  S5        [        U R                  U R                  U R
                  U R                  UU R                  U R                  S9$ )z2Return a file object if this handler is activated.Nr   )r^   rB   namer3   ri   r5   r6   )	rz   r^   rh   r   rB   r2   r3   r5   r6   rN   s     r   rP   %MemoryFileUploadHandler.file_complete   sZ    ~~		q#**LL#66
 	
r   )rz   r^   r1   )r   r   r   r   r   r?   rC   rK   rP   r   rt   ru   s   @r   r   r      s)    
 DH	P'
 
r   r   c                 $    [        U 5      " U0 UD6$ )aD  
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   )pathr`   ra   s      r   r   r      s     ///r   )r   ro   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>r      s    
    V 5		) 	B$ B(	" 		, 	Y Yx!2 @+
/ +
\0r   