
    Yf@                         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dS )z
Test L{twisted.web.pages}
    )cast)SynchronousTestCase)Headers)IRequest)	errorPage	forbiddennotFound)	IResource)DummyRequestresourcereturnc                 v    t          dg          }|                     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     M/var/www/html/env/lib/python3.11/site-packages/twisted/web/test/test_pages.py_renderr      s6     C5!!G OOD7++,,,Nr   c                   N    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dS )ErrorPageTestszu
    Test L{twisted.web.pages._ErrorPage} and its public aliases L{errorPage},
    L{notFound} and L{forbidden}.
    Nr   codebodyr   c                 :   |                      |j        |           |                      |j        t          ddgi                     |                      d                    |j                                      d          |                    d                     d S )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*   s    -t444#_'B&CDEE	
 	
 	
 	 HHW_%%,,Y77KK	""		
 	
 	
 	
 	
r   c           	      l    |                      t          t          ddd                    dd           dS )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   sF     	Ic7,DEEFF&			
 		
 		
 		
 		
r   c                     t          ddd          }|                     |                    dt          t          t          dg                              |           dS )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,u2E2E#F#FGG	
 	
 	
 	
 	
r   c                 f    |                      t          t                                dd           dS )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=    
 	HJJ"	
	
 
	
 
	
 
	
 
	
r   c                 f    |                      t          t                                dd           dS )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=    
 	IKK  "	
	
 
	
 
	
 
	
 
	
r   )r   N)__name__
__module____qualname____doc__maxDiffr   intbytesr    r#   r+   r-   r/    r   r   r   r   "   s         
 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?      s           6 6 6 6 6 6 , , , , , , % % % % % % < < < < < < < < < < * * * * * * 7 7 7 7 7 7i L     O
 O
 O
 O
 O
( O
 O
 O
 O
 O
r   