o
    >h}A                     @  s   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	 d	e	jZG d
d de	jZG dd de	jZG dd de	jZG dd de	jZG dd de	jZG dd de	jZG dd de	jZG dd de	jZdS )z
HTTP errors.
    )annotationsN)nativeString)unittest)error)Tagc                   @  s.   e Zd ZdZdddZdddZddd	Zd
S )CodeToMessageTestsz<
    L{_codeToMessages} inverts L{_responses.RESPONSES}
    returnNonec                 C  s   t d}| |d d S )N   302s   Foundr   _codeToMessageassertEqualselfm r   {/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/twisted/web/test/test_error.pytest_validCode      
z!CodeToMessageTests.test_validCodec                 C     t d}| |d  d S )Ns   987r   r   r   r   r   test_invalidCode   r   z#CodeToMessageTests.test_invalidCodec                 C  r   )Ns   InvalidCoder   r   r   r   r   test_nonintegerCode!   r   z&CodeToMessageTests.test_nonintegerCodeNr   r	   )__name__
__module____qualname____doc__r   r   r   r   r   r   r   r      s
    

r   c                   @  B   e Zd ZdZdddZdddZddd	Zdd
dZdddZdS )
ErrorTestsz<
    Tests for how L{Error} attributes are initialized.
    r   r	   c                 C  s,   t 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   er   r   r   test_noMessageValidStatus+   s   
z$ErrorTests.test_noMessageValidStatusc                 C  s,   t 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&   r   r   r   test_noMessageForStatus5   s   
z"ErrorTests.test_noMessageForStatusc                 C  s:   |  t td W d   dS 1 s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   r   r   r   test_invalidStatus>   s   "zErrorTests.test_invalidStatusc                 C  s.   t 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&   r   r   r   test_messageExistsF   s   zErrorTests.test_messageExistsc                 C  s<   t dd}| t|d t 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&   r   r   r   test_strO   s   zErrorTests.test_strNr   )	r   r   r   r   r(   r+   r/   r1   r3   r   r   r   r   r   &   s    



	
	r   c                   @  r   )PageRedirectTestszC
    Tests for how L{PageRedirect} attributes are initialized.
    r   r	   c                 C      t jd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&   r   r   r   r(   b   s   z+PageRedirectTests.test_noMessageValidStatusc                 C     t 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    Nr:   r&   r   r   r   #test_noMessageValidStatusNoLocationk   s   
z5PageRedirectTests.test_noMessageValidStatusNoLocationc                 C  s    t jd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)   r6   r7   Nr:   r&   r   r   r   )test_noMessageInvalidStatusLocationExistsu   s   z;PageRedirectTests.test_noMessageInvalidStatusLocationExistsc                 C  "   t jd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   r0   r6   r7      My own message to /fooNr:   r&   r   r   r    test_messageExistsLocationExists}      z2PageRedirectTests.test_messageExistsLocationExistsc                 C     t 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   r0   Nr:   r&   r   r   r   test_messageExistsNoLocation      z.PageRedirectTests.test_messageExistsNoLocationNr   	r   r   r   r   r(   r=   r>   rA   rD   r   r   r   r   r4   ]   s    

	


r4   c                   @  r   )InfiniteRedirectionTestszJ
    Tests for how L{InfiniteRedirection} attributes are initialized.
    r   r	   c                 C  r5   )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   r6   r7   r9   Nr   InfiniteRedirectionr   r$   r&   r   r   r   r(      s   z2InfiniteRedirectionTests.test_noMessageValidStatusc                 C  r<   )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    NrH   r&   r   r   r   r=      s   
z<InfiniteRedirectionTests.test_noMessageValidStatusNoLocationc                 C  s0   t jd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)   r6   r7   Nr*   )r   rI   r   r$   r%   r&   r   r   r   r>      s   zBInfiniteRedirectionTests.test_noMessageInvalidStatusLocationExistsc                 C  r?   )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   r0   r6   r7   r@   NrH   r&   r   r   r   rA      rB   z9InfiniteRedirectionTests.test_messageExistsLocationExistsc                 C  rC   )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   r0   NrH   r&   r   r   r   rD      rE   z5InfiniteRedirectionTests.test_messageExistsNoLocationNr   rF   r   r   r   r   rG      s    





rG   c                   @     e Zd ZdZd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                 C  s.   t 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&   r   r   r   test_validMessage   s   z-RedirectWithNoLocationTests.test_validMessageNr   )r   r   r   r   rN   r   r   r   r   rK      s    rK   c                   @  $   e Zd ZdZd	ddZd	ddZdS )
MissingRenderMethodTestsz\
    Tests for how L{MissingRenderMethod} exceptions are initialized and
    displayed.
    r   r	   c                 C  s2   t  }t|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'   r   r   r   test_constructor   s   z)MissingRenderMethodTests.test_constructorc                 C  s*   t  }t|d}| t|d|  dS )z
        A L{MissingRenderMethod} is represented using a custom string
        containing the element's representation and the method name.
        rQ   zB'MissingRenderMethod': %r had no render method named 'renderThing'N)rR   r   rS   r   reprrW   r   r   r   	test_repr   s   z"MissingRenderMethodTests.test_reprNr   r   r   r   r   rY   r[   r   r   r   r   rP      s    
rP   c                   @  rO   )
MissingTemplateLoaderTestsz^
    Tests for how L{MissingTemplateLoader} exceptions are initialized and
    displayed.
    r   r	   c                 C  s"   t  }t|}| |j| dS )z
        Given an C{element} argument, the L{MissingTemplateLoader} constructor
        assigns the value to the corresponding attribute.
        N)rR   r   MissingTemplateLoaderrT   rU   rW   r   r   r   rY      s   
