§
    ÉtºfŸ  ã                   ó¢   — d 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mZ ddlmZ dd	lmZ  G d
„ de¦  «        Z G d„ de¦  «        ZdS )z"
Tests for L{twisted.web.script}.
é    N)Údefer)ÚFilePath)ÚTestCase)Ú	NOT_FOUND)ÚPythonScriptÚResourceScriptDirectory)Ú_render)ÚDummyRequestc                   óx   — e Zd ZdZdej        d         fd„Zdej        d         fd„Zdej        d         fd„ZdS )ÚResourceScriptDirectoryTestsz/
    Tests for L{ResourceScriptDirectory}.
    ÚreturnNc                 óÒ   ‡ ‡— t          ‰                      ¦   «         ¦  «        }t          dg¦  «        Št          |‰¦  «        }dt          ddfˆˆ fd„}|                     |¦  «        S )zh
        L{ResourceScriptDirectory.render} sets the HTTP response code to I{NOT
        FOUND}.
        ó    Úignoredr   Nc                 óH   •— ‰                      ‰j        t          ¦  «         d S ©N©ÚassertEqualÚresponseCoder   ©r   ÚrequestÚselfs    €€ú[/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/web/test/test_script.pyÚ
cbRenderedzDResourceScriptDirectoryTests.test_renderNotFound.<locals>.cbRendered!   ó"   ø€ Ø×Ò˜WÔ1µ9Ñ=Ô=Ð=Ð=Ð=r   )r   Úmktempr
   r	   ÚobjectÚaddCallback©r   ÚresourceÚdr   r   s   `   @r   Útest_renderNotFoundz0ResourceScriptDirectoryTests.test_renderNotFound   s~   øø€ õ
 +¨4¯;ª;©=¬=Ñ9Ô9ˆÝ ˜uÑ%Ô%ˆÝ�H˜gÑ&Ô&ˆð	>¥ð 	>¨4ð 	>ð 	>ð 	>ð 	>ð 	>ð 	>ð 	>ð �}Š}˜ZÑ(Ô(Ð(r   c                 ó*  ‡ ‡— ‰                       ¦   «         }t          j        |¦  «         t          |¦  «        }t	          dg¦  «        Š|                     d‰¦  «        }t          |‰¦  «        }dt          ddfˆˆ fd„}|                     |¦  «        S )a  
        L{ResourceScriptDirectory.getChild} returns a resource which renders an
        response with the HTTP I{NOT FOUND} status code if the indicated child
        does not exist as an entry in the directory used to initialized the
        L{ResourceScriptDirectory}.
        s   fooÚfoor   r   Nc                 óH   •— ‰                      ‰j        t          ¦  «         d S r   r   r   s    €€r   r   zCResourceScriptDirectoryTests.test_notFoundChild.<locals>.cbRendered4   r   r   )	r   ÚosÚmakedirsr   r
   ÚgetChildr	   r   r   )r   Úpathr    Úchildr!   r   r   s   `     @r   Útest_notFoundChildz/ResourceScriptDirectoryTests.test_notFoundChild&   s¨   øø€ ð �{Š{‰}Œ}ˆÝ
Œ�DÑÔÐÝ*¨4Ñ0Ô0ˆÝ ˜xÑ(Ô(ˆØ×!Ò! %¨Ñ1Ô1ˆÝ�E˜7Ñ#Ô#ˆð	>¥ð 	>¨4ð 	>ð 	>ð 	>ð 	>ð 	>ð 	>ð 	>ð �}Š}˜ZÑ(Ô(Ð(r   c                 ó¸  ‡ ‡— t          ‰                      ¦   «         ¦  «        }|                     ¦   «          |                     d¦  «                             d¦  «         t          |                     ¦   «         ¦  «        }t          dg¦  «        Š|                     d‰¦  «        }t          |‰¦  «        }dt          ddfˆˆ fd„}|                     |¦  «        S )	ú¿
        L{ResourceScriptDirectory.getChild} returns a resource which renders a
        response with the HTTP 200 status code and the content of the rpy's
        C{request} global.
        ztest.rpys¬   
from twisted.web.resource import Resource
class TestResource(Resource):
    isLeaf = True
    def render_GET(self, request):
        return b'ok'
resource = TestResource()r   s   test.rpyr   r   Nc                 ód   •— ‰                      d                     ‰j        ¦  «        d¦  «         d S )Nr   s   ok)r   ÚjoinÚwrittenr   s    €€r   r   z<ResourceScriptDirectoryTests.test_render.<locals>.cbRenderedO   s-   ø€ Ø×Ò˜SŸXšX g¤oÑ6Ô6¸Ñ>Ô>Ð>Ð>Ð>r   )r   r   r'   r*   Ú
setContentr   Ú_asBytesPathr
   r(   r	   r   r   )r   Útmpr    r*   r!   r   r   s   `     @r   Útest_renderz(ResourceScriptDirectoryTests.test_render9   sä   øø€ õ �t—{’{‘}”}Ñ%Ô%ˆØ�Š‰ŒˆØ�	Š	�*ÑÔ×(Ò(ðñ	
ô 	
ð 	
õ +¨3×+;Ò+;Ñ+=Ô+=Ñ>Ô>ˆÝ ˜uÑ%Ô%ˆØ×!Ò! +¨wÑ7Ô7ˆÝ�E˜7Ñ#Ô#ˆð	?¥ð 	?¨4ð 	?ð 	?ð 	?ð 	?ð 	?ð 	?ð 	?ð �}Š}˜ZÑ(Ô(Ð(r   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚDeferredr"   r+   r4   © r   r   r   r      s„   € € € € € ðð ð) U¤^°DÔ%9ð )ð )ð )ð )ð) E¤N°4Ô$8ð )ð )ð )ð )ð&)˜Uœ^¨DÔ1ð )ð )ð )ð )ð )ð )r   r   c                   óV   — e Zd ZdZdej        d         fd„Zdej        d         fd„ZdS )ÚPythonScriptTestsz$
    Tests for L{PythonScript}.
    r   Nc                 óÔ   ‡ ‡— t          ‰                      ¦   «         d¦  «        }t          dg¦  «        Št          |‰¦  «        }dt          ddfˆˆ fd„}|                     |¦  «        S )z¥
        If the source file a L{PythonScript} is initialized with doesn't exist,
        L{PythonScript.render} sets the HTTP response code to I{NOT FOUND}.
        Nr   r   r   c                 óH   •— ‰                      ‰j        t          ¦  «         d S r   r   r   s    €€r   r   z9PythonScriptTests.test_notFoundRender.<locals>.cbRenderedc   r   r   )r   r   r
   r	   r   r   r   s   `   @r   Útest_notFoundRenderz%PythonScriptTests.test_notFoundRenderZ   s€   øø€ õ
   §¢¡¤¨tÑ4Ô4ˆÝ ˜uÑ%Ô%ˆÝ�H˜gÑ&Ô&ˆð	>¥ð 	>¨4ð 	>ð 	>ð 	>ð 	>ð 	>ð 	>ð 	>ð �}Š}˜ZÑ(Ô(Ð(r   c                 ó’  ‡ ‡— t          ‰                      ¦   «         ¦  «        }|                     ¦   «          |                     d¦  «        }|                     d¦  «         t          |                     ¦   «         d¦  «        }t          dg¦  «        Št          |‰¦  «        }dt          ddfˆˆ fd„}| 
                    |¦  «        S )r-   ztest.epys   raise Exception("nooo")Nr   r   r   c                 ód   •— ‰                      dd                     ‰j        ¦  «        ¦  «         d S )Ns   nooor   )ÚassertInr/   r0   r   s    €€r   r   z:PythonScriptTests.test_renderException.<locals>.cbRenderedv   s+   ø€ Ø�MŠM˜' 3§8¢8¨G¬OÑ#<Ô#<Ñ=Ô=Ð=Ð=Ð=r   )r   r   r'   r*   r1   r   r2   r
   r	   r   r   )r   r3   r*   r    r!   r   r   s   `     @r   Útest_renderExceptionz&PythonScriptTests.test_renderExceptionh   sÌ   øø€ õ �t—{’{‘}”}Ñ%Ô%ˆØ�Š‰ŒˆØ—	’	˜*Ñ%Ô%ˆØ×ÒÐ3Ñ4Ô4Ð4Ý × 2Ò 2Ñ 4Ô 4°dÑ;Ô;ˆÝ ˜uÑ%Ô%ˆÝ�H˜gÑ&Ô&ˆð	>¥ð 	>¨4ð 	>ð 	>ð 	>ð 	>ð 	>ð 	>ð 	>ð �}Š}˜ZÑ(Ô(Ð(r   )r5   r6   r7   r8   r   r9   r?   rC   r:   r   r   r<   r<   U   sb   € € € € € ðð ð) U¤^°DÔ%9ð )ð )ð )ð )ð) e¤n°TÔ&:ð )ð )ð )ð )ð )ð )r   r<   )r8   r&   Útwisted.internetr   Útwisted.python.filepathr   Útwisted.trial.unittestr   Útwisted.web.httpr   Útwisted.web.scriptr   r   Útwisted.web.test._utilr	   Útwisted.web.test.requesthelperr
   r   r<   r:   r   r   ú<module>rK      sý   ððð ð 
€	€	€	à "Ð "Ð "Ð "Ð "Ð "Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø +Ð +Ð +Ð +Ð +Ð +Ø &Ð &Ð &Ð &Ð &Ð &Ø DÐ DÐ DÐ DÐ DÐ DÐ DÐ DØ *Ð *Ð *Ð *Ð *Ð *Ø 7Ð 7Ð 7Ð 7Ð 7Ð 7ð?)ð ?)ð ?)ð ?)ð ?) 8ñ ?)ô ?)ð ?)ðD$)ð $)ð $)ð $)ð $)˜ñ $)ô $)ð $)ð $)ð $)r   