+
    Dfj(                        R t ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RI	H
t
HtHtHtHtHtHt ^ RIHt  ! R R]4      t ! R	 R
]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      tR# )z$
Tests for L{twisted.web.resource}.
)TestCase)UnsupportedMethod)Headers)IRequest)	FORBIDDEN	NOT_FOUNDResource_UnsafeErrorPage_UnsafeForbiddenResource_UnsafeNoResourcegetChildForRequest)DummyRequestc                      a  ] tR t^t o RtV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR	 ltV 3R
 lR lt	V 3R lR lt
V 3R lR ltV 3R lR ltRtV tR# )ErrorPageTestszV
Tests for L{_UnafeErrorPage}, L{_UnsafeNoResource}, and
L{_UnsafeForbiddenResource}.
c                   < V ^8  d   QhRR/#    returnN )format__classdict__s   "@/usr/lib/python3/dist-packages/twisted/web/test/test_resource.py__annotate__ErrorPageTests.__annotate__   s     	I 	I$ 	I    c                    \        ^{RR4      pV P                  4       w  pV P                  VR,          \        4       V P	                  RVR,          4       R# )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   &  r   test_deprecatedErrorPage'ErrorPageTests.test_deprecatedErrorPage   sL     c5&)&&(	,.@A3WY5GHr   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   )   s     	H 	H4 	Hr   c                    \        4       pV P                  4       w  pV P                  VR,          \        4       V P	                  RVR,          4       R# )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2GI4FGr   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   4   s     	I 	I$ 	Ir   c                    \        4       pV P                  4       w  pV P                  VR,          \        4       V P	                  RVR,          4       R# )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3WY5GHr   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   ?   s     E Et Er   c                t    \        RRR4      pV P                  VP                  R\        4       4      V4       R# )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/    
 eU+T]]7FH=tDr   c          
      6   < V ^8  d   QhRS[ RS[RS[RS[RR/# )r   r<   codebriefdetailr   N)r   intstr)r   r   s   "r   r   r   G   s5     
 

$'
03
=@
	
r   c                    \        R .4      pRpWbW3V3,          pV P                  VP                  V4      VP                  R4      4       V P                  VP                  V4       V P                  VP
                  \        RR./4      4       R# )r   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-8N)r   r!   renderencoderesponseCoderesponseHeadersr   )r%   r<   r@   rA   rB   requesttemplateexpecteds   &&&&&   r   _pageRenderingTest!ErrorPageTests._pageRenderingTestG   s     u% 	 U6::W-xw/GH--t4##_'B&CDE	
r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   ]   s     ; ; ;r   c                N    RpRpRp\        WV4      pV P                  WAW#4       R# )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.
r6   zbrief description textzmuch longer text might go hereN)r   rM   )r%   r@   rA   rB   r<   s   &    r   test_errorPageRendering&ErrorPageTests.test_errorPageRendering]   s/     (1f-E:r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   j   s     M M$ Mr   c                P    Rp\        V4      pV P                  V\        RV4       R# )z0
L{NoResource} sets the HTTP I{NOT FOUND} code.
zlong messagezNo Such ResourceN)r,   rM   r   r%   rB   r<   s   &  r   test_noResourceRendering'ErrorPageTests.test_noResourceRenderingj   s(      &!i1CVLr   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   r   s     O O Or   c                P    Rp\        V4      pV P                  V\        RV4       R# )z7
L{ForbiddenResource} sets the HTTP I{FORBIDDEN} code.
zlonger messagezForbidden ResourceN)r1   rM   r   rU   s   &  r   test_forbiddenResourceRendering.ErrorPageTests.test_forbiddenResourceRenderingr   s(     " (i1EvNr   r   N)__name__
__module____qualname____firstlineno____doc__r(   r-   r2   r=   rM   rQ   rV   rZ   __static_attributes____classdictcell__r   s   @r   r   r      sf     
	I 	I	H 	H	I 	IE E
 
,; ;M MO Or   r   c                   6   a  ] tR t^{t o RtV 3R lR ltRtV tR# )DynamicChildz?
A L{Resource} to be created on the fly by L{DynamicChildren}.
c                *   < V ^8  d   QhRS[ RS[RR/# )r   pathrJ   r   N)bytesr   )r   r   s   "r   r   DynamicChild.__annotate__   s"      U X $ r   c                J    \         P                  ! V 4       Wn        W n        R # N)r   __init__rg   rJ   r%   rg   rJ   s   &&&r   rl   DynamicChild.__init__   s    $	r   )rg   rJ   N)r\   r]   r^   r_   r`   rl   ra   rb   rc   s   @r   re   re   {   s      r   re   c                   6   a  ] tR t^t o RtV 3R lR ltRtV tR# )DynamicChildrenz&
A L{Resource} with dynamic children.
c                ,   < V ^8  d   QhRS[ RS[RS[/# )r   rg   rJ   r   )rh   r   re   )r   r   s   "r   r   DynamicChildren.__annotate__   s"     + +U +X +, +r   c                    \        W4      # rk   )re   rm   s   &&&r   r:   DynamicChildren.getChild   s    D**r   r   N)r\   r]   r^   r_   r`   r:   ra   rb   rc   s   @r   rp   rp      s     + +r   rp   c                   H   a  ] tR t^t o RtV 3R lR ltV 3R lR ltRtV tR# )BytesReturnedRenderablez?
A L{Resource} with minimal capabilities to render a response.
c                $   < V ^8  d   QhRS[ RR/# )r   responser   N)rh   )r   r   s   "r   r   $BytesReturnedRenderable.__annotate__   s     " " "4 "r   c                >    \         P                  ! V 4       Wn        R# )zW
@param response: A C{bytes} object giving the value to return from
    C{render_GET}.
N)r   rl   	_response)r%   rx   s   &&r   rl    BytesReturnedRenderable.__init__   s    
 	$!r   c                &   < V ^8  d   QhRS[ RS[/# )r   rJ   r   )r;   rh   )r   r   s   "r   r   ry      s      & U r   c                    V P                   # )ze
Render a response to a I{GET} request by returning a short byte string
to be written by the server.
r{   r%   rJ   s   &&r   
render_GET"BytesReturnedRenderable.render_GET   s    
 ~~r   r   N)	r\   r]   r^   r_   r`   rl   r   ra   rb   rc   s   @r   rv   rv      s     " " r   rv   c                   H   a  ] tR t^t o RtV 3R lR ltV 3R lR ltRtV tR# )ImplicitAllowedMethodszb
A L{Resource} which implicitly defines its allowed methods by defining
renderers to handle them.
c                $   < V ^8  d   QhRS[ RR/# r   rJ   r   Nr;   )r   r   s   "r   r   #ImplicitAllowedMethods.__annotate__         & T r   c                    R # rk   r   r   s   &&r   r   !ImplicitAllowedMethods.render_GET       r   c                $   < V ^8  d   QhRS[ RR/# r   r   )r   r   s   "r   r   r      r   r   c                    R # rk   r   r   s   &&r   
render_PUT!ImplicitAllowedMethods.render_PUT   r   r   r   N)	r\   r]   r^   r_   r`   r   r   ra   rb   rc   s   @r   r   r      s     
  r   r   c                      a  ] tR t^t o RtV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR	 ltV 3R
 lR lt	V 3R lR lt
RtV tR# )ResourceTestsz
Tests for L{Resource}.
c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   ResourceTests.__annotate__   s     
 
T 
r   c           	         \        4       p\        4       p\        4       pVP                  RV4       VP                  RV4       V P                  W!P                  R\	        . 4      4      4       R# )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   putChildr9   getChildWithDefaultr   r%   resourcechildsiblings   &   r   test_staticChildren!ResourceTests.test_staticChildren   s\     :
*&%(&'*//R8HI	
r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r      s     5 5d 5r   c                    Rp\        . 4      p\        4       pVP                  W4      pV P                  V\        4       V P                  VP                  V4       V P                  VP                  V4       R# )z
L{Resource.getChildWithDefault} delegates to L{Resource.getChild} when
the requested path is not associated with any static child.
r   N)	r   rp   r   assertIsInstancere   r!   rg   r9   rJ   )r%   rg   rJ   r   r   s   &    r   test_dynamicChildren"ResourceTests.test_dynamicChildren   sc    
 r""$,,T;e\2T*U]]G4r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r      s     	G 	G$ 	Gr   c                    \        4       p\        4       p\        4       pV P                  \        VP                  RV4       V P                  \        VP                  RV4       R# )z^
Test that passing the wrong type to putChild results in a warning,
and a failure in Python 3
r7   N)r   assertRaises	TypeErrorr   r   s   &   r   test_staticChildPathType&ResourceTests.test_staticChildPathType   sM    
 :
*)X%6%6uE)X%6%6gFr   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r      s     	= 	=$ 	=r   c                    Rp\        . 4      pRVn        \        V4      pV P                  WP	                  V4      4       R# )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   methodrv   r!   rF   )r%   rL   rJ   r   s   &   r   test_defaultHEADResourceTests.test_defaultHEAD   s;    
 +r" *84??7#;<r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r      s     A AT Ar   c                    . ROp\        4       pWn        \        . 4      pRVn        V P	                  \
        VP                  V4      pV P                  \        V4      \        VP                  4      4       R# )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.
	   FICTIONALN)   GETr      PUT)	r   allowedMethodsr   r   r   r   rF   r!   setr%   rL   r   rJ   excs   &    r   test_explicitAllowedMethods)ResourceTests.test_explicitAllowedMethods   s_     -:"*r"% 18??GLXC,>,>(?@r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r      s     < <T <r   c                    0 Rmp\        4       p\        . 4      pRVn        V P                  \        VP
                  V4      pV P                  V\        VP                  4      4       R# )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   N>   r   r   r   )	r   r   r   r   r   rF   r!   r   r   r   s   &    r   test_implicitAllowedMethods)ResourceTests.test_implicitAllowedMethods   sV     -)+r"% 18??GL3s'9'9#:;r   r   N)r\   r]   r^   r_   r`   r   r   r   r   r   r   ra   rb   rc   s   @r   r   r      sJ     
 
5 5	G 	G	= 	=A A< <r   r   c                   Z   a  ] tR tRt o RtV 3R lR ltV 3R lR ltV 3R lR ltR	tV t	R
# )GetChildForRequestTestsi  z"
Tests for L{getChildForRequest}.
c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   $GetChildForRequestTests.__annotate__  s     / / /r   c                h    \        . 4      p\        4       p\        W!4      pV P                  W#4       R# )zr
L{getChildForRequest} returns whatever resource has been reached by the
time the request's C{postpath} is empty.
N)r   r   r   r9   r%   rJ   r   results   &   r   test_exhaustedPostPath.GetChildForRequestTests.test_exhaustedPostPath  s-    
 r":#H6X.r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r     s     	/ 	/4 	/r   c                z    \        RR.4      p\        4       pRVn        \        W!4      pV P	                  W#4       R# )zk