z+MissingTemplateLoaderTests.test_constructorc                 C  s(   t  }t|}| t|d|  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)rR   r   r^   r   rZ   rW   r   r   r   r[     s   
z$MissingTemplateLoaderTests.test_reprNr   r\   r   r   r   r   r]      s    
	r]   c                   @  s   e Zd ZdZg fd)ddZd*ddZd+ddZd+ddZd+ddZd+ddZ	d+ddZ
d+ddZd+ddZd+ddZd+ddZd+d d!Zd+d"d#Zd+d$d%Zd+d&d'Zd(S ),FlattenerErrorTestsz&
    Tests for L{FlattenerError}.
    rootslist[object]r   error.FlattenerErrorc              
   C  sN   zt d ty& } ztt d }t|||W  Y d }~S d }~ww )Noh noes   )RuntimeError	Exception	traceback
extract_tbsysexc_infor   FlattenerError)r   r`   r'   tbr   r   r   makeFlattenerError  s   z&FlattenerErrorTests.makeFlattenerErrorobjrR   r%   c                 C  s   d| S )NzR(%s)r   )r   rn   r   r   r   fakeFormatRoot  s   z"FlattenerErrorTests.fakeFormatRootr	   c                 C  s&   | j ddgd}| |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)r`   N)rm   r   _rootsr&   r   r   r   rY     s   z$FlattenerErrorTests.test_constructorc                 C  s    |   }| t|t| dS )zd
        The string form of a L{FlattenerError} is identical to its
        representation.
        N)rm   r   r%   rZ   r&   r   r   r   r3   &  s   zFlattenerErrorTests.test_strc                 C  s@   |  ddg}| j|_| tdt|tjtjB 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.
        rp   rq   zException while flattening:
  R\(a\)
  R\(b\)
  File "[^"]*", line [0-9]*, in makeFlattenerError
    raise RuntimeError\("oh noes"\)
RuntimeError: oh noes
$N)	rm   ro   _formatRoot
assertTruerematchrZ   MSr&   r   r   r   "test_reprWithRootsAndWithTraceback.  s   

z6FlattenerErrorTests.test_reprWithRootsAndWithTracebackc                 C  s4   |  g }| tdt|tjtjB 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)rm   rt   ru   rv   rZ   rw   rx   r&   r   r   r   %test_reprWithoutRootsAndWithTracebackD  s   

z9FlattenerErrorTests.test_reprWithoutRootsAndWithTracebackc                 C  s<   t tdg d}| tdt|tjtjB t| dS )rz   rc   Nz3Exception while flattening:
RuntimeError: oh noes
$)	r   rk   re   rt   ru   rv   rZ   rw   rx   r&   r   r   r   (test_reprWithoutRootsAndWithoutTracebackV  s   
z<FlattenerErrorTests.test_reprWithoutRootsAndWithoutTracebackc                 C  s&   |   }| |tdtd dS )zk
        The C{_formatRoot} method formats a short unicode string using the
        built-in repr.
        abcdN)rm   r   rs   r   rZ   r&   r   r   r   !test_formatRootShortUnicodeStringe  s   z5FlattenerErrorTests.test_formatRootShortUnicodeStringc                 C  s*   |   }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)rm   r   r   rs   rZ   r   r'   
longStringr   r   r    test_formatRootLongUnicodeStringm  s   z4FlattenerErrorTests.test_formatRootLongUnicodeStringc                 C  s"   |   }| |dtd dS )zh
        The C{_formatRoot} method formats a short byte string using the
        built-in repr.
        s   abcdNrm   r   rs   rZ   r&   r   r   r   test_formatRootShortByteStringy     z2FlattenerErrorTests.test_formatRootShortByteStringc                 C  s&   |   }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   r   r   r   test_formatRootLongByteString  s   z1FlattenerErrorTests.test_formatRootLongByteStringc                 C  s"   |   }| |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)rm   r   rs   r   r&   r   r   r   test_formatRootTagNoFilename  r   z0FlattenerErrorTests.test_formatRootTagNoFilenamec                 C  s.   |   }td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)rm   r   r   rs   )r   r'   tr   r   r   test_formatRootTagWithFilename  s
   
z2FlattenerErrorTests.test_formatRootTagWithFilenamec                 C  D   |  tttddgg d |  tt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   rk   re   r.   r   r   r   test_string  s   zFlattenerErrorTests.test_stringc                 C  r   )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   r.   r   r   r   test_unicode  s   z FlattenerErrorTests.test_unicodeN)r`   ra   r   rb   )rn   rR   r   r%   r   )r   r   r   r   rm   ro   rY   r3   ry   r{   r|   r~   r   r   r   r   r   r   r   r   r   r   r   r_     s"    


	









r_   c                   @  rJ   )UnsupportedMethodTestsz)
    Tests for L{UnsupportedMethod}.
    r   r	   c                 C  s"   t 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&   r   r   r   r3     s
   zUnsupportedMethodTests.test_strNr   )r   r   r   r   r3   r   r   r   r   r     s    r   )r   
__future__r   ru   ri   rg   twisted.python.compatr   twisted.trialr   twisted.webr   twisted.web.templater   TestCaser   r   r4   rG   rK   rP   r]   r_   SynchronousTestCaser   r   r   r   r   <module>   s&   726 A