%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/twisted/web/test/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/twisted/web/test/__pycache__/test_error.cpython-312.pyc

�

Ϫ�f}A����dZddlmZddlZddlZddlZddlmZddlm	Z	ddl
mZddlm
Z
Gd�d	e	j�ZGd
�de	j�ZGd�d
e	j�ZGd�de	j�ZGd�de	j�ZGd�de	j�ZGd�de	j�ZGd�de	j�ZGd�de	j.�Zy)z
HTTP errors.
�)�annotationsN)�nativeString)�unittest)�error)�Tagc�(�eZdZdZdd�Zdd�Zdd�Zy)�CodeToMessageTestsz<
    L{_codeToMessages} inverts L{_responses.RESPONSES}
    c�R�tjd�}|j|d�y)N�302sFound�r�_codeToMessage�assertEqual��self�ms  �=/usr/lib/python3/dist-packages/twisted/web/test/test_error.py�test_validCodez!CodeToMessageTests.test_validCodes"��� � ��(������H�%�c�R�tjd�}|j|d�y)Ns987rrs  r�test_invalidCodez#CodeToMessageTests.test_invalidCodes"��� � ��(������D�!rc�R�tjd�}|j|d�y)NsInvalidCoderrs  r�test_nonintegerCodez&CodeToMessageTests.test_nonintegerCode!s"��� � ��0������D�!rN��return�None)�__name__�
__module__�__qualname__�__doc__rrr�rrr	r	s���&�"�"rr	c�8�eZdZdZdd�Zdd�Zdd�Zdd�Zdd�Zy)	�
ErrorTestsz<
    Tests for how L{Error} attributes are initialized.
    c��tjd�}|j|jd�|jt	|�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:��
�K�K����������E�*�����Q���*rc��tjd�}|j|jd�|jt	|�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_noMessageForStatus5s:��

�K�K����������D�)�����Q���'rc��|jt�5tjd�ddd�y#1swYyxYw)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�
ValueErrorrr(�rs r�test_invalidStatuszErrorTests.test_invalidStatus>s4��
�
�
�z�
*�	*��K�K�(�)�	*�	*�	*�s�5�>c��tjdd�}|j|jd�|jt	|�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 messagez200 My own messageNr'r+s  r�test_messageExistszErrorTests.test_messageExistsFs?��

�K�K�� 1�2��������$5�6�����Q��!5�6rc���tjdd�}|jt|�d�tjdd�}|jt|�d�y)zh
        C{str()} on an L{Error} returns the code and message it was
        instantiated with.
        r$r%r&��N)rr(rr*r+s  r�test_strzErrorTests.test_strOsN��
�K�K���&������Q���*�
�K�K��U�#������Q���*rNr)	rrrrr-r1r6r9r<r rrr"r"&s ���+�(�*�7�+rr"c�8�eZdZdZdd�Zdd�Zdd�Zdd�Zdd�Zy)	�PageRedirectTestszC
    Tests for how L{PageRedirect} attributes are initialized.
    c�j�tjdd��}|j|jd�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�PageRedirectrr)r+s  rr-z+PageRedirectTests.test_noMessageValidStatusbs*��
���v��8��������M�2rc�f�tjd�}|j|jd�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%NrDr+s  r�#test_noMessageValidStatusNoLocationz5PageRedirectTests.test_noMessageValidStatusNoLocationks(��
���v�&��������E�*rc�j�tjdd��}|j|jd�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@rANrDr+s  r�)test_noMessageInvalidStatusLocationExistsz;PageRedirectTests.test_noMessageInvalidStatusLocationExistsus*��

���v��8��������D�)rc�l�tjddd��}|j|jd�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$r8r@rA�My own message to /fooNrDr+s  r� test_messageExistsLocationExistsz2PageRedirectTests.test_messageExistsLocationExists}s.��

���v�'8�7�K��������$=�>rc�h�tjdd�}|j|jd�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$r8NrDr+s  r�test_messageExistsNoLocationz.PageRedirectTests.test_messageExistsNoLocation�s,��
���v�'8�9��������$5�6rNr�	rrrrr-rGrIrLrNr rrr>r>]s ���3�+�*�?�7rr>c�8�eZdZdZdd�Zdd�Zdd�Zdd�Zdd�Zy)	�InfiniteRedirectionTestszJ
    Tests for how L{InfiniteRedirection} attributes are initialized.
    c�j�tjdd��}|j|jd�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@rArCN�r�InfiniteRedirectionrr)r+s  rr-z2InfiniteRedirectionTests.test_noMessageValidStatus�s*��
