;i=NddlmZddlZddlmZddlmZddlm Z ddl m Z ddl m Z dd l m Z dd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZ ddlmZn#e$r ddlmZdZYnwxYwej rCddlZ!ddl"m#Z#e$ej%e&e e'e'fe e'e ffZ(Gdde!j)Z*ej+dej,dej-fZ. d>d?d$Z/ d@dd&dAd3Z0Gd4d5Z1Gd6d7Z2dBd=Z3dS)C) annotationsN)BytesIO) parse_qsl) _plain_int) FileStorage)Headers) MultiDict)RequestEntityTooLarge)parse_options_header)Data)Epilogue)Field)File)MultipartDecoder)NeedData)get_content_length)get_input_stream)SpooledTemporaryFile) TemporaryFile)WSGIEnvironmentceZdZ d d d ZdS) TStreamFactoryNtotal_content_length int | None content_type str | Nonefilenamecontent_lengthreturn t.IO[bytes]cdSN)selfrrrrs GC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\werkzeug/formparser.py__call__zTStreamFactory.__call__)s #r# rrrrrrrrr r!)__name__ __module__ __qualname__r'r$r(r&rr(s2 *.        r(rF.)boundrrrrrrr r!c d}t9tjtjtt|dS|||kr7tjtjtt dSt S)Nizrb+)max_sizemode)rtcastIObytesrr)rrrrr0s r&default_stream_factoryr65sq H'vad5k#7PU#V#V#VWWW  %)=)H)Hvad5k=#7#7888 99r(Tmax_form_partsenvironrstream_factoryTStreamFactory | Nonemax_form_memory_sizemax_content_lengthcls"type[MultiDict[str, t.Any]] | Nonesilentboolr8t_parse_resultcRt|||||||S)aParse the form data in the environ and return it as tuple in the form ``(stream, form, files)``. You should only call this method if the transport method is `POST`, `PUT`, or `PATCH`. If the mimetype of the data transmitted is `multipart/form-data` the files multidict will be filled with `FileStorage` objects. If the mimetype is unknown the input stream is wrapped and returned as first argument, else the stream is empty. This is a shortcut for the common usage of :class:`FormDataParser`. :param environ: the WSGI environment to be used for parsing. :param stream_factory: An optional callable that returns a new read and writeable file descriptor. This callable works the same as :meth:`Response._get_file_stream`. :param max_form_memory_size: the maximum number of bytes to be accepted for in-memory stored form data. If the data exceeds the value specified an :exc:`~exceptions.RequestEntityTooLarge` exception is raised. :param max_content_length: If this is provided and the transmitted data is longer than this value an :exc:`~exceptions.RequestEntityTooLarge` exception is raised. :param cls: an optional dict class to use. If this is not specified or `None` the default :class:`MultiDict` is used. :param silent: If set to False parsing errors will not be caught. :param max_form_parts: The maximum number of multipart parts to be parsed. If this is exceeded, a :exc:`~exceptions.RequestEntityTooLarge` exception is raised. :return: A tuple in the form ``(stream, form, files)``. .. versionchanged:: 3.0 The ``charset`` and ``errors`` parameters were removed. .. versionchanged:: 2.3 Added the ``max_form_parts`` parameter. .. versionadded:: 0.5.1 Added the ``silent`` parameter. .. versionadded:: 0.5 Added the ``max_form_memory_size``, ``max_content_length``, and ``cls`` parameters. )r:r<r=r8r@r>)FormDataParserparse_from_environ)r9r:r<r=r>r@r8s r&parse_form_datarFEs>l %1-%     !!"r(cPeZdZdZ d!ddd"dZd#dZ d$d%dZd&dZd&d ZdS)'rDaThis class implements parsing of form data for Werkzeug. By itself it can parse multipart and url encoded form data. It can be subclassed and extended but for most mimetypes it is a better idea to use the untouched stream and expose it as separate attributes on a request object. :param stream_factory: An optional callable that returns a new read and writeable file descriptor. This callable works the same as :meth:`Response._get_file_stream`. :param max_form_memory_size: the maximum number of bytes to be accepted for in-memory stored form data. If the data exceeds the value specified an :exc:`~exceptions.RequestEntityTooLarge` exception is raised. :param max_content_length: If this is provided and the transmitted data is longer than this value an :exc:`~exceptions.RequestEntityTooLarge` exception is raised. :param cls: an optional dict class to use. If this is not specified or `None` the default :class:`MultiDict` is used. :param silent: If set to False parsing errors will not be caught. :param max_form_parts: The maximum number of multipart parts to be parsed. If this is exceeded, a :exc:`~exceptions.RequestEntityTooLarge` exception is raised. .. versionchanged:: 3.0 The ``charset`` and ``errors`` parameters were removed. .. versionchanged:: 3.0 The ``parse_functions`` attribute and ``get_parse_func`` methods were removed. .. versionchanged:: 2.2.3 Added the ``max_form_parts`` parameter. .. versionadded:: 0.8 NTr7r:r;r<rr=r>r?r@rAr8r Nonec|t}||_||_||_||_|t jdt}||_||_ dSNztype[MultiDict[str, t.Any]]) r6r:r<r=r8r2r3r r>r@)r%r:r<r=r>r@r8s r&__init__zFormDataParser.__init__sX  !3N,$8!"4, ;&6 BBC r(r9rrBct||j}t|}t|d\}}|||||S)zParses the information from the environment as form data. :param environ: the WSGI environment to be used for parsing. :return: A tuple in the form ``(stream, form, files)``. )r= CONTENT_TYPE)rmimetypeoptions)rr=rr getparse)r%r9streamrrNrOs r&rEz!FormDataParser.parse_from_environsk "'d>UVVV+G440^1L1LMM'zz )    r(rRr!rNstrrrOdict[str, str] | Nonec4|dkr|j}n7|dkr|j}n)|||fS|i} |||||S#t$r |jsYnwxYw|||fS)avParses the information from the given stream, mimetype, content length and mimetype parameters. :param stream: an input stream :param mimetype: the mimetype of the data :param content_length: the content length of the incoming data :param options: optional mimetype parameters (used for the multipart boundary for instance) :return: A tuple in the form ``(stream, form, files)``. .. versionchanged:: 3.0 The invalid ``application/x-url-encoded`` content type is not treated as ``application/x-www-form-urlencoded``. zmultipart/form-dataz!application/x-www-form-urlencoded)_parse_multipart_parse_urlencodedr> ValueErrorr@)r%rRrNrrO parse_funcs r&rQzFormDataParser.parses* , , ,.JJ < < </JJ488::txxzz1 1 ?G :fhHH H   ;    txxzz488::--s AA.-A.dict[str, str]ct|j|j|j|j}|ddd}|std||||\}}|||fS)N)r:r<r8r>boundaryasciizMissing boundary) MultiPartParserr:r<r8r>rPencoderXrQ) r%rRrNrrOparserr\formfiless r&rVzFormDataParser._parse_multiparts!.!%!:.     ;;z2..55g>> 1/00 0ll68^DD etU""r(c|j|||jkrtt|dd}||||fS)NTzwerkzeug.url_quote)keep_blank_valueserrors)r<r rreaddecoder>)r%rRrNrrOitemss r&rWz FormDataParser._parse_urlencodeds  % 1*!:::')) ) KKMM " ""'    txx 22r(NNNNT)r:r;r<rr=rr>r?r@rAr8rr rH)r9rr rBr#) rRr!rNrSrrrOrTr rB) rRr!rNrSrrrOrZr rB) r*r+r,__doc__rKrErQrVrWr$r(r&rDrDs""L15+/)-26 &*0    **. %.%.%.%.%.N####*333333r(rDcBeZdZ d!d"dZd#dZd$dZd%dZd&d ZdS)'r_Nr:r;r<rr>r? buffer_sizeintr8r rHc||_||_|t}||_|t jdt }||_||_dSrJ) r<r8r6r:r2r3r r>rn)r%r:r<r>rnr8s r&rKzMultiPartParser.__init__%sS%9!,  !3N, ;&6 BBC&r(messagerS te.NoReturnc t|r#)rX)r%rqs r&failzMultiPartParser.fail;s!!!r(headersr c|d}|rCt|d}|dd}|dvr|SdS)N content-typercharsetr]>us-ascii iso-8859-1r^utf-8r{)rPr lower)r%rur parameters ct_charsets r&get_part_charsetz MultiPartParser.get_part_charset>se{{>22  "-l;;A>J# 266<<>>JIII!!wr(eventrrr!c|jd} t|jd}n#ttf$rd}YnwxYw|||j||}|S)Nrwzcontent-lengthr)rrrr)rurPrKeyErrorrXr:r)r%rrrr containers r&start_file_streamingz$MultiPartParser.start_file_streamingMs}((88  ' 6F(GHHNN*%   NNN ''!5^%) (  s7A  A rRr\r5r7tuple[MultiDict[str, str], MultiDict[str, FileStorage]]c &d}t||j|j}g}g}t|j|jD]*}|||} t| ttfst| tr| } d}g} | j } nt| tr#| } d}|| |} | j} nTt| t r>|j2|0|t#| jz }||jkrt'| | j| jst| tr^d| || jd} | | j| fn{t5jt4jt:| } | d| | jt?| | j | j| jf|} t| ttf,|!||!|fS)N)r< max_partsrr(replace)ru)"rr<r8 _chunk_iterrgrn receive_data next_event isinstancerrrappendrrwriter lendatar more_datajoinrhrrunamer2r3r4r5seekrrr>)r%rRr\r field_sizerafieldsrcrr current_partr_writevalues r&rQzMultiPartParser.parse_s"& " !%!:)     T-=>>- ,- ,D    % % %%%''E 8(<==* ,eU++'#(L!"J "I&-FFt,,"#(L!%J $ 9 9% P PI&_FFt,,0<AW#c%*oo5 %(AAA"7"9"99F5:&&& ?%lE::$'HHY$7$7$>$> $ 5 5l6J K KY%%E#MM<+r?rnror8rr rH)rqrSr rr)rur r rS)rrrrr r!)rRr!r\r5rrr r)r*r+r,rKrtrrrQr$r(r&r_r_$s15+/26$%) ''''',""""    $@1@1@1@1@1@1r(r_rgt.Callable[[int], bytes]sizerot.Iterator[bytes | None]c#:K ||}|sn|VdVdS)zRead data in chunks for multipart/form-data parsing. Stop if no data is read. Yield ``None`` at the end to signal end of parsing. TNr$)rgrrs r&rrs@tDzz    JJJJJr(r#r)rj)r9rr:r;r<rr=rr>r?r@rAr8rr rB)rgrrror r)4 __future__rtypingr2ior urllib.parser _internalrdatastructuresrr r exceptionsr httpr sansio.multipartr rrrrrwsgirrtempfiler ImportErrorr TYPE_CHECKINGte_typeshed.wsgirtupler4r5rSrBProtocolrTypeVarCallableAnyr-r6rFrDr_rr$r(r&rs""""""""""""!!!!!!''''''######%%%%%%------&&&&&&""""""&&&&&&######""""""......&&&&&&$$$$$$"""""" -------   &&&&&& ?...... U YsCx()C4D*EENAIcCJ/000"&     $-1'+%).2 =""&="="="="="="@\3\3\3\3\3\3\3\3~{1{1{1{1{1{1{1{1|      s,A33 BB