
    Yf}A                       d Z ddlmZ ddlZddl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  G d d	e	j                  Z G d
 de	j                  Z G d de	j                  Z G d de	j                  Z G d de	j                  Z G d de	j                  Z G d de	j                  Z G d de	j                  Z G d de	j                  ZdS )z
HTTP errors.
    )annotationsN)nativeString)unittest)error)Tagc                  *    e Zd ZdZddZddZddZdS )	CodeToMessageTestsz<
    L{_codeToMessages} inverts L{_responses.RESPONSES}
    returnNonec                Z    t          j        d          }|                     |d           d S )N   302s   Foundr   _codeToMessageassertEqualselfms     M/var/www/html/env/lib/python3.11/site-packages/twisted/web/test/test_error.pytest_validCodez!CodeToMessageTests.test_validCode   s.     ((H%%%%%    c                Z    t          j        d          }|                     |d            d S )Ns   987r   r   s     r   test_invalidCodez#CodeToMessageTests.test_invalidCode   s.     ((D!!!!!r   c                Z    t          j        d          }|                     |d            d S )Ns   InvalidCoder   r   s     r   test_nonintegerCodez&CodeToMessageTests.test_nonintegerCode!   s.     00D!!!!!r   Nr
   r   )__name__
__module____qualname____doc__r   r   r    r   r   r	   r	      sZ         & & & &" " " "" " " " " "r   r	   c                  :    e Zd ZdZd
dZd
dZd
dZd
dZd
dZd	S )
ErrorTestsz<
    Tests for how L{Error} attributes are initialized.
    r
   r   c                    t          j        d          }|                     |j        d           |                     t	          |          d           dS )z
        If no C{message} argument is passed to the L{Error} constructor and the
        C{code} argument is a valid HTTP status code, C{message} is set to the
        HTTP reason phrase for C{code}.
           200   OK200 OKNr   Errorr   messagestrr   es     r   test_noMessageValidStatusz$ErrorTests.test_noMessageValidStatus+   sM     KE***Q*****r   c                    t          j        d          }|                     |j        d           |                     t	          |          d           dS )z
        If no C{message} argument is passed to the L{Error} constructor and
        C{code} isn't a known HTTP status code, C{message} stays L{None}.
           999N999r'   r+   s     r   test_noMessageForStatusz"ErrorTests.test_noMessageForStatus5   sM    
 KD)))Q'''''r   c                    |                      t                    5  t          j        d           ddd           dS # 1 swxY w Y   dS )z
        If C{code} isn't plausibly an HTTP status code (i.e., composed of
        digits) it is rejected with L{ValueError}.
        s   InvalidStatusN)assertRaises
ValueErrorr   r(   r   s    r   test_invalidStatuszErrorTests.test_invalidStatus>   s    
 z** 	* 	*K()))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*s   =AAc                    t          j        dd          }|                     |j        d           |                     t	          |          d           dS )z
        If a C{message} argument is passed to the L{Error} constructor, the
        C{message} isn't affected by the value of C{status}.
        r$      My own messagez200 My own messageNr'   r+   s     r   test_messageExistszErrorTests.test_messageExistsF   sR    
 K 122$5666Q!566666r   c                    t          j        dd          }|                     t          |          d           t          j        dd          }|                     t          |          d           dS )zh
        C{str()} on an L{Error} returns the code and message it was
        instantiated with.
        r$   r%   r&      N)r   r(   r   r*   r+   s     r   test_strzErrorTests.test_strO   sf     K&&Q*** KU##Q*****r   Nr   )	r   r   r   r   r-   r1   r6   r9   r<   r    r   r   r"   r"   &   s         + + + +( ( ( (* * * *7 7 7 7+ + + + + +r   r"   c                  :    e Zd ZdZd
dZd
dZd
dZd
dZd
dZd	S )PageRedirectTestszC
    Tests for how L{PageRedirect} attributes are initialized.
    r
   r   c                h    t          j        dd          }|                     |j        d           dS )z
        If no C{message} argument is passed to the L{PageRedirect} constructor
        and the C{code} argument is a valid HTTP status code, C{code} is mapped
        to a descriptive string to which C{message} is assigned.
        r$      /foolocation
   OK to /fooNr   PageRedirectr   r)   r+   s     r   r-   z+PageRedirectTests.test_noMessageValidStatusb   s7     v888M22222r   c                d    t          j        d          }|                     |j        d           dS )a;  
        If no C{message} argument is passed to the L{PageRedirect} constructor
        and C{location} is also empty and the C{code} argument is a valid HTTP
        status code, C{code} is mapped to a descriptive string to which
        C{message} is assigned without trying to include an empty location.
        r$   r%   NrD   r+   s     r   #test_noMessageValidStatusNoLocationz5PageRedirectTests.test_noMessageValidStatusNoLocationk   s2     v&&E*****r   c                h    t          j        dd          }|                     |j        d           dS )z
        If no C{message} argument is passed to the L{PageRedirect} constructor
        and C{code} isn't a valid HTTP status code, C{message} stays L{None}.
        r/   r@   rA   NrD   r+   s     r   )test_noMessageInvalidStatusLocationExistsz;PageRedirectTests.test_noMessageInvalidStatusLocationExistsu   s7    
 v888D)))))r   c                j    t          j        ddd          }|                     |j        d           dS )z
        If a C{message} argument is passed to the L{PageRedirect} constructor,
        the C{message} isn't affected by the value of C{status}.
        r$   r8   r@   rA      My own message to /fooNrD   r+   s     r    test_messageExistsLocationExistsz2PageRedirectTests.test_messageExistsLocationExists}   s;    
 v'87KKK$=>>>>>r   c                f    t          j        dd          }|                     |j        d           dS )z
        If a C{message} argument is passed to the L{PageRedirect} constructor
        and no location is provided, C{message} doesn't try to include the
        empty location.
        r$   r8   NrD   r+   s     r   test_messageExistsNoLocationz.PageRedirectTests.test_messageExistsNoLocation   s6     v'899$566666r   Nr   	r   r   r   r   r-   rG   rI   rL   rN   r    r   r   r>   r>   ]   s         3 3 3 3+ + + +* * * *? ? ? ?7 7 7 7 7 7r   r>   c                  :    e Zd ZdZd
dZd
dZd
dZd
dZd
dZd	S )InfiniteRedirectionTestszJ
    Tests for how L{InfiniteRedirection} attributes are initialized.
    r
   r   c                h    t          j        dd          }|                     |j        d           dS )z
        If no C{message} argument is passed to the L{InfiniteRedirection}
        constructor and the C{code} argument is a valid HTTP status code,
        C{code} is mapped to a descriptive string to which C{message} is
        assigned.
        r$   r@   rA   rC   Nr   InfiniteRedirectionr   r)   r+   s     r   r-   z2InfiniteRedirectionTests.test_noMessageValidStatus   s7     %fw???M22222r   c                d    t          j        d          }|                     |j        d           dS )aJ  
        If no C{message} argument is passed to the L{InfiniteRedirection}
        constructor and C{location} is also empty and the C{code} argument is a
        valid HTTP status code, C{code} is mapped to a descriptive string to
        which C{message} is assigned without trying to include an empty
        location.
        r$   r%   NrS   r+   s     r   rG   z<InfiniteRedirectionTests.test_noMessageValidStatusNoLocation   s2     %f--E*****r   c                    t          j        dd          }|                     |j        d           |                     t	          |          d           dS )z
        If no C{message} argument is passed to the L{InfiniteRedirection}
        constructor and C{code} isn't a valid HTTP status code, C{message} stays
        L{None}.
        r/   r@   rA   Nr0   )r   rT   r   r)   r*   r+   s     r   rI   zBInfiniteRedirectionTests.test_noMessageInvalidStatusLocationExists   sS     %fw???D)))Q'''''r   c                j    t          j        ddd          }|                     |j        d           dS )z
        If a C{message} argument is passed to the L{InfiniteRedirection}
        constructor, the C{message} isn't affected by the value of C{status}.
        r$   r8   r@   rA   rK   NrS   r+   s     r   rL   z9InfiniteRedirectionTests.test_messageExistsLocationExists   s;    
 %f.?'RRR$=>>>>>r   c                f    t          j        dd          }|                     |j        d           dS )z
        If a C{message} argument is passed to the L{InfiniteRedirection}
        constructor and no location is provided, C{message} doesn't try to
        include the empty location.
        r$   r8   NrS   r+   s     r   rN   z5InfiniteRedirectionTests.test_messageExistsNoLocation   s6     %f.?@@$566666r   Nr   rO   r    r   r   rQ   rQ      s         3 3 3 3	+ 	+ 	+ 	+( ( ( (? ? ? ?7 7 7 7 7 7r   rQ   c                      e Zd ZdZddZdS )RedirectWithNoLocationTestszq
    L{RedirectWithNoLocation} is a subclass of L{Error} which sets
    a custom message in the constructor.
    r
   r   c                    t          j        ddd          }|                     |j        d           |                     |j        d           dS )z
        When C{code}, C{message}, and C{uri} are passed to the
        L{RedirectWithNoLocation} constructor, the C{message} and C{uri}
        attributes are set, respectively.
        r   s   REDIRECTs   https://example.coms   REDIRECT to https://example.comN)r   RedirectWithNoLocationr   r)   urir+   s     r   test_validMessagez-RedirectWithNoLocationTests.test_validMessage   sQ     (>TUU$FGGG 677777r   Nr   )r   r   r   r   r^   r    r   r   rZ   rZ      s2         
8 8 8 8 8 8r   rZ   c                  "    e Zd ZdZddZddZdS )MissingRenderMethodTestsz\
    Tests for how L{MissingRenderMethod} exceptions are initialized and
    displayed.
    r
   r   c                    t                      }t          j        |d          }|                     |j        |           |                     |j        d           dS )z
        Given C{element} and C{renderName} arguments, the
        L{MissingRenderMethod} constructor assigns the values to the
        corresponding attributes.
        renderThingN)objectr   MissingRenderMethodassertIselement
