Ë
    ojŸ  ã                   ó”   — 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y)z"
Tests for L{twisted.web.script}.
é    N)Údefer)ÚFilePath)ÚTestCase)Ú	NOT_FOUND)ÚPythonScriptÚResourceScriptDirectory)Ú_render)ÚDummyRequestc                   ó‚   — 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y)ÚResourceScriptDirectoryTestsz/
    Tests for L{ResourceScriptDirectory}.
    ÚreturnNc                 ó¨   ‡ ‡— t        ‰ j                  «       «      }t        dg«      Št        |‰«      }dt        ddfˆˆ fd„}|j                  |«      S )zh
        L{ResourceScriptDirectory.render} sets the HTTP response code to I{NOT
        FOUND}.
        ó    Úignoredr   Nc                 óF   •— ‰j                  ‰j                  t        «       y ©N©ÚassertEqualÚresponseCoder   ©r   ÚrequestÚselfs    €€ú>/usr/lib/python3/dist-packages/twisted/web/test/test_script.pyÚ
cbRenderedzDResourceScriptDirectoryTests.test_renderNotFound.<locals>.cbRendered!   ó   ø€ Ø×Ñ˜W×1Ñ1´9Õ=r   )r   Úmktempr
   r	   ÚobjectÚaddCallback©r   ÚresourceÚdr   r   s   `   @r   Útest_renderNotFoundz0ResourceScriptDirectoryTests.test_renderNotFound   sQ   ù€ ô
 +¨4¯;©;«=Ó9ˆÜ ˜uÓ%ˆÜ�H˜gÓ&ˆð	>¤ð 	>¨4ö 	>ð �}‰}˜ZÓ(Ð(r   c                 óú   ‡ ‡— ‰ j                  «       }t        j                  |«       t        |«      }t	        dg«      Š|j                  d‰«      }t        |‰«      }dt        ddfˆˆ fd„}|j                  |«      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                 óF   •— ‰j                  ‰j                  t        «       y 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&   st   ù€ ð �{‰{‹}ˆÜ
�‰�DÔÜ*¨4Ó0ˆÜ ˜xÓ(ˆØ×!Ñ! %¨Ó1ˆÜ�E˜7Ó#ˆð	>¤ð 	>¨4ö 	>ð �}‰}˜ZÓ(Ð(r   c                 ó^  ‡ ‡— t        ‰ j                  «       «      }|j                  «        |j                  d«      j	                  d«       t        |j                  «       «      }t        dg«      Š|j                  d‰«      }t        |‰«      }dt        ddfˆˆ fd„}|j                  |«      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                 ó\   •— ‰j                  dj                  ‰j                  «      d«       y )Nr   s   ok)r   ÚjoinÚwrittenr   s    €€r   r   z<ResourceScriptDirectoryTests.test_render.<locals>.cbRenderedO   s    ø€ Ø×Ñ˜SŸX™X g§o¡oÓ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ˆÜ�E˜7Ó#ˆð	?¤ð 	?¨4ö 	?ð �}‰}˜ZÓ(Ð(r   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚDeferredr"   r+   r4   © r   r   r   r      sF   „ ñð) U§^¡^°DÑ%9ó )ð) E§N¡N°4Ñ$8ó )ð&)˜UŸ^™^¨DÑ1ô )r   r   c                   ó\   — e Zd ZdZdej
                  d   fd„Zdej
                  d   fd„Zy)ÚPythonScriptTestsz$
    Tests for L{PythonScript}.
    r   Nc                 óª   ‡ ‡— t        ‰ j                  «       d«      }t        dg«      Št        |‰«      }dt        ddfˆˆ fd„}|j                  |«      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                 óF   •— ‰j                  ‰j                  t        «       y 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   sS   ù€ ô
   §¡£¨tÓ4ˆÜ ˜uÓ%ˆÜ�H˜gÓ&ˆð	>¤ð 	>¨4ö 	>ð �}‰}˜ZÓ(Ð(r   c                 ó@  ‡ ‡— t        ‰ j                  «       «      }|j                  «        |j                  d«      }|j	                  d«       t        |j                  «       d«      }t        dg«      Št        |‰«      }dt        ddfˆˆ fd„}|j                  |«      S )r-   ztest.epys   raise Exception("nooo")Nr   r   r   c                 ó\   •— ‰j                  ddj                  ‰j                  «      «       y )Ns   nooor   )ÚassertInr/   r0   r   s    €€r   r   z:PythonScriptTests.test_renderException.<locals>.cbRenderedv   s   ø€ Ø�M‰M˜' 3§8¡8¨G¯O©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Ü × 2Ñ 2Ó 4°dÓ;ˆÜ ˜uÓ%ˆÜ�H˜gÓ&ˆð	>¤ð 	>¨4ö 	>ð �}‰}˜ZÓ(Ð(r   )r5   r6   r7   r8   r   r9   r?   rC   r:   r   r   r<   r<   U   s1   „ ñð) U§^¡^°DÑ%9ó )ð) e§n¡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Ý *Ý 7ô?) 8ô ?)ôD$)˜õ $)r   