ó
    pñ:iŒ8  ã                  óJ  • S r SSKJr  SSKrSSKJr  SSKJr  SSK	J
r
  SSKJr  SS	KJr  SS
KJr  \R"                  (       a  SSKJr  SSKJr  SSKJr   " S S\5      r " S S\5      r\4SS jjr " S S5      r " S S5      r " S S5      r " S S5      r " S S5      rg)a‹  
WSGI Protocol Linter
====================

This module provides a middleware that performs sanity checks on the
behavior of the WSGI server and application. It checks that the
:pep:`3333` WSGI spec is properly implemented. It also warns on some
common HTTP errors such as non-empty responses for 304 status codes.

.. autoclass:: LintMiddleware

:copyright: 2007 Pallets
:license: BSD-3-Clause
é    )ÚannotationsN)ÚTracebackType)Úurlparse)Úwarné   )ÚHeaders)Úis_entity_header)ÚFileWrapper)ÚStartResponse)ÚWSGIApplication)ÚWSGIEnvironmentc                  ó   • \ rS rSrSrSrg)ÚWSGIWarningé!   z Warning class for WSGI warnings.© N©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__static_attributes__r   ó    Ú[/srv/projetos/modelo_ml_acdoc/venv/lib/python3.13/site-packages/werkzeug/middleware/lint.pyr   r   !   ó   † Ü*r   r   c                  ó   • \ rS rSrSrSrg)ÚHTTPWarningé%   z Warning class for HTTP warnings.r   Nr   r   r   r   r   r   %   r   r   r   c           	     ó’   • [        U5      ULa9  [        U < SUR                  < S[        U5      R                  < S3[        SS9  g g )Nz
 requires z, got Ú.é   ©Ú
stacklevel)Útyper   r   r   )ÚcontextÚobjÚneeds      r   Ú
check_typer(   )   sH   € ÜˆCƒy˜ÒÜØ‰k˜ D§M¡MÑ#4°F¼4À»9×;MÑ;MÑ:PÐPQÐRÜØó	
ð r   c                  óF   • \ rS rSrS	S jrS
S jrS
S jrSS jrSS jrSr	g)ÚInputStreamé2   c                ó   • Xl         g ©N©Ú_stream©ÚselfÚstreams     r   Ú__init__ÚInputStream.__init__3   ó   € Ø�r   c                ó®   • [        U5      S:X  a  [        S[        SS9  O[        U5      S:w  a  [        S[        SS9  U R                  R                  " U6 $ )Nr   zŸWSGI does not guarantee an EOF marker on the input stream, thus making calls to 'wsgi.input.read()' unsafe. Conforming servers may never return from this call.r   r"   é   z2Too many parameters passed to 'wsgi.input.read()'.)Úlenr   r   r/   Úread©r1   Úargss     r   r9   ÚInputStream.read6   sW   € Üˆt‹9˜‹>Üð*ô Øóô �‹Y˜!‹^ÜØDÜØòð
 �|‰|× Ò  $Ð'Ð'r   c                óÆ   • [        U5      S:X  a  [        S[        SS9  O*[        U5      S:X  a  [        S[        SS9  O[        S5      eU R                  R
                  " U6 $ )Nr   z_Calls to 'wsgi.input.readline()' without arguments are unsafe. Use 'wsgi.input.read()' instead.r   r"   r7   z~'wsgi.input.readline()' was called with a size hint. WSGI does not support this, although it's available on all major servers.z5Too many arguments passed to 'wsgi.input.readline()'.)r8   r   r   Ú	TypeErrorr/   Úreadliner:   s     r   r?   ÚInputStream.readlineG   sd   € Üˆt‹9˜‹>Üð0äØó	ô �‹Y˜!‹^ÜðOäØó	ô ÐSÓTÐTØ�|‰|×$Ò$ dÐ+Ð+r   c                ó‚   •  [        U R                  5      $ ! [         a    [        S[        SS9  [        S5      s $ f = f)Nz'wsgi.input' is not iterable.r   r"   r   )Úiterr/   r>   r   r   ©r1   s    r   Ú__iter__ÚInputStream.__iter__Z   s;   € ð	Ü˜Ÿ™Ó%Ð%øÜó 	ÜÐ0´+È!ÒLÜ˜“8ŠOð	ús   ‚ —$>½>c                óV   • [        S[        SS9  U R                  R                  5         g )Nz(The application closed the input stream!r   r"   ©r   r   r/   ÚcloserC   s    r   rH   ÚInputStream.closea   ó    € ÜÐ7¼ÐQRÒSØ�‰×ÑÕr   r.   N)r2   zt.IO[bytes]ÚreturnÚNone)r;   út.AnyrK   Úbytes)rK   zt.Iterator[bytes]©rK   rL   )
r   r   r   r   r3   r9   r?   rD   rH   r   r   r   r   r*   r*   2   s   † ôô(ô",ô&÷r   r*   c                  óF   • \ rS rSrS	S jrS
S jrSS jrSS jrSS jrSr	g)ÚErrorStreaméf   c                ó   • Xl         g r-   r.   r0   s     r   r3   ÚErrorStream.__init__g   r5   r   c                ó\   • [        SU[        5        U R                  R                  U5        g )Nzwsgi.error.write())r(   Ústrr/   Úwrite©r1   Úss     r   rW   ÚErrorStream.writej   s!   € ÜÐ'¨¬CÔ0Ø�‰×Ñ˜1Õr   c                ó8   • U R                   R                  5         g r-   )r/   ÚflushrC   s    r   r\   ÚErrorStream.flushn   s   € Ø�‰×ÑÕr   c                ó8   • U H  nU R                  U5        M     g r-   )rW   )r1   ÚseqÚlines      r   Ú
writelinesÚErrorStream.writelinesq   s   € ÛˆDØ�J‰J�tÖò r   c                óV   • [        S[        SS9  U R                  R                  5         g )Nz(The application closed the error stream!r   r"   rG   rC   s    r   rH   ÚErrorStream.closeu   rJ   r   r.   N)r2   z	t.IO[str]rK   rL   )rY   rV   rK   rL   rO   )r_   zt.Iterable[str]rK   rL   )
r   r   r   r   r3   rW   r\   ra   rH   r   r   r   r   rQ   rQ   f   s   † ôôôô÷r   rQ   c                  ó(   • \ rS rSrSS jrSS jrSrg)ÚGuardedWriteéz   c                ó   • Xl         X l        g r-   )Ú_writeÚ_chunks)r1   rW   Úchunkss      r   r3   ÚGuardedWrite.__init__{   s   € ØŒØ�r   c                ó�   • [        SU[        5        U R                  U5        U R                  R	                  [        U5      5        g )Nzwrite())r(   rN   ri   rj   Úappendr8   rX   s     r   Ú__call__ÚGuardedWrite.__call__   s/   € Ü�9˜a¤Ô'Ø�‰�AŒØ�‰×ÑœC ›FÕ#r   )rj   ri   N)rW   zt.Callable[[bytes], object]rk   ú	list[int]rK   rL   )rY   rN   rK   rL   )r   r   r   r   r3   ro   r   r   r   r   rf   rf   z   s   † ô÷$r   rf   c                  óV   • \ rS rSr        S	S jrS
S jrSS jrSS jrSS jrSr	g)ÚGuardedIteratoré…   c                ój   • Xl         [        U5      R                  U l        SU l        X l        X0l        g )NF)Ú	_iteratorrB   Ú__next__Ú_nextÚclosedÚheaders_setrk   )r1   Úiteratorrz   rk   s       r   r3   ÚGuardedIterator.__init__†   s,   € ð "ŒÜ˜(“^×,Ñ,ˆŒ
ØˆŒØ&ÔØ�r   c                ó   • U $ r-   r   rC   s    r   rD   ÚGuardedIterator.__iter__’   s   € Øˆr   c                ó  • U R                   (       a  [        S[        SS9  U R                  5       nU R                  (       d  [        S[        SS9  [        SU[        5        U R                  R                  [        U5      5        U$ )Nz Iterated over closed 'app_iter'.r   r"   z8The application returned before it started the response.zapplication iterator items)
ry   r   r   rx   rz   r(   rN   rk   rn   r8   )r1   Úrvs     r   rw   ÚGuardedIterator.__next__•   se   € Ø�;�;ÜÐ3´[ÈQÒOà�Z‰Z‹\ˆà××ÜØJÜØòô 	Ð/°´UÔ;Ø�‰×Ñœ3˜r›7Ô#Øˆ	r   c                ó   • SU l         [        U R                  S5      (       a  U R                  R                  5         U R                  (       Ga   U R                  u  p[        U R                  5      nUR                  S[        S9nUS:X  aa  U HC  u  pVUR                  5       nUS;  d  M  [        U5      (       d  M/  [        SU< S3[        S	S
9  ME     U(       a  [        S[        S	S
9  g g SUs=::  a  S:  d  O  US:X  a3  US:w  a  [        U S3[        S	S
9  U(       a  [        U S3[        S	S
9  g g Ub  XC:w  a  [        S[        S	S
9  g g g g )NTrH   zcontent-length)r$   i0  )Úexpireszcontent-locationzEntity header z found in 304 response.r   r"   z#304 responses must not have a body.éd   éÈ   éÌ   r   z- responses must have an empty content length.z  responses must not have a body.zGContent-Length and the number of bytes sent to the client do not match.)ry   Úhasattrrv   rH   rz   Úsumrk   ÚgetÚintÚlowerr	   r   r   r   )r1   Ústatus_codeÚheadersÚ
bytes_sentÚcontent_lengthÚkeyÚ_values          r   rH   ÚGuardedIterator.close¦   s`  € ØˆŒä�4—>‘> 7×+Ñ+Ø�N‰N× Ñ Ô"à××ÐØ#'×#3Ñ#3Ñ ˆKÜ˜TŸ[™[Ó)ˆJØ$Ÿ[™[Ð)9Ä˜[ÐDˆNà˜cÓ!Û#*‘K�CØŸ)™)›+�CØÐ"AÕAÔFVØ÷Gó Gô Ø,¨S©GÐ3JÐKÜ'Ø'(ôñ $+ö ÜØ=Ü#Ø#$óð ð ˜Õ) cÕ)¨[¸CÓ-?Ø! QÓ&ÜØ&˜-Ð'TÐUÜ#Ø#$òö
 ÜØ&˜-Ð'GÐHÜ#Ø#$óð ð  Ñ+°Ó0LÜð,äØ ó	ð 1MÐ+ðG r   c                óh   • U R                   (       d   [        S[        SS9  g g ! [         a     g f = f)Nz4Iterator was garbage collected before it was closed.r   r"   )ry   r   r   Ú	ExceptionrC   s    r   Ú__del__ÚGuardedIterator.__del__×   s8   € Ø�{�{ðÜØJÜØ óð øô ó Ùðús   “$ ¤
1°1)rv   rx   rk   ry   rz   N)r{   út.Iterable[bytes]rz   útuple[int, Headers]rk   rq   rK   rL   )rK   rs   )rK   rN   rO   )
r   r   r   r   r3   rD   rw   rH   r•   r   r   r   r   rs   rs   …   sB   † ð
à#ð
ð )ð
ð ð	
ð
 
ô
ôôô"/÷b	r   rs   c                  ód   • \ rS rSrSrSS jrSS jr        SS jrSS jrSS jr	SS jr
S	rg
)ÚLintMiddlewareéã   a`  Warns about common errors in the WSGI and HTTP behavior of the
server and wrapped application. Some of the issues it checks are:

-   invalid status codes
-   non-bytes sent to the WSGI server
-   strings returned from the WSGI application
-   non-empty conditional responses
-   unquoted etags
-   relative URLs in the Location header
-   unsafe calls to wsgi.input
-   unclosed iterators

Error information is emitted using the :mod:`warnings` module.

:param app: The WSGI application to wrap.

.. code-block:: python

    from werkzeug.middleware.lint import LintMiddleware
    app = LintMiddleware(app)
c                ó   • Xl         g r-   ©Úapp)r1   rž   s     r   r3   ÚLintMiddleware.__init__ú   s   € Ø�r   c                ó–  • [        U5      [        La  [        S[        SS9  S H  nX!;  d  M
  [        SU< S3[        SS9  M      US   S	:w  a  [        S
[        SS9  UR	                  SS5      nUR	                  SS5      nU(       a  US   S:w  a  [        SU< 3[        SS9  U(       a  US   S:w  a  [        SU< 3[        SS9  g g g )Nz/WSGI environment is not a standard Python dict.é   r"   )	ÚREQUEST_METHODÚSERVER_NAMEÚSERVER_PORTúwsgi.versionú
wsgi.inputúwsgi.errorszwsgi.multithreadzwsgi.multiprocesszwsgi.run_oncezRequired environment key z
 not foundr!   r¥   )r7   r   z"Environ is not a WSGI 1.0 environ.ÚSCRIPT_NAMEÚ Ú	PATH_INFOr   Ú/z+'SCRIPT_NAME' does not start with a slash: z)'PATH_INFO' does not start with a slash: )r$   Údictr   r   r‰   )r1   Úenvironr�   Úscript_nameÚ	path_infos        r   Úcheck_environÚLintMiddleware.check_environý   sÞ   € Ü�‹=¤Ò$ÜØAÜØòó


ˆCð Õ!ÜØ/°©w°jÐAÜØ ôñ

ð" �>Ñ" fÓ,ÜÐ5´{ÈqÒQà—k‘k -°Ó4ˆØ—K‘K ¨RÓ0ˆ	æ˜; q™>¨SÓ0ÜØ=¸k¹_ÐMÜØòö ˜ 1™¨Ó,ÜØ;¸I¹=ÐIÜØóð -ˆ9r   c                óD  • [        SU[        5        UR                  S S5      S   n[        U5      S:w  d  UR	                  5       (       d  [        S[        SS9  [        U5      S:  d	  US   S:w  a  [        S	U< S
3[        SS9  [        U5      nUS:  a  [        S[        SS9  [        U5      [        La  [        S[        SS9  U H�  n[        U5      [        Ld  [        U5      S:w  a  [        S[        SS9  Uu  px[        U5      [        Ld  [        U5      [        La  [        S[        SS9  UR                  5       S:X  d  M€  [        S[        SS9  M‘     Ub$  [        U[        5      (       d  [        S[        SS9  [        U5      n	U R                  U	5        XY4$ )NÚstatusr7   r   r!   z!Status code must be three digits.r"   r¡   Ú zInvalid value for status zJ. Valid status strings are three digits, a space and a status explanation.r„   zStatus code < 100 detected.zHeader list is not a list.r   z#Header items must be 2-item tuples.z'Header keys and values must be strings.zFThe status header is not supported due to conflicts with the CGI spec.zInvalid value for exc_info.)r(   rV   Úsplitr8   Ú	isdecimalr   r   rŠ   r$   ÚlistÚtupler‹   Ú
isinstancer   Úcheck_headers)
r1   r³   r�   Úexc_infoÚstatus_code_strrŒ   ÚitemÚnameÚvalueÚheaders_objs
             r   Úcheck_start_responseÚ#LintMiddleware.check_start_response)  s}  € ô 	�8˜V¤SÔ)Ø Ÿ,™, t¨QÓ/°Ñ2ˆäˆÓ 1Ó$¨O×,EÑ,E×,GÑ,GÜÐ4´kÈaÒPäˆv‹;˜‹?˜f Q™i¨3Ó.ÜØ+¨F©:ð 6=ð =äØò	ô ˜/Ó*ˆà˜ÓÜÐ.´ÈÒJä�‹=¤Ò$ÜÐ-¬{ÀqÒIãˆDÜ�D‹z¤Ò&¬#¨d«)°q«.ÜÐ:¼KÐTUÒVØ‰KˆDÜ�D‹z¤Ò$¬¨U«¼3Ò(>ÜØ=¼{ÐWXòð �z‰z‹|˜xÕ'Üð4äØ ô	ñ ð  Ñ¬
°8¼U×(CÑ(CÜÐ.´ÈÒJä˜gÓ&ˆØ×Ñ˜;Ô'àÐ'Ð'r   c                ór  • UR                  S5      nUbd  UR                  S5      (       a*  UR                  S5      (       a  [        S[        SS9  USS  nUS S US	S  s=:X  a  S
:X  d  O  [        S[        SS9  UR                  S5      nUb+  [	        U5      R
                  (       d  [        S[        SS9  g g g )NÚetag)zW/úw/rÅ   z)Weak etag indicator should be upper case.r¡   r"   r   r7   éÿÿÿÿÚ"zUnquoted etag emitted.Úlocationz+Absolute URLs required for location header.)r‰   Ú
startswithr   r   r   Únetloc)r1   r�   rÄ   rÈ   s       r   rº   ÚLintMiddleware.check_headers]  sµ   € Ø�{‰{˜6Ó"ˆàÑØ�‰˜|×,Ñ,Ø—?‘? 4×(Ñ(ÜØCÜ#Ø#$òð ˜A˜B�x�à˜˜!�H  R S 	Õ0¨SÕ0ÜÐ-¬{ÀqÒIà—;‘;˜zÓ*ˆàÑÜ˜HÓ%×,×,ÜØAÜØ óð -ð  r   c                óN   • [        U[        5      (       a  [        S[        SS9  g g )Nz The application returned a string. The response will send one character at a time to the client, which will kill performance. Return a list or iterable instead.r!   r"   )r¹   rV   r   r   )r1   Úapp_iters     r   Úcheck_iteratorÚLintMiddleware.check_iteratorx  s)   € Ü�h¤×$Ñ$Üð6ô Øóð %r   c                óþ  ^ ^^^• [        U5      S:w  a  [        S[        SS9  U(       a  [        S[        SS9  US   nUS   mT R                  U5        [	        US   5      US'   [        US   5      US'   [        US	'   / m/ m      SUUU U4S
 jjnT R                  U[        R                  " SU5      5      nT R                  U5        [        U[        R                  " [        [        [        4   T5      T5      $ )Nr   zA WSGI app takes two arguments.r"   z+A WSGI app does not take keyword arguments.r   r7   r¦   r§   zwsgi.file_wrapperc                 ó  >• [        U 5      S;  a  [        S[        U 5       S3[        SS9  U(       a  [        S[        SS9  U S   nU S   n[        U 5      S	:X  a  U S   OS nTR                  X#U5      TS S & [	        T" X#U5      T5      $ )
N>   r   r!   zInvalid number of arguments: z, expected 2 or 3.r   r"   z1'start_response' does not take keyword arguments.r   r7   r!   )r8   r   r   rÁ   rf   )	r;   Úkwargsr³   r�   r»   rk   rz   r1   Ústart_responses	        €€€€r   Úchecking_start_responseÚ8LintMiddleware.__call__.<locals>.checking_start_response™  s    ø€ ô �4‹y Ó&ÜØ3´C¸³I°;Ð>PÐQÜØ òö ÜØGÜØ òð ˜q™'ˆFØ-1°!©WˆGô ˜t›9¨›>��Q’¨tð ð "×6Ñ6°vÈÓQˆK™ˆNÜ¡¨vÀÓ IÈ6ÓRÐRr   r   )r;   rM   rÒ   rM   rK   zt.Callable[[bytes], None])r8   r   r   r°   r*   rQ   r
   rž   ÚtÚcastrÎ   rs   r¸   rŠ   r   )	r1   r;   rÒ   r­   rÔ   rÍ   rk   rz   rÓ   s	   `     @@@r   ro   ÚLintMiddleware.__call__‚  s
  û€ Üˆt‹9˜‹>ÜÐ2´KÈAÒNæÜØ=¼{ÐWXòð $(¨¡7ˆØ(,¨Q©ˆà×Ñ˜7Ô#Ü +¨G°LÑ,AÓ Bˆ�ÑÜ!,¨W°]Ñ-CÓ!Dˆ�Ñô (3ˆÐ#Ñ$à#%ˆØˆð	SØð	SØ$)ð	Sà&÷	Sò 	Sð4 —8‘8˜G¤Q§V¢V¨OÐ=TÓ%UÓVˆØ×Ñ˜HÔ%ÜØ”a—f’fœU¤3¬ <Ñ0°+Ó>Àó
ð 	
r   r�   N)rž   r   rK   rL   )r­   r   rK   rL   )r³   rV   r�   zlist[tuple[str, str]]r»   z?None | tuple[type[BaseException], BaseException, TracebackType]rK   r˜   )r�   r   rK   rL   )rÍ   r—   rK   rL   )r;   rM   rÒ   rM   rK   r—   )r   r   r   r   r   r3   r°   rÁ   rº   rÎ   ro   r   r   r   r   rš   rš   ã   sN   † ñô,ô*ðX2(àð2(ð 'ð2(ð Tð	2(ð
 
ô2(ôhô6÷5
r   rš   )r%   rV   r&   Úobjectr'   r$   rK   rL   ) r   Ú
__future__r   ÚtypingrÖ   Útypesr   Úurllib.parser   Úwarningsr   Údatastructuresr   Úhttpr	   Úwsgir
   ÚTYPE_CHECKINGÚ_typeshed.wsgir   r   r   ÚWarningr   r   rV   r(   r*   rQ   rf   rs   rš   r   r   r   Ú<module>rå      sŽ   ðñõ #ã Ý Ý !Ý å $Ý #Ý à‡?‡?Ý,Ý.Ý.ô+�'ô +ô+�'ô +ð 8;ö 
÷1ñ 1÷hñ ÷($ñ $÷[ñ [÷|T
ò T
r   