ó
    ×›‘h(  ã                   ó  • S 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
JrJrJrJrJrJr  SSKJr   " S S	\5      r " S
 S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rg)z$
Tests for L{twisted.web.resource}.
é    )ÚTestCase)ÚUnsupportedMethod)ÚHeaders)ÚIRequest)Ú	FORBIDDENÚ	NOT_FOUNDÚResourceÚ_UnsafeErrorPageÚ_UnsafeForbiddenResourceÚ_UnsafeNoResourceÚgetChildForRequest)ÚDummyRequestc            
       ó|   • \ 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
\
S\S\SS4
S jrSS jrSS jrSS jrSrg)ÚErrorPageTestsé   zV
Tests for L{_UnafeErrorPage}, L{_UnsafeNoResource}, and
L{_UnsafeForbiddenResource}.
ÚreturnNc                 óž   • [        SSS5      nU R                  5       u  nU R                  US   [        5        U R	                  SUS   5        g)z‡
The public C{twisted.web.resource.ErrorPage} alias for the
corresponding C{_Unsafe} class produces a deprecation warning when
called.
é{   Úonozono!Úcategoryztwisted.web.pages.errorPageÚmessageN)Ú	ErrorPageÚflushWarningsÚassertEqualÚDeprecationWarningÚassertIn©ÚselfÚ_Úwarnings      ÚbC:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/web/test/test_resource.pyÚtest_deprecatedErrorPageÚ'ErrorPageTests.test_deprecatedErrorPage   sL   € ô �c˜5 &Ó)ˆØ×&Ñ&Ó(‰	ˆØ×Ñ˜ Ñ,Ô.@ÔAØ�‰Ð3°W¸YÑ5GÕHó    c                 ó˜   • [        5       nU R                  5       u  nU R                  US   [        5        U R	                  SUS   5        g)zˆ
The public C{twisted.web.resource.NoResource} alias for the
corresponding C{_Unsafe} class produces a deprecation warning when
called.
r   ztwisted.web.pages.notFoundr   N)Ú
NoResourcer   r   r   r   r   s      r!   Útest_deprecatedNoResourceÚ(ErrorPageTests.test_deprecatedNoResource)   sE   € ô ‹LˆØ×&Ñ&Ó(‰	ˆØ×Ñ˜ Ñ,Ô.@ÔAØ�‰Ð2°G¸IÑ4FÕGr$   c                 ó˜   • [        5       nU R                  5       u  nU R                  US   [        5        U R	                  SUS   5        g)zŽ
The public C{twisted.web.resource.ForbiddenResource} alias for the
corresponding C{_Unsafe} class produce a deprecation warning when
called.
r   ztwisted.web.pages.forbiddenr   N)ÚForbiddenResourcer   r   r   r   r   s      r!   Ú test_deprecatedForbiddenResourceÚ/ErrorPageTests.test_deprecatedForbiddenResource4   sF   € ô ÓˆØ×&Ñ&Ó(‰	ˆØ×Ñ˜ Ñ,Ô.@ÔAØ�‰Ð3°W¸YÑ5GÕHr$   c                 ór   • [        SSS5      nU R                  UR                  S[        5       5      U5        g)zR
The C{getChild} method of L{ErrorPage} returns the L{ErrorPage} it is
called on.
éA  ÚfooÚbars   nameN)r   ÚassertIdenticalÚgetChildÚobject)r   Úpages     r!   Útest_getChildÚErrorPageTests.test_getChild?   s/   € ô
 ˜˜e UÓ+ˆØ×Ñ˜TŸ]™]¨7´F³HÓ=¸tÕDr$   r4   ÚcodeÚbriefÚdetailc                 ó  • [        S/5      nSnXbX3U4-  nU R                  UR                  U5      UR                  S5      5        U R                  UR                  U5        U R                  UR
                  [        SS/05      5        g )Nr$   zg
<html>
  <head><title>%s - %s</title></head>
  <body>
    <h1>%s</h1>
    <p>%s</p>
  </body>
</html>
zutf-8s   content-types   text/html; charset=utf-8)r   r   ÚrenderÚencodeÚresponseCodeÚresponseHeadersr   )r   r4   r7   r8   r9   ÚrequestÚtemplateÚexpecteds           r!   Ú_pageRenderingTestÚ!ErrorPageTests._pageRenderingTestG   s‹   € ô  ˜uÓ%ˆðð 	ð  U°6Ð:Ñ:ˆØ×Ñ˜Ÿ™ WÓ-¨x¯©¸wÓ/GÔHØ×Ñ˜×-Ñ-¨tÔ4Ø×ÑØ×#Ñ#Ü�_Ð'BÐ&CÐDÓEõ	
r$   c                 óL   • SnSnSn[        XU5      nU R                  XAX#5        g)zÞ
L{ErrorPage.render} returns a C{bytes} describing the error defined by
the response code and message passed to L{ErrorPage.__init__}.  It also
uses that response code to set the response code on the L{Request}
passed in.
r.   zbrief description textzmuch longer text might go hereN)r   rB   )r   r7   r8   r9   r4   s        r!   Útest_errorPageRenderingÚ&ErrorPageTests.test_errorPageRendering]   s/   € ð ˆØ(ˆØ1ˆÜ˜ fÓ-ˆØ×Ñ ¨EÕ:r$   c                 óN   • Sn[        U5      nU R                  U[        SU5        g)z0
L{NoResource} sets the HTTP I{NOT FOUND} code.
zlong messagezNo Such ResourceN)r&   rB   r   ©r   r9   r4   s      r!   Útest_noResourceRenderingÚ'ErrorPageTests.test_noResourceRenderingj   s(   € ð  ˆÜ˜&Ó!ˆØ×Ñ ¤iÐ1CÀVÕLr$   c                 óN   • Sn[        U5      nU R                  U[        SU5        g)z7
L{ForbiddenResource} sets the HTTP I{FORBIDDEN} code.
zlonger messagezForbidden ResourceN)r*   rB   r   rH   s      r!   Útest_forbiddenResourceRenderingÚ.ErrorPageTests.test_forbiddenResourceRenderingr   s(   € ð "ˆÜ  Ó(ˆØ×Ñ ¤iÐ1EÀvÕNr$   © ©r   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r"   r'   r+   r5   r	   ÚintÚstrrB   rE   rI   rL   Ú__static_attributes__rN   r$   r!   r   r      s]   † ñô
	Iô	Hô	IôEð
Øð
Ø$'ð
Ø03ð
Ø=@ð
à	ô
ô,;ôM÷Or$   r   c                   ó.   • \ rS rSrSrS\S\SS4S jrSrg)	ÚDynamicChildr   z?
A L{Resource} to be created on the fly by L{DynamicChildren}.
Úpathr?   r   Nc                 óH   • [         R                  " U 5        Xl        X l        g ©N)r	   Ú__init__rZ   r?   ©r   rZ   r?   s      r!   r]   ÚDynamicChild.__init__€   s   € Ü×Ò˜$ÔØŒ	Ø�r$   )rZ   r?   )	rP   rQ   rR   rS   rT   Úbytesr   r]   rW   rN   r$   r!   rY   rY   {   s!   † ñð˜Uð ¨Xð ¸$÷ r$   rY   c                   ó.   • \ rS rSrSrS\S\S\4S jrSr	g)	ÚDynamicChildrené†   z&
A L{Resource} with dynamic children.
rZ   r?   r   c                 ó   • [        X5      $ r\   )rY   r^   s      r!   r2   ÚDynamicChildren.getChild‹   s   € Ü˜DÓ*Ð*r$   rN   N)
rP   rQ   rR   rS   rT   r`   r   rY   r2   rW   rN   r$   r!   rb   rb   †   s!   † ñð+˜Uð +¨Xð +¸,÷ +r$   rb   c                   ó<   • \ rS rSrSrS\SS4S jrS\S\4S jrS	r	g)
ÚBytesReturnedRenderableé�   z?
A L{Resource} with minimal capabilities to render a response.
Úresponser   Nc                 ó<   • [         R                  " U 5        Xl        g)zW
@param response: A C{bytes} object giving the value to return from
    C{render_GET}.
N)r	   r]   Ú	_response)r   ri   s     r!   r]   Ú BytesReturnedRenderable.__init__”   s   € ô
 	×Ò˜$ÔØ!�r$   r?   c                 ó   • U R                   $ )ze
Render a response to a I{GET} request by returning a short byte string
to be written by the server.
©rk   ©r   r?   s     r!   Ú
render_GETÚ"BytesReturnedRenderable.render_GETœ   s   € ð
 �~‰~Ðr$   rn   )
rP   rQ   rR   rS   rT   r`   r]   r3   rp   rW   rN   r$   r!   rg   rg   �   s-   † ñð" ð "¨4ô "ð &ð ¨U÷ r$   rg   c                   ó<   • \ rS rSrSrS\SS4S jrS\SS4S jrSrg)	ÚImplicitAllowedMethodsé¤   zb
A L{Resource} which implicitly defines its allowed methods by defining
renderers to handle them.
r?   r   Nc                 ó   • g r\   rN   ro   s     r!   rp   Ú!ImplicitAllowedMethods.render_GETª   ó   € Ør$   c                 ó   • g r\   rN   ro   s     r!   Ú
render_PUTÚ!ImplicitAllowedMethods.render_PUT­   rw   r$   rN   )	rP   rQ   rR   rS   rT   r3   rp   ry   rW   rN   r$   r!   rs   rs   ¤   s-   † ñð
 &ð ¨Tô ð &ð ¨T÷ r$   rs   c                   óT   • \ 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)ÚResourceTestsé±   z
