
    Vh}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y)z
HTTP errors.
    )annotationsN)nativeString)unittest)error)Tagc                  (    e Zd ZdZddZddZddZy)CodeToMessageTestsz<
    L{_codeToMessages} inverts L{_responses.RESPONSES}
    c                R    t        j                  d      }| j                  |d       y )N   302s   Foundr   _codeToMessageassertEqualselfms     K/home/dcms/DCMS/lib/python3.12/site-packages/twisted/web/test/test_error.pytest_validCodez!CodeToMessageTests.test_validCode   s"      (H%    c                R    t        j                  d      }| j                  |d        y )Ns   987r   r   s     r   test_invalidCodez#CodeToMessageTests.test_invalidCode   s"      (D!r   c                R    t        j                  d      }| j                  |d        y )Ns   InvalidCoder   r   s     r   test_nonintegerCodez&CodeToMessageTests.test_nonintegerCode!   s"      0D!r   NreturnNone)__name__
__module____qualname____doc__r   r   r    r   r   r	   r	      s    &""r   r	   c                  8    e Zd ZdZddZddZddZddZddZy)	
ErrorTestsz<
    Tests for how L{Error} attributes are initialized.
    c                    t        j                  d      }| j                  |j                  d       | j                  t	        |      d       y)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+   s:     KKE*Q*r   c                    t        j                  d      }| j                  |j                  d       | j                  t	        |      d       y)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   s:    
 KKD)Q'r   c                    | j                  t              5  t        j                  d       ddd       y# 1 sw Y   yxY w)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>   s4    
 z* 	*KK()	* 	* 	*s   5>c                    t        j                  dd      }| j                  |j                  d       | j                  t	        |      d       y)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   s?    
 KK 12$56Q!56r   c                    t        j                  dd      }| j                  t        |      d       t        j                  dd      }| j                  t        |      d       y)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   sN     KK&Q* KKU#Q*r   Nr   )	r   r   r   r   r-   r1   r6   r9   r<   r    r   r   r"   r"   &   s     +(*7+r   r"   c                  8    e Zd ZdZddZddZddZddZddZy)	PageRedirectTestszC
    Tests for how L{PageRedirect} attributes are initialized.
    c                j    t        j                  dd      }| j                  |j                  d       y)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   s*     v8M2r   c                f    t        j                  d      }| j                  |j                  d       y)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   s(     v&E*r   c                j    t        j                  dd      }| j                  |j                  d       y)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   s*    
 v8D)r   c                l    t        j                  ddd      }| j                  |j                  d       y)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$=>r   c                h    t        j                  dd      }| j                  |j                  d       y)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   s,     v'89$56r   Nr   	r   r   r   r   r-   rG   rI   rL   rN   r    r   r   r>   r>   ]   s     3+*?7r   r>   c                  8    e Zd ZdZddZddZddZddZddZy)	InfiniteRedirectionTestszJ
    Tests for how L{InfiniteRedirection} attributes are initialized.
    c                j    t        j                  dd      }| j                  |j                  d       y)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   s*     %%fw?M2r   c                f    t        j                  d      }| j                  |j                  d       y)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   s(     %%f-E*r   c                    t        j                  dd      }| j                  |j                  d       | j                  t	        |      d       y)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   s>     %%fw?D)Q'r   c                l    t        j                  ddd      }| j                  |j                  d       y)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   c                h    t        j                  dd      }| j                  |j                  d       y)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   s,     %%f.?@$56r   Nr   rO   r    r   r   rQ   rQ      s     3	+(?7r   rQ   c                      e Zd ZdZddZy)RedirectWithNoLocationTestszq
    L{RedirectWithNoLocation} is a subclass of L{Error} which sets
    a custom message in the constructor.
    c                    t        j                  ddd      }| j                  |j                  d       | j                  |j                  d       y)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   sC     ((>TU$FG 67r   Nr   )r   r   r   r   r^   r    r   r   rZ   rZ      s    
8r   rZ   c                       e Zd ZdZddZddZy)MissingRenderMethodTestsz\
    Tests for how L{MissingRenderMethod} exceptions are initialized and
    displayed.
    c                    t               }t        j                  |d      }| j                  |j                  |       | j                  |j
                  d       y)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   sA     h%%c=9aii%allM2r   c                    t               }t        j                  |d      }| j                  t	        |      d|z         y)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   s=    
 h%%c=9GT	
