o a.@sdZddlZddlmZddlmZddlmZmZddl m Z gdZ Gdd d e Z Gd d d e ZGd d d e ZGddde ZGdddZGdddeZGdddeZddZdS)zH Base file upload handler classes, and the built-in concrete subclasses N)BytesIO)settings)InMemoryUploadedFileTemporaryUploadedFile import_string)UploadFileException StopUploadSkipFileFileUploadHandlerTemporaryFileUploadHandlerMemoryFileUploadHandler load_handlerStopFutureHandlersc@eZdZdZdS)rz6 Any error having to do with uploading files. N__name__ __module__ __qualname____doc__rrA/usr/lib/python3/dist-packages/django/core/files/uploadhandler.pyrrc@s"eZdZdZdddZddZdS) r z= This exception is raised when an upload must abort. FcCs ||_dS)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. Nconnection_reset)selfrrrr__init__s zStopUpload.__init__cCs|jrdSdS)Nz StopUpload: Halt current upload.z,StopUpload: Consume request data, then halt.rrrrr__str__'szStopUpload.__str__N)F)rrrrrrrrrrr s  r c@r)r zX This exception is raised by an upload handler that wants to skip a given file. Nrrrrrr .rr c@r)rz Upload handlers that have handled a file and do not want future handlers to run should raise this exception instead of returning None. Nrrrrrr5src@sReZdZdZdZdddZdddZddd Zd d Zd d Z ddZ ddZ dS)r z3 Base class for streaming upload handlers. iNcCs(d|_d|_d|_d|_d|_||_dSN) file_name content_typecontent_lengthcharsetcontent_type_extrarequest)rr%rrrrCs  zFileUploadHandler.__init__cCdS)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 '--'. Nrr input_dataMETAr"boundaryencodingrrrhandle_raw_inputKsz"FileUploadHandler.handle_raw_inputcCs(||_||_||_||_||_||_dS)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$)rr-r r!r"r#r$rrrnew_file]s  zFileUploadHandler.new_filecCtd)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() methodNotImplementedErrorrraw_datastartrrrreceive_data_chunkksz$FileUploadHandler.receive_data_chunkcCr/)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() methodr0r file_sizerrr file_completerszFileUploadHandler.file_completecCr&)z Signal that the upload is complete. Subclasses should perform cleanup that is necessary for this handler. Nrrrrrupload_complete{z!FileUploadHandler.upload_completecCr&)z Signal that the upload was interrupted. Subclasses should perform cleanup that is necessary for this handler. Nrrrrrupload_interruptedr:z$FileUploadHandler.upload_interruptedr)NN) rrrr chunk_sizerr,r.r5r8r9r;rrrrr =s    r cs8eZdZdZfddZddZddZdd ZZS) r zA Upload handler that streams data into a temporary file. cs0tj|i|t|j|jd|j|j|_dS)zK Create the file object to append to as data is coming in. rN)superr.rr r!r#r$filerargskwargs __class__rrr.sz#TemporaryFileUploadHandler.new_filecCs|j|dSr)r>writer2rrrr5sz-TemporaryFileUploadHandler.receive_data_chunkcCs|jd||j_|jS)Nr)r>seeksizer6rrrr8s z(TemporaryFileUploadHandler.file_completecCsHt|dr"|j}z |jt|WdSty!YdSwdS)Nr>)hasattrr>temporary_file_pathcloseosremoveFileNotFoundError)r temp_locationrrrr;s    z-TemporaryFileUploadHandler.upload_interrupted) rrrrr.r5r8r; __classcell__rrrBrr s  r cs:eZdZdZd ddZfddZddZd d ZZS) r zS File upload handler to stream uploads into memory (used for small files). NcCs|tjk|_dS)zf Use the content_length to signal whether or not this handler should be used. N)rFILE_UPLOAD_MAX_MEMORY_SIZE activatedr'rrrr,sz(MemoryFileUploadHandler.handle_raw_inputcs*tj|i||jrt|_tdSr)r=r.rPrr>rr?rBrrr.s z MemoryFileUploadHandler.new_filecCs|jr |j|dS|S)z!Add the data to the BytesIO file.N)rPr>rDr2rrrr5sz*MemoryFileUploadHandler.receive_data_chunkc Cs8|jsdS|jdt|j|j|j|j||j|jdS)z2Return a file object if this handler is activated.Nr)r>r-namer!rFr#r$) rPr>rErr-r r!r#r$r6rrrr8s z%MemoryFileUploadHandler.file_completer) rrrrr,r.r5r8rNrrrBrr s   r cOst||i|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) r)pathr@rArrrrs r)rrJior django.confrdjango.core.files.uploadedfilerrdjango.utils.module_loadingr__all__ Exceptionrr r rr r r rrrrrs   M ,