HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/web/test/__pycache__/test_error.cpython-38.pyc
U


W[R?�@sdZddlmZmZddlZddlZddlZddlmZddl	m
Z
mZddlm
Z
ddlmZGdd	�d	ej�ZGd
d�dej�ZGdd
�d
ej�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZdS)z
HTTP errors.
�)�division�absolute_importN)�unittest)�nativeString�_PY3)�error)�Tagc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�CodeToMessageTestsz<
    L{_codeToMessages} inverts L{_responses.RESPONSES}
    cCst�d�}|�|d�dS)N�302sFound�rZ_codeToMessage�assertEqual��self�m�r�=/usr/lib/python3/dist-packages/twisted/web/test/test_error.py�test_validCodes
z!CodeToMessageTests.test_validCodecCst�d�}|�|d�dS)Ns987rr
rrr�test_invalidCodes
z#CodeToMessageTests.test_invalidCodecCst�d�}|�|d�dS)N�InvalidCoderr
rrr�test_nonintegerCode#s
z&CodeToMessageTests.test_nonintegerCodeN)�__name__�
__module__�__qualname__�__doc__rrrrrrrr	sr	c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�
ErrorTestsz<
    Tests for how L{Error} attributes are initialized.
    cCst�d�}|�|jd�dS)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{code} is mapped to a
        descriptive string to which C{message} is assigned.
        �200�OKN�r�Errorr�message�r�errr�test_noMessageValidStatus-s
z$ErrorTests.test_noMessageValidStatuscCst�d�}|�|jd�dS)z�
        If no C{message} argument is passed to the L{Error} constructor and
        C{code} isn't a valid HTTP status code, C{message} stays L{None}.
        rNrr rrr�test_noMessageInvalidStatus7s
z&ErrorTests.test_noMessageInvalidStatuscCst�dd�}|�|jd�dS)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 messageNrr rrr�test_messageExists@szErrorTests.test_messageExistscCs<t�dd�}|�t|�d�t�dd�}|�t|�d�dS)zh
        C{str()} on an L{Error} returns the code and message it was
        instantiated with.
        rrz200 OK��N)rrr�strr rrr�test_strIszErrorTests.test_strN)rrrrr"r#r%r(rrrrr)s

		rc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�PageRedirectTestszC
    Tests for how L{PageRedirect} attributes are initialized.
    cCs tjddd�}|�|jd�dS)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�rZPageRedirectrrr rrrr"\sz+PageRedirectTests.test_noMessageValidStatuscCst�d�}|�|jd�dS)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.
        rrNr.r rrr�#test_noMessageValidStatusNoLocationfs
z5PageRedirectTests.test_noMessageValidStatusNoLocationcCs tjddd�}|�|jd�dS)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}.
        rr*r+Nr.r rrr�)test_noMessageInvalidStatusLocationExistsqsz;PageRedirectTests.test_noMessageInvalidStatusLocationExistscCs"tjdddd�}|�|jd�dS)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}.
        rr$r*r+�My own message to /fooNr.r rrr� test_messageExistsLocationExistszsz2PageRedirectTests.test_messageExistsLocationExistscCst�dd�}|�|jd�dS)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.
        rr$Nr.r rrr�test_messageExistsNoLocation�sz.PageRedirectTests.test_messageExistsNoLocationN�	rrrrr"r/r0r2r3rrrrr)Xs
		r)c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�InfiniteRedirectionTestszJ
    Tests for how L{InfiniteRedirection} attributes are initialized.
    cCs tjddd�}|�|jd�dS)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.
        rr*r+r-N�rZInfiniteRedirectionrrr rrrr"�sz2InfiniteRedirectionTests.test_noMessageValidStatuscCst�d�}|�|jd�dS)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.
        rrNr6r rrrr/�s
z<InfiniteRedirectionTests.test_noMessageValidStatusNoLocationcCs tjddd�}|�|jd�dS)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}.
        rr*r+Nr6r rrrr0�szBInfiniteRedirectionTests.test_noMessageInvalidStatusLocationExistscCs"tjdddd�}|�|jd�dS)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}.
        rr$r*r+r1Nr6r rrrr2�s�z9InfiniteRedirectionTests.test_messageExistsLocationExistscCst�dd�}|�|jd�dS)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.
        rr$Nr6r rrrr3�sz5InfiniteRedirectionTests.test_messageExistsNoLocationNr4rrrrr5�s