L{getChildForRequest} returns the first resource it encounters with a
C{isLeaf} attribute set to C{True}.
r   r   TN)r   r   isLeafr   r9   r   s   &   r   test_leafResource)GetChildForRequestTests.test_leafResource  s9    
 /0:#H6X.r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r      s     5 5 5r   c                $   \        RR.4      p\        4       p\        4       pRVn        VP                  RV4       V P	                  V\        W!4      4       V P                  VP                  R.4       V P                  VP                  R.4       R# )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   r9   r   r!   prepathpostpath)r%   rJ   rootr   s   &   r   test_postPathToPrePath.GetChildForRequestTests.test_postPathToPrePath   sz    
 /0z
fe$U$6t$EF6(3))F84r   r   N)
r\   r]   r^   r_   r`   r   r   r   ra   rb   rc   s   @r   r   r     s(     / /	/ 	/5 5r   r   N)r`   twisted.trial.unittestr   twisted.web.errorr   twisted.web.http_headersr   twisted.web.iwebr   twisted.web.resourcer   r   r   r	   r   r
   r1   r   r,   r   twisted.web.test.requesthelperr   r   re   rp   rv   r   r   r   r   r   r   <module>r      s    , / , %   8`OX `OF8 +h +h *
X 
R<H R<j&5h &5r   