§
    ¥”j%  ã                   óB  — d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 ddl	mZ ddl	mZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ  G d„ d¦  «        Z G d„ d¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        ZdS )zÅ
Parsers are used to parse the content of incoming HTTP requests.

They give us a generic way of being able to handle various media types
on the request, such as form content or json encoded data.
é    N)Úsettings)ÚStopFutureHandlers)Ú	QueryDict)Ú	ChunkIter)ÚMultiPartParser)ÚMultiPartParserError)Úparse_header_parameters)Ú	renderers)Ú
ParseError)Úapi_settings)Újsonc                   ó   — e Zd Zd„ ZdS )ÚDataAndFilesc                 ó"   — || _         || _        d S )N)ÚdataÚfiles)Úselfr   r   s      úe/var/www/finuniver-perm.ru/html/portfolio/venv/lib/python3.11/site-packages/rest_framework/parsers.pyÚ__init__zDataAndFiles.__init__   s   € ØˆŒ	ØˆŒ
ˆ
ˆ
ó    N)Ú__name__Ú
__module__Ú__qualname__r   © r   r   r   r      s#   € € € € € ðð ð ð ð r   r   c                   ó   — e Zd ZdZdZdd„ZdS )Ú
BaseParserz€
    All parsers should extend `BaseParser`, specifying a `media_type`
    attribute, and overriding the `.parse()` method.
    Nc                 ó    — t          d¦  «        ‚)z¿
        Given a stream to read from, return the parsed representation.
        Should return parsed data, or a `DataAndFiles` object consisting of the
        parsed data and files.
        z.parse() must be overridden.)ÚNotImplementedError)r   ÚstreamÚ
media_typeÚparser_contexts       r   ÚparsezBaseParser.parse'   s   € õ "Ð"@ÑAÔAÐAr   ©NN©r   r   r   Ú__doc__r    r"   r   r   r   r   r       s?   € € € € € ðð ð €JðBð Bð Bð Bð Bð Br   r   c                   ó:   — e Zd ZdZdZej        Zej	        Z
dd„ZdS )Ú
JSONParserz&
    Parses JSON-serialized data.
    zapplication/jsonNc                 ó>  — |pi }|                      dt          j        ¦  «        }	  t          j        |¦  «        |¦  «        }| j        rt          j        nd}t          j        ||¬¦  «        S # t          $ r$}t          dt          |¦  «        z  ¦  «        ‚d}~ww xY w)zX
        Parses the incoming bytestream as JSON and returns the resulting data.
        ÚencodingN)Úparse_constantzJSON parse error - %s)Úgetr   ÚDEFAULT_CHARSETÚcodecsÚ	getreaderÚstrictr   Ústrict_constantÚloadÚ
ValueErrorr   Ústr)r   r   r    r!   r)   Údecoded_streamr*   Úexcs           r   r"   zJSONParser.parse8   s¬   € ð (Ð-¨2ˆØ!×%Ò% jµ(Ô2JÑKÔKˆð	AØ7�VÔ-¨hÑ7Ô7¸Ñ?Ô?ˆNØ59´[ÐJ�TÔ1Ð1ÀdˆNÝ”9˜^¸NÐKÑKÔKÐKøÝð 	Að 	Að 	AÝÐ4µs¸3±x´xÑ?Ñ@Ô@Ð@øøøøð	Aøøøs   ¦AA. Á.
BÁ8BÂBr#   )r   r   r   r%   r    r
   ÚJSONRendererÚrenderer_classr   ÚSTRICT_JSONr/   r"   r   r   r   r'   r'   0   sO   € € € € € ðð ð $€JØÔ+€NØÔ%€FðAð Að Að Að Að Ar   r'   c                   ó   — e Zd ZdZdZdd„ZdS )Ú
FormParserz
    Parser for form data.
    z!application/x-www-form-urlencodedNc                 ó�   — |pi }|                      dt          j        ¦  «        }t          |                     ¦   «         |¬¦  «        S )zt
        Parses the incoming bytestream as a URL encoded form,
        and returns the resulting QueryDict.
        r)   )r)   )r+   r   r,   r   Úread)r   r   r    r!   r)   s        r   r"   zFormParser.parseM   sA   € ð
 (Ð-¨2ˆØ!×%Ò% jµ(Ô2JÑKÔKˆÝ˜Ÿš™œ°Ð:Ñ:Ô:Ð:r   r#   r$   r   r   r   r:   r:   G   s9   € € € € € ðð ð 5€Jð;ð ;ð ;ð ;ð ;ð ;r   r:   c                   ó   — e Zd ZdZdZdd„ZdS )r   zF
    Parser for multipart form data, which may include file data.
    zmultipart/form-dataNc                 óz  — |pi }|d         }|                      dt          j        ¦  «        }|j                             ¦   «         }||d<   |j        }	 t          ||||¦  «        }|                     ¦   «         \  }	}