�%�%�f�w�?��������M�2rc�f�tjd�}|j|jd�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%NrSr+s  rrGz<InfiniteRedirectionTests.test_noMessageValidStatusNoLocation�s(��
�%�%�f�-��������E�*rc��tjdd��}|j|jd�|jt	|�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@rANr0)rrTrr)r*r+s  rrIzBInfiniteRedirectionTests.test_noMessageInvalidStatusLocationExists�s>��
�%�%�f�w�?��������D�)�����Q���'rc�l�tjddd��}|j|jd�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$r8r@rArKNrSr+s  rrLz9InfiniteRedirectionTests.test_messageExistsLocationExists�s.��

�%�%�f�.?�'�R��������$=�>rc�h�tjdd�}|j|jd�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$r8NrSr+s  rrNz5InfiniteRedirectionTests.test_messageExistsNoLocation�s,��
�%�%�f�.?�@��������$5�6rNrrOr rrrQrQ�s ���3�	+�(�?�7rrQc��eZdZdZdd�Zy)�RedirectWithNoLocationTestszq
    L{RedirectWithNoLocation} is a subclass of L{Error} which sets
    a custom message in the constructor.
    c��tjddd�}|j|jd�|j|jd�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.
        rsREDIRECTshttps://example.comsREDIRECT to https://example.comN)r�RedirectWithNoLocationrr)�urir+s  r�test_validMessagez-RedirectWithNoLocationTests.test_validMessage�sC��
�(�(���>T�U��������$F�G������� 6�7rNr)rrrrr^r rrrZrZ�s���
8rrZc� �eZdZdZdd�Zdd�Zy)�MissingRenderMethodTestsz\
    Tests for how L{MissingRenderMethod} exceptions are initialized and
    displayed.
    c��t�}tj|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���
�
�a�i�i��%��
�
�a�l�l�M�2rc��t�}tj|d�}|jt	|�d|z�y)z�
        A L{MissingRenderMethod} is represented using a custom string
        containing the element's representation and the method name.
        rbzB'MissingRenderMethod': %r had no render method named 'renderThing'N)rcrrdr�reprrhs   r�	test_reprz"MissingRenderMethodTests.test_repr�s=��
�h���%�%�c�=�9�������G�
T��
�	
rNr�rrrrrjrmr rrr`r`�s���
	3�
rr`c� �eZdZdZdd�Zdd�Zy)�MissingTemplateLoaderTestsz^
    Tests for how L{MissingTemplateLoader} exceptions are initialized and
    displayed.
    c�z�t�}tj|�}|j|j|�y)z�
        Given an C{element} argument, the L{MissingTemplateLoader} constructor
        assigns the value to the corresponding attribute.
        N)rcr�MissingTemplateLoaderrerfrhs   rrjz+MissingTemplateLoaderTests.test_constructor�s-��
�h���'�'��,���
�
�a�i�i��%rc�~�t�}tj|�}|jt	|�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)rcrrrrrlrhs   rrmz$MissingTemplateLoaderTests.test_reprs6��
�h���'�'��,������a��"M�PS�"S�TrNrrnr rrrprp�s���
&�Urrpc��eZdZdZgfdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z	dd�Z
dd	�Zdd
�Zdd�Z
dd�Zdd
�Zdd�Zdd�Zdd�Zy)�FlattenerErrorTestsz&
    Tests for L{FlattenerError}.
    c���	td��#t$rK}tjt	j
�d�}t
j|||�cYd}~Sd}~wwxYw)N�oh noes�)�RuntimeError�	Exception�	traceback�
extract_tb�sys�exc_infor�FlattenerError)r�rootsr,�tbs    r�makeFlattenerErrorz&FlattenerErrorTests.makeFlattenerErrorsR��	6��y�)�)���	6��%�%�c�l�l�n�Q�&7�8�B��'�'��5�"�5�5��	6�s�
�	A!�AA�A!�A!c��d|zS)NzR(%s)r )r�objs  r�fakeFormatRootz"FlattenerErrorTests.fakeFormatRoots����}�rc�h�|jddg��}|j|jddg�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  rrjz$FlattenerErrorTests.test_constructors3��
�#�#�3��*�#�5��������C��:�.rc�l�|j�}|jt|�t|��y)zd
        The string form of a L{FlattenerError} is identical to its
        representation.
        N)r�rr*rlr+s  rr<zFlattenerErrorTests.test_str&s*��

�#�#�%������Q���a��)rc��|jddg�}|j|_|jt	j
dt
|�tjtjz�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�z�Exception 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�/���+�+��
�����H�H�+��Q�����r�t�t��	
�
��G�	
rc���|jg�}|jtjdt	|�tj
tjz�t	|��y)��
        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)r�r�r�r�rlr�r�r+s  r�%test_reprWithoutRootsAndWithTracebackz9FlattenerErrorTests.test_reprWithoutRootsAndWithTracebackDsR��

�#�#�B�'������H�H�+��Q�����r�t�t��

�
��G�
	
rc���tjtd�gd�}|jt	j
dt
|�tjtjz�t
|��y)r�rwNz3Exception while flattening:
RuntimeError: oh noes
$)	rrryr�r�r�rlr�r�r+s  r�(test_reprWithoutRootsAndWithoutTracebackz<FlattenerErrorTests.test_reprWithoutRootsAndWithoutTracebackVsW��

� � ��i�!8�"�d�C������H�H�J��Q�����r�t�t��
�

��G�
	
rc��|j�}|j|jtd��t	d��y)zk
        The C{_formatRoot} method formats a short unicode string using the
        built-in repr.
        �abcdN)r�rr�rrlr+s  r�!test_formatRootShortUnicodeStringz5FlattenerErrorTests.test_formatRootShortUnicodeStringes4��

�#�#�%��������|�F�';�<�d�6�l�Krc��|j�}td�}|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�rrr�rl�rr,�
longStrings   r� test_formatRootLongUnicodeStringz4FlattenerErrorTests.test_formatRootLongUnicodeStringms?��

�#�#�%��!�-�0�
����
�M�M�*�%��@�A�	
rc�x�|j�}|j|jd�td��y)zh
        The C{_formatRoot} method formats a short byte string using the
        built-in repr.
        sabcdN�r�rr�rlr+s  r�test_formatRootShortByteStringz2FlattenerErrorTests.test_formatRootShortByteStringys/��

�#�#�%��������w�/��g��?rc�|�|j�}d}|j|j|�td��y)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-Nr�r�s   r�test_formatRootLongByteStringz1FlattenerErrorTests.test_formatRootLongByteString�s:��

�#�#�%��#�
����
�M�M�*�%��A�B�	
rc�x�|j�}|j|jtd��d�y)zu
        The C{_formatRoot} method formats a C{Tag} with no filename information
        as 'Tag <tagName>'.
        �a-tagzTag <a-tag>N)r�rr�rr+s  r�test_formatRootTagNoFilenamez0FlattenerErrorTests.test_formatRootTagNoFilename�s/��

�#�#�%��������s�7�|�4�m�Drc��|j�}tdddd��}|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�ztpl.py�
�)�filename�
lineNumber�columnNumberz-File "tpl.py", line 10, column 20, in "a-tag"N)r�rrr�)rr,�ts   r�test_formatRootTagWithFilenamez2FlattenerErrorTests.test_formatRootTagWithFilename�s?��

�#�#�%����(�r��K�����
�M�M�!��M�	
rc	���|jttjt	d�dgg��d�|jttjt	d�dgg��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�rr*rrryr5s r�test_stringzFlattenerErrorTests.test_string�si��	
�����$�$�\�(�%;�k�]�B�O�P�V�	
�	
�����$�$�\�(�%;�>O�=P�RT�U�V�
%�	
rc	���|jttjt	d�dgg��d�|jttjt	d�dgg��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
ux01234567☃901234567☃901234567☃901234567☃901234567☃901234567☃901234567☃901234567☃901234567☃901234567☃9zwException while flattening:
  '01234567\u2603901234567\u26039<...>01234567\u2603901234567\u26039'
RuntimeError: reason
Nr�r5s r�test_unicodez FlattenerErrorTests.test_unicode�sv��	
�����$�$�\�(�%;�>Q�=R�TV�W�
�
%�		
�	
�����$�$� ��*�-H�,I�2��
�

%�
	
rN)r�zlist[object]rzerror.FlattenerError)r�rcrr*r)rrrrr�r�rjr<r�r�r�r�r�r�r�r�r�r�r�r rrrurusZ���8:�6��/�*�
�,
�$

�L�

�@�

�E�	
�
�$
rruc��eZdZdZdd�Zy)�UnsupportedMethodTestsz)
    Tests for L{UnsupportedMethod}.
    c�h�tjddg�}|jt|�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.
        sHEADsPATCHz#Expected one of [b'HEAD', b'PATCH']N)r�UnsupportedMethodrr*r+s  rr<zUnsupportedMethodTests.test_str�s1��
�#�#�W�h�$7�8�������F�1�	
rNr)rrrrr<r rrr�r��s���

rr�)r�
__future__rr�r}r{�twisted.python.compatr�
twisted.trialr�twisted.webr�twisted.web.templater�TestCaser	r"r>rQrZr`rpru�SynchronousTestCaser�r rr�<module>r�s����#�	�
��.�"��$�"��*�*�"�$4+��"�"�4+�n/7��)�)�/7�d37�x�0�0�37�l8�(�"3�"3�8�"
�x�0�0�
�>U��!2�!2�U�2}
�(�+�+�}
�@
�X�9�9�
r

Zerion Mini Shell 1.0