Tests for L{Resource}.
Nc           	      óÜ   • [        5       n[        5       n[        5       nUR                  SU5        UR                  SU5        U R                  X!R                  S[	        / 5      5      5        g)z�
L{Resource.putChild} adds a I{static} child to the resource.  That child
is returned from any call to L{Resource.getChildWithDefault} for the
child's path.
ó   fooó   barN)r	   ÚputChildr1   ÚgetChildWithDefaultr   ©r   ÚresourceÚchildÚsiblings       r!   Útest_staticChildrenÚ!ResourceTests.test_staticChildren¶   s\   € ô “:ˆÜ“
ˆÜ“*ˆØ×Ñ˜& %Ô(Ø×Ñ˜& 'Ô*Ø×ÑØ×/Ñ/°¼ÀRÓ8HÓIõ	
r$   c                 óð   • Sn[        / 5      n[        5       nUR                  X5      nU R                  U[        5        U R                  UR                  U5        U R                  UR                  U5        g)z„
L{Resource.getChildWithDefault} delegates to L{Resource.getChild} when
the requested path is not associated with any static child.
r   N)	r   rb   r‚   ÚassertIsInstancerY   r   rZ   r1   r?   )r   rZ   r?   r„   r…   s        r!   Útest_dynamicChildrenÚ"ResourceTests.test_dynamicChildrenÅ   sc   € ð
 ˆÜ˜rÓ"ˆÜ"Ó$ˆØ×,Ñ,¨TÓ;ˆØ×Ñ˜e¤\Ô2Ø×Ñ˜Ÿ™ TÔ*Ø×Ñ˜UŸ]™]¨GÕ4r$   c                 óÈ   • [        5       n[        5       n[        5       nU R                  [        UR                  SU5        U R                  [        UR                  SU5        g)z^
Test that passing the wrong type to putChild results in a warning,
and a failure in Python 3
r/   N)r	   ÚassertRaisesÚ	TypeErrorr�   rƒ   s       r!   Útest_staticChildPathTypeÚ&ResourceTests.test_staticChildPathTypeÒ   sM   € ô
 “:ˆÜ“
ˆÜ“*ˆØ×Ñœ) X×%6Ñ%6¸¸uÔEØ×Ñœ) X×%6Ñ%6¸¸gÕFr$   c                 ó‚   • Sn[        / 5      nSUl        [        U5      nU R                  XR	                  U5      5        g)zl
When not otherwise overridden, L{Resource.render} treats a I{HEAD}
request as if it were a I{GET} request.
s   insert response hereó   HEADN)r   Úmethodrg   r   r;   )r   rA   r?   r„   s       r!   Útest_defaultHEADÚResourceTests.test_defaultHEADÝ   s;   € ð
 +ˆÜ˜rÓ"ˆØ ˆŒÜ*¨8Ó4ˆØ×Ñ˜§?¡?°7Ó#;Õ<r$   c                 óî   • / SQn[        5       nXl        [        / 5      nSUl        U R	                  [
        UR                  U5      nU R                  [        U5      [        UR                  5      5        g)zÒ
The L{UnsupportedMethod} raised by L{Resource.render} for an unsupported
request method has a C{allowedMethods} attribute set to the value of the
C{allowedMethods} attribute of the L{Resource}, if it has one.
)ó   GETr“   ó   PUTó	   FICTIONALN)	r	   ÚallowedMethodsr   r”   rŽ   r   r;   r   Úset©r   rA   r„   r?   Úexcs        r!   Útest_explicitAllowedMethodsÚ)ResourceTests.test_explicitAllowedMethodsè   s_   € ò -ˆÜ“:ˆØ"*ÔÜ˜rÓ"ˆØ%ˆŒØ×ÑÔ 1°8·?±?ÀGÓLˆØ×Ñœ˜X›¬¨C×,>Ñ,>Ó(?Õ@r$   c                 óÐ   • 1 Skn[        5       n[        / 5      nSUl        U R                  [        UR
                  U5      nU R                  U[        UR                  5      5        g)a<  
The L{UnsupportedMethod} raised by L{Resource.render} for an unsupported
request method has a C{allowedMethods} attribute set to a list of the
methods supported by the L{Resource}, as determined by the
I{render_}-prefixed methods which it defines, if C{allowedMethods} is
not explicitly defined by the L{Resource}.
>   r˜   r™   r“   rš   N)	rs   r   r”   rŽ   r   r;   r   rœ   r›   r�   s        r!   Útest_implicitAllowedMethodsÚ)ResourceTests.test_implicitAllowedMethodsö   sV   € ò -ˆÜ)Ó+ˆÜ˜rÓ"ˆØ%ˆŒØ×ÑÔ 1°8·?±?ÀGÓLˆØ×Ñ˜¤3 s×'9Ñ'9Ó#:Õ;r$   rN   rO   )rP   rQ   rR   rS   rT   r‡   r‹   r�   r•   rŸ   r¢   rW   rN   r$   r!   r|   r|   ±   s'   † ñô
ô5ô	Gô	=ôA÷<r$   r|   c                   ó6   • \ rS rSrSrSS jrSS jrSS jrSrg)	ÚGetChildForRequestTestsi  z"
Tests for L{getChildForRequest}.
Nc                 óf   • [        / 5      n[        5       n[        X!5      nU R                  X#5        g)zr
L{getChildForRequest} returns whatever resource has been reached by the
time the request's C{postpath} is empty.
N)r   r	   r   r1   ©r   r?   r„   Úresults       r!   Útest_exhaustedPostPathÚ.GetChildForRequestTests.test_exhaustedPostPath  s-   € ô
 ˜rÓ"ˆÜ“:ˆÜ# HÓ6ˆØ×Ñ˜XÕ.r$   c                 óx   • [        SS/5      n[        5       nSUl        [        X!5      nU R	                  X#5        g)zk
L{getChildForRequest} returns the first resource it encounters with a
C{isLeaf} attribute set to C{True}.
r   r€   TN)r   r	   ÚisLeafr   r1   r§   s       r!   Útest_leafResourceÚ)GetChildForRequestTests.test_leafResource  s9   € ô
  ¨Ð/Ó0ˆÜ“:ˆØˆŒÜ# HÓ6ˆØ×Ñ˜XÕ.r$   c                 ó"  • [        SS/5      n[        5       n[        5       nSUl        UR                  SU5        U R	                  U[        X!5      5        U R                  UR                  S/5        U R                  UR                  S/5        g)zk
