
    Vh@                         d 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mZ ddlmZ ddlmZ d	ed
efdZ G d de      Zy)z
Test L{twisted.web.pages}
    )cast)SynchronousTestCase)Headers)IRequest)	errorPage	forbiddennotFound)	IResource)DummyRequestresourcereturnc                 \    t        dg      }| j                  t        t        |             |S )z
    Render a response using the given resource.

    @param resource: The resource to use to handle the request.

    @returns: The request that the resource handled,
        )r   renderr   r   )r   requests     K/home/dcms/DCMS/lib/python3.12/site-packages/twisted/web/test/test_pages.py_renderr      s*     C5!G OOD7+,Nr   c                   L    e Zd ZdZdZdedededdfdZddZ	dd	Z
dd
ZddZy)ErrorPageTestszu
    Test L{twisted.web.pages._ErrorPage} and its public aliases L{errorPage},
    L{notFound} and L{forbidden}.
    Nr   codebodyr   c                    | j                  |j                  |       | j                  |j                  t        ddgi             | j                  dj	                  |j
                        j                  d      |j                  d             y )Ns   content-types   text/html; charset=utf-8r   zlatin-1)assertEqualresponseCoderesponseHeadersr   joinwrittendecode)selfr   r   r   s       r   assertResponsezErrorPageTests.assertResponse*   sy    --t4##_'B&CDE	
 	 HHW__%,,Y7KK	"		
r   c           	      R    | j                  t        t        ddd            dd       y)zS
        The I{brief} and I{detail} parameters are HTML-escaped on render.
        i  zA & Bz<script>alert('oops!')s   <!DOCTYPE html>
<html><head><title>400 - A &amp; B</title></head><body><h1>A &amp; B</h1><p>&lt;script&gt;alert('oops!')</p></body></html>N)r    r   r   r   s    r   test_escapesHTMLzErrorPageTests.test_escapesHTML7   s,     	Ic7,DEF&			
r   c                     t        ddd      }| j                  |j                  dt        t        t        dg                  |       y)z
        The C{getChild} method of the resource returned by L{errorPage} returns
        the L{_ErrorPage} it is called on.
          foobars   namer   N)r   assertIsgetChildr   r   r   )r   pages     r   test_getChildzErrorPageTests.test_getChildF   s=    
 eU+MM'4,u2E#FG	
r   c                 L    | j                  t        t                     dd       y)zq
        The default arguments to L{twisted.web.pages.notFound} produce
        a reasonable error page.
        r%   s   <!DOCTYPE html>
<html><head><title>404 - No Such Resource</title></head><body><h1>No Such Resource</h1><p>Sorry. No luck finding that resource.</p></body></html>N)r    r   r	   r"   s    r   test_notFoundDefaultsz$ErrorPageTests.test_notFoundDefaultsQ   s$    
 	HJ"	
	
r   c                 L    | j                  t        t                     dd       y)zr
        The default arguments to L{twisted.web.pages.forbidden} produce
        a reasonable error page.
        i  s   <!DOCTYPE html>
<html><head><title>403 - Forbidden Resource</title></head><body><h1>Forbidden Resource</h1><p>Sorry, resource is forbidden.</p></body></html>N)r    r   r   r"   s    r   test_forbiddenDefaultsz%ErrorPageTests.test_forbiddenDefaultsb   s$    
 	IK "	
	
r   )r   N)__name__
__module____qualname____doc__maxDiffr   intbytesr    r#   r+   r-   r/    r   r   r   r   "   sC    
 G
l 
# 
U 
t 

	

"
r   r   N)r3   typingr   twisted.trial.unittestr   twisted.web.http_headersr   twisted.web.iwebr   twisted.web.pagesr   r   r	   twisted.web.resourcer
   twisted.web.test.requesthelperr   r   r   r7   r   r   <module>r?      sF     6 , % < < * 7i L  O
( O
r   