r5c@seZdZdZdd�ZdS)�RedirectWithNoLocationTestszq
    L{RedirectWithNoLocation} is a subclass of L{Error} which sets
    a custom message in the constructor.
    cCs.t�ddd�}|�|jd�|�|jd�dS)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
sREDIRECTshttps://example.comsREDIRECT to https://example.comN)rZRedirectWithNoLocationrrZurir rrr�test_validMessage�s
�z-RedirectWithNoLocationTests.test_validMessageN)rrrrr8rrrrr7�sr7c@s eZdZdZdd�Zdd�ZdS)�MissingRenderMethodTestsz\
    Tests for how L{MissingRenderMethod} exceptions are initialized and
    displayed.
    cCs2t�}t�|d�}|�|j|�|�|jd�dS)z�
        Given C{element} and C{renderName} arguments, the
        L{MissingRenderMethod} constructor assigns the values to the
        corresponding attributes.
        �renderThingN)�objectr�MissingRenderMethod�assertIs�elementZ
renderName�rZeltr!rrr�test_constructor�sz)MissingRenderMethodTests.test_constructorcCs*t�}t�|d�}|�t|�d|�dS)z�
        A L{MissingRenderMethod} is represented using a custom string
        containing the element's representation and the method name.
        r:zB'MissingRenderMethod': %r had no render method named 'renderThing'N)r;rr<r�reprr?rrr�	test_repr�s��z"MissingRenderMethodTests.test_reprN�rrrrr@rBrrrrr9�sr9c@s eZdZdZdd�Zdd�ZdS)�MissingTemplateLoaderTestsz^
    Tests for how L{MissingTemplateLoader} exceptions are initialized and
    displayed.
    cCs"t�}t�|�}|�|j|�dS)z�
        Given an C{element} argument, the L{MissingTemplateLoader} constructor
        assigns the value to the corresponding attribute.
        N)r;r�MissingTemplateLoaderr=r>r?rrrr@�s
z+MissingTemplateLoaderTests.test_constructorcCs(t�}t�|�}|�t|�d|�dS)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)r;rrErrAr?rrrrBs
�z$MissingTemplateLoaderTests.test_reprNrCrrrrrD�s
rDc@s�eZdZdZgfdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd S)!�FlattenerErrorTestsz&
    Tests for L{FlattenerError}.
    c
CsXztd��WnFtk
rR}z(t�t��d�}t�|||�WY�Sd}~XYnXdS)N�oh noes�)�RuntimeError�	Exception�	traceback�
extract_tb�sys�exc_infor�FlattenerError)r�rootsr!�tbrrr�makeFlattenerErrors
z&FlattenerErrorTests.makeFlattenerErrorcCsd|S)NzR(%s)r)r�objrrr�fakeFormatRoot!sz"FlattenerErrorTests.fakeFormatRootcCs&|jddgd�}|�|jddg�dS)z�
        Given C{exception}, C{roots}, and C{traceback} arguments, the
        L{FlattenerError} constructor assigns the roots to the C{_roots}
        attribute.
        �a�b)rPN)rRrZ_rootsr rrrr@%sz$FlattenerErrorTests.test_constructorcCs |��}|�t|�t|��dS)zd
        The string form of a L{FlattenerError} is identical to its
        representation.
        N)rRrr'rAr rrrr(/szFlattenerErrorTests.test_strcCs@|�ddg�}|j|_|�t�dt|�tjtjB�t|��dS)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.
        rUrVz�Exception while flattening:
  R\(a\)
  R\(b\)
  File "[^"]*", line [0-9]*, in makeFlattenerError
    raise RuntimeError\("oh noes"\)
RuntimeError: oh noes
$N)	rRrT�_formatRoot�
assertTrue�re�matchrA�M�Sr rrr�"test_reprWithRootsAndWithTraceback8s
��z6FlattenerErrorTests.test_reprWithRootsAndWithTracebackcCs4|�g�}|�t�dt|�tjtjB�t|��dS)��
        The representation of a L{FlattenerError} initialized without roots but
        with a traceback contains a formatted traceback but no roots.
        z�Exception while flattening:
  File "[^"]*", line [0-9]*, in makeFlattenerError
    raise RuntimeError\("oh noes"\)