renderNamer   eltr,   s      r   test_constructorz)MissingRenderMethodTests.test_constructor   sQ     hh%c=99ai%%%alM22222r   c                    t                      }t          j        |d          }|                     t	          |          d|z             dS )z
        A L{MissingRenderMethod} is represented using a custom string
        containing the element's representation and the method name.
        rb   zB'MissingRenderMethod': %r had no render method named 'renderThing'N)rc   r   rd   r   reprrh   s      r   	test_reprz"MissingRenderMethodTests.test_repr   sU    
 hh%c=99GGT	
 	
 	
 	
 	
r   Nr   r   r   r   r   rj   rm   r    r   r   r`   r`      sF         
	3 	3 	3 	3
 
 
 
 
 
r   r`   c                  "    e Zd ZdZddZddZdS )MissingTemplateLoaderTestsz^
    Tests for how L{MissingTemplateLoader} exceptions are initialized and
    displayed.
    r
   r   c                    t                      }t          j        |          }|                     |j        |           dS )z
        Given an C{element} argument, the L{MissingTemplateLoader} constructor
        assigns the value to the corresponding attribute.
        N)rc   r   MissingTemplateLoaderre   rf   rh   s      r   rj   z+MissingTemplateLoaderTests.test_constructor   s9    
 hh',,ai%%%%%r   c                    t                      }t          j        |          }|                     t	          |          d|z             dS )z
        A L{MissingTemplateLoader} is represented using a custom string
        containing the element's representation and the method name.
        z)'MissingTemplateLoader': %r had no loaderN)rc   r   rr   r   rl   rh   s      r   rm   z$MissingTemplateLoaderTests.test_repr  sF    
 hh',,a"MPS"STTTTTr   Nr   rn   r    r   r   rp   rp      sL         
& & & &U U U U U Ur   rp   c                      e Zd ZdZg fddZdd
ZddZddZddZddZ	ddZ
ddZddZddZddZddZddZddZddZdS )FlattenerErrorTestsz&
    Tests for L{FlattenerError}.
    rootslist[object]r
   error.FlattenerErrorc                    	 t          d          # t          $ rK}t          j        t	          j                    d                   }t          j        |||          cY d }~S d }~ww xY w)Noh noes   )RuntimeError	Exception	traceback
extract_tbsysexc_infor   FlattenerError)r   rv   r,   tbs       r   makeFlattenerErrorz&FlattenerErrorTests.makeFlattenerError  ss    	6y))) 	6 	6 	6%clnnQ&788B'5"55555555	6s    
A&A A!A&!A&objrc   r*   c                    d|z  S )NzR(%s)r    )r   r   s     r   fakeFormatRootz"FlattenerErrorTests.fakeFormatRoot  s    }r   r   c                p    |                      ddg          }|                     |j        ddg           dS )z
        Given C{exception}, C{roots}, and C{traceback} arguments, the
        L{FlattenerError} constructor assigns the roots to the C{_roots}
        attribute.
        ab)rv   N)r   r   _rootsr+   s     r   rj   z$FlattenerErrorTests.test_constructor  s@     ##3*#55C:.....r   c                    |                                  }|                     t          |          t          |                     dS )zd
        The string form of a L{FlattenerError} is identical to its
        representation.
        N)r   r   r*   rl   r+   s     r   r<   zFlattenerErrorTests.test_str&  s=    
 ##%%Qa)))))r   c                   |                      ddg          }| j        |_        |                     t	          j        dt          |          t          j        t          j        z            t          |                     dS )z
        The representation of a L{FlattenerError} initialized with roots and a
        traceback contains a formatted representation of those roots (using
        C{_formatRoot}) and a formatted traceback.
        r   r   zException while flattening:
  R\(a\)
  R\(b\)
  File "[^"]*", line [0-9]*, in makeFlattenerError
    raise RuntimeError\("oh noes"\)
RuntimeError: oh noes
$N)	r   r   _formatRoot
assertTruerematchrl   MSr+   s     r   "test_reprWithRootsAndWithTracebackz6FlattenerErrorTests.test_reprWithRootsAndWithTraceback.  sz     ##S#J//+H+ Qrt	 	 GG	
 	
 	
 	
 	
r   c                    |                      g           }|                     t          j        dt	          |          t          j        t          j        z            t	          |                     dS )
        The representation of a L{FlattenerError} initialized without roots but
        with a traceback contains a formatted traceback but no roots.
        zException while flattening:
  File "[^"]*", line [0-9]*, in makeFlattenerError
    raise RuntimeError\("oh noes"\)
RuntimeError: oh noes
$N)r   r   r   r   rl   r   r   r+   s     r   %test_reprWithoutRootsAndWithTracebackz9FlattenerErrorTests.test_reprWithoutRootsAndWithTracebackD  sl    
 ##B''H+ Qrt  GG
	
 
	
 
	
 
	
 
	
r   c                   t          j        t          d          g d          }|                     t	          j        dt          |          t          j        t          j        z            t          |                     dS )r   rz   Nz3Exception while flattening:
RuntimeError: oh noes
$)	r   r   r|   r   r   r   rl   r   r   r+   s     r   (test_reprWithoutRootsAndWithoutTracebackz<FlattenerErrorTests.test_reprWithoutRootsAndWithoutTracebackV  sq    
  i!8!8"dCCHJQrt 
 GG	
 	
 	
 	
 	
r   c                    |                                  }|                     |                    t          d                    t	          d                     dS )zk
        The C{_formatRoot} method formats a short unicode string using the
        built-in repr.
        abcdN)r   r   r   r   rl   r+   s     r   !test_formatRootShortUnicodeStringz5FlattenerErrorTests.test_formatRootShortUnicodeStringe  sK    
 ##%%|F';';<<d6llKKKKKr   c                    |                                  }t          d          }|                     |                    |          t	          d                     dS )z{
        The C{_formatRoot} method formats a long unicode string using the
        built-in repr with an ellipsis.
        zxabcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-z-abcde-abcde-abcde-ab<...>e-abcde-abcde-abcde-N)r   r   r   r   rl   r   r,   
longStrings      r    test_formatRootLongUnicodeStringz4FlattenerErrorTests.test_formatRootLongUnicodeStringm  s_    
 ##%%!-00
MM*%%@AA	
 	
 	
 	
 	
r   c                    |                                  }|                     |                    d          t          d                     dS )zh
        The C{_formatRoot} method formats a short byte string using the
        built-in repr.
        s   abcdNr   r   r   rl   r+   s     r   test_formatRootShortByteStringz2FlattenerErrorTests.test_formatRootShortByteStringy  sC    
 ##%%w//g?????r   c                    |                                  }d}|                     |                    |          t          d                     dS )zx
        The C{_formatRoot} method formats a long byte string using the
        built-in repr with an ellipsis.
        sx   abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-s-   abcde-abcde-abcde-ab<...>e-abcde-abcde-abcde-Nr   r   s      r   test_formatRootLongByteStringz1FlattenerErrorTests.test_formatRootLongByteString  sW    
 ##%%#
MM*%%ABB	
 	
 	
 	
 	
r   c                    |                                  }|                     |                    t          d                    d           dS )zu
        The C{_formatRoot} method formats a C{Tag} with no filename information
        as 'Tag <tagName>'.
        a-tagzTag <a-tag>N)r   r   r   r   r+   s     r   test_formatRootTagNoFilenamez0FlattenerErrorTests.test_formatRootTagNoFilename  sC    
 ##%%s7||44mDDDDDr   c                    |                                  }t          dddd          }|                     |                    |          d           dS )z
        The C{_formatRoot} method formats a C{Tag} with filename information
        using the filename, line, column, and tag information
        r   ztpl.py
      )filename
lineNumbercolumnNumberz-File "tpl.py", line 10, column 20, in "a-tag"N)r   r   r   r   )r   r,   ts      r   test_formatRootTagWithFilenamez2FlattenerErrorTests.test_formatRootTagWithFilename  s_    
 ##%%(rKKKMM!M	
 	
 	
 	
 	
r   c           	        |                      t          t          j        t	          d          dgg                     d           |                      t          t          j        t	          d          dgg                     d           dS )z
        If a L{FlattenerError} is created with a string root, up to around 40
        bytes from that string are included in the string representation of the
        exception.
        reason	abc123xyzz?Exception while flattening:
  'abc123xyz'
RuntimeError: reason
d0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789zcException while flattening:
  '01234567890123456789<...>01234567890123456789'
RuntimeError: reason
Nr   r*   r   r   r|   r5   s    r   test_stringzFlattenerErrorTests.test_string  s     	$\(%;%;k]BOOPPV	
 	
 	
 	$\(%;%;>O=PRTUUVV%	
 	
 	
 	
 	
r   c           	        |                      t          t          j        t	          d          dgg                     d           |                      t          t          j        t	          d          dgg                     d           dS )z
        If a L{FlattenerError} is created with a unicode root, up to around 40
        characters from that string are included in the string representation
        of the exception.
        r   u	   abc☃xyzzBException while flattening:
  'abc\u2603xyz'
RuntimeError: reason
ux   01234567☃901234567☃901234567☃901234567☃901234567☃901234567☃901234567☃901234567☃901234567☃901234567☃9zwException while flattening:
  '01234567\u2603901234567\u26039<...>01234567\u2603901234567\u26039'
RuntimeError: reason
Nr   r5   s    r   test_unicodez FlattenerErrorTests.test_unicode  s     	$\(%;%;>Q=RTVWW %		
 	
 	
 	$ **-H,I2  
%	
 	
 	
 	
 	
r   N)rv   rw   r
   rx   )r   rc   r
   r*   r   )r   r   r   r   r   r   rj   r<   r   r   r   r   r   r   r   r   r   r   r   r    r   r   ru   ru     s`         8: 6 6 6 6 6   / / / /* * * *
 
 
 
,
 
 
 
$
 
 
 
L L L L

 

 

 

@ @ @ @

 

 

 

E E E E	
 	
 	
 	

 
 
 
$
 
 
 
 
 
r   ru   c                      e Zd ZdZddZdS )UnsupportedMethodTestsz)
    Tests for L{UnsupportedMethod}.
    r
   r   c                x    t          j        ddg          }|                     t          |          d           dS )z
        The C{__str__} for L{UnsupportedMethod} makes it clear that what it
        shows is a list of the supported methods, not the method that was
        unsupported.
        s   HEADs   PATCHz#Expected one of [b'HEAD', b'PATCH']N)r   UnsupportedMethodr   r*   r+   s     r   r<   zUnsupportedMethodTests.test_str  sG     #Wh$788FF1	
 	
 	
 	
 	
r   Nr   )r   r   r   r   r<   r    r   r   r   r     s2         

 

 

 

 

 

r   r   )r   
__future__r   r   r   r~   twisted.python.compatr   twisted.trialr   twisted.webr   twisted.web.templater   TestCaser	   r"   r>   rQ   rZ   r`   rp   ru   SynchronousTestCaser   r    r   r   <module>r      s<    # " " " " " 				 



     . . . . . . " " " " " "       $ $ $ $ $ $" " " " "* " " "$4+ 4+ 4+ 4+ 4+" 4+ 4+ 4+n/7 /7 /7 /7 /7) /7 /7 /7d37 37 37 37 37x0 37 37 37l8 8 8 8 8("3 8 8 8"
 
 
 
 
x0 
 
 
>U U U U U!2 U U U2}
 }
 }
 }
 }
(+ }
 }
 }
@
 
 
 
 
X9 
 
 
 
 
r   