As path segments from the request are traversed, they are taken from
C{postpath} and put into C{prepath}.
r   r€   TN)	r   r	   r¬   r�   r1   r   r   ÚprepathÚpostpath)r   r?   Úrootr…   s       r!   Útest_postPathToPrePathÚ.GetChildForRequestTests.test_postPathToPrePath   sz   € ô
  ¨Ð/Ó0ˆÜ‹zˆÜ“
ˆØˆŒØ�‰�f˜eÔ$Ø×Ñ˜UÔ$6°tÓ$EÔFØ×Ñ˜Ÿ™¨6¨(Ô3Ø×Ñ˜×)Ñ)¨F¨8Õ4r$   rN   rO   )	rP   rQ   rR   rS   rT   r©   r­   r³   rW   rN   r$   r!   r¥   r¥     s   † ñô/ô	/÷5r$   r¥   N)rT   Útwisted.trial.unittestr   Útwisted.web.errorr   Útwisted.web.http_headersr   Útwisted.web.iwebr   Útwisted.web.resourcer   r   r	   r
   r   r   r*   r   r&   r   Útwisted.web.test.requesthelperr   r   rY   rb   rg   rs   r|   r¥   rN   r$   r!   Ú<module>r»      sˆ   ðñõ ,Ý /Ý ,Ý %÷÷ ñ õ 8ô`O�Xô `OôF�8ô ô+�hô +ô˜hô ô*
˜Xô 
ôR<�Hô R<ôj&5˜hõ &5r$   