RuntimeError: oh noes
$N)rRrXrYrZrAr[r\r rrr�%test_reprWithoutRootsAndWithTracebackKs

��z9FlattenerErrorTests.test_reprWithoutRootsAndWithTracebackcCs<t�td�gd�}|�t�dt|�tjtjB�t|��dS)r^rGNz3Exception while flattening:
RuntimeError: oh noes
$)	rrOrIrXrYrZrAr[r\r rrr�(test_reprWithoutRootsAndWithoutTracebackZs
��z<FlattenerErrorTests.test_reprWithoutRootsAndWithoutTracebackcCs&|��}|�|�td��td��dS)zk
        The C{_formatRoot} method formats a short unicode string using the
        built-in repr.
        ZabcdN)rRrrWrrAr rrr�!test_formatRootShortUnicodeStringgsz5FlattenerErrorTests.test_formatRootShortUnicodeStringcCs*|��}td�}|�|�|�td��dS)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)rRrrrWrA�rr!Z
longStringrrr� test_formatRootLongUnicodeStringps
�z4FlattenerErrorTests.test_formatRootLongUnicodeStringcCs"|��}|�|�d�td��dS)zh
        The C{_formatRoot} method formats a short byte string using the
        built-in repr.
        sabcdN�rRrrWrAr rrr�test_formatRootShortByteString{sz2FlattenerErrorTests.test_formatRootShortByteStringcCs&|��}d}|�|�|�td��dS)zx
        The C{_formatRoot} method formats a long byte string using the
        built-in repr with an ellipsis.
        sxabcde-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-Nrdrbrrr�test_formatRootLongByteString�s
�z1FlattenerErrorTests.test_formatRootLongByteStringcCs"|��}|�|�td��d�dS)zu
        The C{_formatRoot} method formats a C{Tag} with no filename information
        as 'Tag <tagName>'.
        �a-tagzTag <a-tag>N)rRrrWrr rrr�test_formatRootTagNoFilename�sz0FlattenerErrorTests.test_formatRootTagNoFilenamecCs.|��}tddddd�}|�|�|�d�dS)z�
        The C{_formatRoot} method formats a C{Tag} with filename information
        using the filename, line, column, and tag information
        rgztpl.py�
�)�filenameZ
lineNumberZcolumnNumberz-File "tpl.py", line 10, column 20, in "a-tag"N)rRrrrW)rr!�trrr�test_formatRootTagWithFilename�s
�z2FlattenerErrorTests.test_formatRootTagWithFilenamecCsD|�tt�td�dgg��d�|�tt�td�dgg��d�dS)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.
        �reasonZ	abc123xyzz?Exception while flattening:
  'abc123xyz'
RuntimeError: reason
Zd0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789zcException while flattening:
  '01234567890123456789<...>01234567890123456789'
RuntimeError: reason
N)rr'rrOrI)rrrr�test_string�s����zFlattenerErrorTests.test_stringcCs`trddinddi}|�tt�td�dgg��d|�|�tt�td�dgg��d|�dS)	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.
        �u�rnu	abc☃xyzzGException while flattening:
  %(u)s'abc\u2603xyz'
RuntimeError: reason
ux01234567☃901234567☃901234567☃901234567☃901234567☃901234567☃901234567☃901234567☃901234567☃901234567☃9z|Exception while flattening:
  %(u)s'01234567\u2603901234567\u26039<...>01234567\u2603901234567\u26039'
RuntimeError: reason
N)rrr'rrOrI)rrprrr�test_unicode�s*������z FlattenerErrorTests.test_unicodeN)rrrrrRrTr@r(r]r_r`rarcrerfrhrmrorrrrrrrFs 
	
			rFc@seZdZdZdd�ZdS)�UnsupportedMethodTestsz)
    Tests for L{UnsupportedMethod}.
    cCs6trdnd}t�ddg�}|�t|�dj|d��dS)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.
        rVrqsHEADsPATCHz'Expected one of [{b}'HEAD', {b}'PATCH'])rVN)rrZUnsupportedMethodrr'�format)rrVr!rrrr(�s
�zUnsupportedMethodTests.test_strN)rrrrr(rrrrrs�srs)rZ
__future__rrrYrMrKZ
twisted.trialrZtwisted.python.compatrrZtwisted.webrZtwisted.web.templaterZTestCaser	rr)r5r7r9rDrFZSynchronousTestCasersrrrr�<module>s$/6:?