t          |	|
¦  «        S # t          $ r$}t          dt          |¦  «        z  ¦  «        ‚d}~ww xY w)a	  
        Parses the incoming bytestream as a multipart encoded form,
        and returns a DataAndFiles object.

        `.data` will be a `QueryDict` containing all the form parameters.
        `.files` will be a `QueryDict` containing all the form files.
        Úrequestr)   ÚCONTENT_TYPEzMultipart form parse error - %sN)r+   r   r,   ÚMETAÚcopyÚupload_handlersÚDjangoMultiPartParserr"   r   r   r   r3   )r   r   r    r!   r?   r)   ÚmetarC   Úparserr   r   r5   s               r   r"   zMultiPartParser.parse]   sÌ   € ð (Ð-¨2ˆØ  Ô+ˆØ!×%Ò% jµ(Ô2JÑKÔKˆØŒ|× Ò Ñ"Ô"ˆØ)ˆˆ^ÑØ!Ô1ˆð	KÝ*¨4°¸È(ÑSÔSˆFØ Ÿ,š,™.œ.‰KˆD�%Ý  eÑ,Ô,Ð,øÝ#ð 	Kð 	Kð 	KÝÐ>ÅÀSÁÄÑIÑJÔJÐJøøøøð	Køøøs   Á8B Â
B:ÂB5Â5B:r#   r$   r   r   r   r   r   W   s?   € € € € € ðð ð '€JðKð Kð Kð Kð Kð Kr   r   c                   ó.   — e Zd ZdZdZdddœZd	d„Zd„ ZdS )
ÚFileUploadParserz&
    Parser for file upload data.
    z*/*zFFileUpload parse error - none of upload handlers can handle the streamz`Missing filename. Request should include a Content-Disposition header with a filename parameter.)Ú	unhandledÚno_filenameNc           	      óØ  — |pi }|d         }|                      dt          j        ¦  «        }|j        }|j        }|                      |||¦  «        }|st          | j        d         ¦  «        ‚|                      d|                      dd¦  «        ¦  «        }		 t          |                      d|                      dd	¦  «        ¦  «        ¦  «        }
n# t          t          f$ r d
}
Y nw xY w|D ]7}|                     |||
d
|¦  «        }|�t          i d|d         i¦  «        c S Œ8d„ |D ¦   «         }t          dg|z   ¦  «        }t          ||¦  «        }d	gt          |¦  «        z  }t!          |¦  «        D ]=\  }}	 |                     d
||	|
|¦  «         Œ # t$          $ r |d
|dz   …         }Y  nw xY w|D ]V}t!          |¦  «        D ]D\  }}t          |¦  «        }|                     |||         ¦  «        }||xx         |z  cc<   |€ nŒEŒWt!          |¦  «        D ]6\  }}|                     ||         ¦  «        }|�t          i d|i¦  «        c S Œ7t          | j        d         ¦  «        ‚)a  
        Treats the incoming bytestream as a raw file upload and returns
        a `DataAndFiles` object.

        `.data` will be None (we expect request body to be a file content).
        `.files` will be a `QueryDict` containing one 'file' element.
        r?   r)   rJ   ÚHTTP_CONTENT_TYPEr@   Ú ÚHTTP_CONTENT_LENGTHÚCONTENT_LENGTHr   NÚfileé   c                 ó*   — g | ]}|j         ¯	|j         ‘ŒS r   )Ú
chunk_size)Ú.0Úxs     r   ú
<listcomp>z*FileUploadParser.parse.<locals>.<listcomp>¥   s!   € ÐPÐPÐP¨1À1Ä<ÐP˜!œ,ÐPÐPÐPr   iüÿÿrI   )r+   r   r,   rA   rC   Úget_filenamer   ÚerrorsÚintr2   Ú	TypeErrorÚhandle_raw_inputr   Úminr   ÚlenÚ	enumerateÚnew_filer   Úreceive_data_chunkÚfile_complete)r   r   r    r!   r?   r)   rE   rC   ÚfilenameÚcontent_typeÚcontent_lengthÚhandlerÚresultÚpossible_sizesrS   ÚchunksÚcountersÚindexÚchunkÚchunk_lengthÚfile_objs                        r   r"   zFileUploadParser.parse~   s  € ð (Ð-¨2ˆØ  Ô+ˆØ!×%Ò% jµ(Ô2JÑKÔKˆØŒ|ˆØ!Ô1ˆØ×$Ò$ V¨Z¸ÑHÔHˆàð 	9Ý˜Tœ[¨Ô7Ñ8Ô8Ð8ð —x’xÐ 3Ø $§¢¨¸Ñ <Ô <ñ>ô >ˆð	"Ý  §¢Ð*?Ø*.¯(ª(Ð3CÀQÑ*GÔ*Gñ"Iô "Iñ Jô JˆNˆNøå�IÐ&ð 	"ð 	"ð 	"Ø!ˆNˆNˆNð	"øøøð 'ð 	=ð 	=ˆGØ×-Ò-¨fØ.2Ø.<Ø.2Ø.6ñ	8ô 8ˆFð
 Ð!Ý# B¨°¸´Ð(;Ñ<Ô<Ð<Ð<Ð<ð "ð QÐP°ÐPÑPÔPˆÝ˜+˜¨Ñ7Ñ8Ô8ˆ
Ý˜6 :Ñ.Ô.ˆØ�3�˜_Ñ-Ô-Ñ-ˆå'¨Ñ8Ô8ð 	ð 	‰NˆE�7ðØ× Ò   x°Ø!/°ñ;ô ;ð ;ð ;øå%ð ð ð Ø"1°*°5¸1±9°*Ô"=�Ø��ðøøøð ð 	ð 	ˆEÝ"+¨OÑ"<Ô"<ð ð ‘��wÝ" 5™zœz�Ø×2Ò2°5¸(À5¼/ÑJÔJ�Ø˜��” <Ñ/��‘Ø�=Ø�Eð !øõ (¨Ñ8Ô8ð 	<ð 	<‰NˆE�7Ø×,Ò,¨X°e¬_Ñ=Ô=ˆHØÐ#Ý# B¨°Ð(:Ñ;Ô;Ð;Ð;Ð;ð $õ ˜œ [Ô1Ñ2Ô2Ð2s$   Â7C ÃC'Ã&C'Å;FÆF0Æ/F0c                 óˆ  — t          j        t          ¦  «        5  |d         d         cddd¦  «         S # 1 swxY w Y   t          j        t          t          t          ¦  «        5  |d         j        }t          |d         ¦  «        \  }}d|v r|d         cddd¦  «         S |d         cddd¦  «         S # 1 swxY w Y   dS )z�
        Detects the uploaded file name. First searches a 'filename' url kwarg.
        Then tries to parse Content-Disposition header.
        Úkwargsrb   Nr?   ÚHTTP_CONTENT_DISPOSITIONz	filename*)Ú
contextlibÚsuppressÚKeyErrorÚAttributeErrorr2   rA   r	   )r   r   r    r!   rE   ÚdispositionÚparamss          r   rW   zFileUploadParser.get_filenameÁ   sa  € õ
 Ô ¥Ñ*Ô*ð 	8ð 	8Ø! (Ô+¨JÔ7ð	8ð 	8ð 	8ð 	8ñ 	8ô 	8ð 	8ð 	8ð 	8ð 	8ð 	8ð 	8øøøð 	8ð 	8ð 	8ð 	8õ Ô ¥µ½:ÑFÔFð 	&ð 	&Ø! )Ô,Ô1ˆDÝ"9¸$Ð?YÔ:ZÑ"[Ô"[ÑˆK˜Ø˜fÐ$Ð$Ø˜kÔ*ð		&ð 	&ð 	&ð 	&ñ 	&ô 	&ð 	&ð 	&ð
 ˜*Ô%ð	&ð 	&ð 	&ð 	&ñ 	&ô 	&ð 	&ð 	&ð 	&ð 	&ð 	&ð 	&øøøð 	&ð 	&ð 	&ð 	&ð 	&ð 	&s$   š5µ9¼9Á%1B7Â#B7Â7B;Â>B;r#   )r   r   r   r%   r    rX   r"   rW   r   r   r   rH   rH   t   s_   € € € € € ðð ð €Jà]Øyðð €Fð
A3ð A3ð A3ð A3ðF&ð &ð &ð &ð &r   rH   )r%   r-   rq   Údjango.confr   Údjango.core.files.uploadhandlerr   Údjango.httpr   Údjango.http.multipartparserr   r   rD   r   Údjango.utils.httpr	   Úrest_frameworkr
   Úrest_framework.exceptionsr   Úrest_framework.settingsr   Úrest_framework.utilsr   r   r   r'   r:   rH   r   r   r   ú<module>r€      s  ððð ð €€€Ø Ð Ð Ð à  Ð  Ð  Ð  Ð  Ð  Ø >Ð >Ð >Ð >Ð >Ð >Ø !Ð !Ð !Ð !Ð !Ð !Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1ð-ð -ð -ð -ð -ð -à <Ð <Ð <Ð <Ð <Ð <Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5à $Ð $Ð $Ð $Ð $Ð $Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø %Ð %Ð %Ð %Ð %Ð %ðð ð ð ð ñ ô ð ðBð Bð Bð Bð Bñ Bô Bð Bð Að Að Að Að A�ñ Aô Að Að.;ð ;ð ;ð ;ð ;�ñ ;ô ;ð ;ð Kð Kð Kð Kð K�jñ Kô Kð Kð:Z&ð Z&ð Z&ð Z&ð Z&�zñ Z&ô Z&ð Z&ð Z&ð Z&r   