r   Nr   r   r   r   r   rj   rm   r    r   r   r`   r`      s    
	3
r   r`   c                       e Zd ZdZddZddZy)MissingTemplateLoaderTestsz^
    Tests for how L{MissingTemplateLoader} exceptions are initialized and
    displayed.
    c                z    t               }t        j                  |      }| j                  |j                  |       y)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   s-    
 h'',aii%r   c                ~    t               }t        j                  |      }| j                  t	        |      d|z         y)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  s6    
 h'',a"MPS"STr   Nr   rn   r    r   r   rp   rp      s    
&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y)FlattenerErrorTestsz&
    Tests for L{FlattenerError}.
    c                    	 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   rootsr,   tbs       r   makeFlattenerErrorz&FlattenerErrorTests.makeFlattenerError  sR    	6y)) 	6%%cllnQ&78B''5"55	6s    	A!A AA!A!c                    d|z  S )NzR(%s)r    )r   objs     r   fakeFormatRootz"FlattenerErrorTests.fakeFormatRoot  s    }r   c                h    | j                  ddg      }| j                  |j                  ddg       y)z
        Given C{exception}, C{roots}, and C{traceback} arguments, the
        L{FlattenerError} constructor assigns the roots to the C{_roots}
        attribute.
        ab)r   N)r   r   _rootsr+   s     r   rj   z$FlattenerErrorTests.test_constructor  s3     ##3*#5C:.r   c                l    | j                         }| j                  t        |      t        |             y)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                    | j                  ddg      }| j                  |_        | j                  t	        j
                  dt        |      t        j                  t        j                  z        t        |             y)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.  sc     ##S#J/++HH+ Qrtt	 G	
r   c                    | j                  g       }| j                  t        j                  dt	        |      t        j
                  t        j                  z        t	        |             y)
        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  sR    
 ##B'HH+ Qrtt G
	
r   c                    t        j                  t        d      g d      }| j                  t	        j
                  dt        |      t        j                  t        j                  z        t        |             y)r   rw   Nz3Exception while flattening:
RuntimeError: oh noes
$)	r   r   ry   r   r   r   rl   r   r   r+   s     r   (test_reprWithoutRootsAndWithoutTracebackz<FlattenerErrorTests.test_reprWithoutRootsAndWithoutTracebackV  sW    
   i!8"dCHHJQrtt
 G	
r   c                    | j                         }| j                  |j                  t        d            t	        d             y)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  s4    
 ##%|F';<d6lKr   c                    | j                         }t        d      }| j                  |j                  |      t	        d             y)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
MM*%@A	
r   c                x    | j                         }| j                  |j                  d      t        d             y)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  s/    
 ##%w/g?r   c                |    | j                         }d}| j                  |j                  |      t        d             y)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  s:    
 ##%#
MM*%AB	
r   c                x    | j                         }| j                  |j                  t        d            d       y)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  s/    
 ##%s7|4mDr   c                    | j                         }t        dddd      }| j                  |j                  |      d       y)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MM!M	
r   c           	         | j                  t        t        j                  t	        d      dgg             d       | j                  t        t        j                  t	        d      dgg             d       y)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   ry   r5   s    r   test_stringzFlattenerErrorTests.test_string  si     	$$\(%;k]BOPV	
 	$$\(%;>O=PRTUV%	
r   c           	         | j                  t        t        j                  t	        d      dgg             d       | j                  t        t        j                  t	        d      dgg             d       y)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  sv     	$$\(%;>Q=RTVW%		
 	$$ *-H,I2
%	
r   N)r   zlist[object]r   zerror.FlattenerError)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     sZ     8: 6/*
,
$
L

@

E	

$
r   ru   c                      e Zd ZdZddZy)UnsupportedMethodTestsz)
    Tests for L{UnsupportedMethod}.
    c                h    t        j                  ddg      }| j                  t        |      d       y)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  s1     ##Wh$78F1	
r   Nr   )r   r   r   r   r<   r    r   r   r   r     s    

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+n/7)) /7d37x00 37l8("3"3 8"
x00 
>U!2!2 U2}
(++ }
@
X99 
r   