%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f�F����dZddlZddlZddlZddlZddlmZddlmZm	Z	m
Z
mZmZm
Z
mZmZmZmZmZmZmZddlmZddlmZddlmZmZGd�d	e�ZGd
�de�ZGd�d
e�ZGd�de�ZeGd�d��Z Gd�de�Z!Gd�de�Z"Gd�de�Z#Gd�de�Z$Gd�de�Z%Gd�de�Z&Gd�de�Z'Gd �d!e�Z(Gd"�d#e�Z)y)$z%
Tests for L{twisted.python.compat}.
�N)�skipIf)
�_PYPY�_get_async_param�bytesEnviron�cmp�
comparable�execfile�
intToBytes�ioType�	iterbytes�
lazyByteSlice�nativeString�
networkString�reraise)�FilePath)�platform)�SynchronousTestCase�TestCasec�:�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�IOTypeTestsz?
    Test cases for determining a file-like object's type.
    c�f�|jttj��t�y)z=
        An L{io.StringIO} accepts and returns text.
        N)�assertEqualr�io�StringIO�str��selfs �:/usr/lib/python3/dist-packages/twisted/test/test_compat.py�test_3StringIOzIOTypeTests.test_3StringIO)s��	
�������
�.��4�c�f�|jttj��t�y)z=
        An L{io.BytesIO} accepts and returns bytes.
        N)rrr�BytesIO�bytesrs r�
test_3BytesIOzIOTypeTests.test_3BytesIO/s��	
�����
�
��-�u�5r c��t|j�d�5}|jt|�t�ddd�y#1swYyxYw)zT
        A file opened via 'io.open' in text mode accepts and returns text.
        �wN)�open�mktemprrr�r�fs  r�test_3openTextModezIOTypeTests.test_3openTextMode5s?���$�+�+�-��
%�	-�����V�A�Y��,�	-�	-�	-��� A�A
c��t|j�d�5}|jt|�t�ddd�y#1swYyxYw)zW
        A file opened via 'io.open' in binary mode accepts and returns bytes.
        �wbN)r'r(rrr#r)s  r�test_3openBinaryModez IOTypeTests.test_3openBinaryMode<s?���$�+�+�-��
&�	/�!����V�A�Y��.�	/�	/�	/�r,c��tj|j�d�5}|jt	|�t
�ddd�y#1swYyxYw)z�
        The L{codecs} module, oddly, returns a file-like object which returns
        bytes when not passed an 'encoding' argument.
        r.N)�codecsr'r(rrr#r)s  r�test_codecsOpenBytesz IOTypeTests.test_codecsOpenBytesCsC��
�[�[������
-�	/�����V�A�Y��.�	/�	/�	/�s� A�Ac��tj|j�dd��5}|jt	|�t
�ddd�y#1swYyxYw)zY
        When passed an encoding, however, the L{codecs} module returns unicode.
        r.�utf-8)�encodingN)r1r'r(rrrr)s  r�test_codecsOpenTextzIOTypeTests.test_codecsOpenTextKsE���[�[������w�
?�	-�1����V�A�Y��,�	-�	-�	-�s� A�Ac�R�|jtt��t�y)zy
        When passed an object about which no sensible decision can be made, err
        on the side of unicode.
        N)rr�objectrrs r�test_defaultToTextzIOTypeTests.test_defaultToTextRs��
	
������)�3�/r N)�__name__�
__module__�__qualname__�__doc__rr$r+r/r2r6r9�r rrr$s*���5�6�-�/�/�-�0r rc��eZdZdZd�Zd�Zy)�CompatTestszy
    Various utility functions in C{twisted.python.compat} provide same
    functionality as modern Python variants.
    c��t�}|jd�|jd�|jd�t|�}|j�|j	|gd��|jd�t|�}|j�|j	|ddg�|j
d�ddh}|j|�}t|�}|j�|j	|gd��y	)
zG
        L{set} should behave like the expected set interface.
        �b�c�a)rDrBrC�d�r�s)rDrCrFrGN)�set�add�list�sortr�remove�discard�union�rrDrBrEs    r�test_setzCompatTests.test_set`s���
�E��	���c�
�	���c�
�	���c�
���G��	��������O�,�	����
���G��	��������S�#�J�'�	�	�	�#��
�#�J��
�G�G�A�J����G��	��������0�1r c�*�tddg�}|jtt|d�|j	t|�ddg�tddg�}|j
|�}t|�}|j�|j	|gd��y)zS
        L{frozenset} should behave like the expected frozenset interface.
        rDrBrIrFrG)rDrBrFrGN)	�	frozenset�assertRaises�AttributeError�getattrr�sortedrNrJrKrOs    r�test_frozensetzCompatTests.test_frozensetxs|��
�s�C�j�!�����.�'�1�e�<�������S�#�J�/��s�C�j�!��
�G�G�A�J����G��	��������0�1r N)r:r;r<r=rPrWr>r rr@r@Zs���
2�02r r@c�(�eZdZdZd�Zd�Zd�Zd�Zy)�ExecfileCompatTestszE
    Tests for the Python 3-friendly L{execfile} implementation.
    c���|j�}t|d�5}|j|jd��ddd�t	|jd��S#1swY�#xYw)zo
        Write L{content} to a new temporary file, returning the L{FilePath}
        for the new file.
        r.�asciiNr4)r(r'�write�encoder)r�content�pathr*s    r�writeScriptzExecfileCompatTests.writeScript�sY��
�{�{�}��
�$��
�	-��
�G�G�G�N�N�7�+�,�	-�����G�,�-�-�	-�	-�s�!A � A)c��|jd�}ddi}t|j|�|jd|d�y)zX
        L{execfile} executes the specified file in the given global namespace.
        �	foo += 1
�foo��N�r`r	r_r)r�script�globalNamespaces   r�test_execfileGlobalsz(ExecfileCompatTests.test_execfileGlobals�s@���!�!�,�/�� �!�*������o�.�����O�E�2�3r c��|jd�}ddi}ddi}t|j||�|jd|d�|jd|d�y)zk
        L{execfile} executes the specified file in the given global and local
        namespaces.
        rbrc�
��Nrf)rrgrh�localNamespaces    r�test_execfileGlobalsAndLocalsz1ExecfileCompatTests.test_execfileGlobalsAndLocals�s`��
�!�!�,�/�� �"�+����������o�~�>�����_�U�3�4�����^�E�2�3r c��dD]E}|jd|z�}ddi}t|j|�|jd|d��Gy)z�
        L{execfile} reads in the specified file using universal newlines so
        that scripts written on one platform will work on another.
        )�
�
z
zfoo = 'okay'rcN�okayrf)r�
lineEndingrgrhs    r�test_execfileUniversalNewlinesz2ExecfileCompatTests.test_execfileUniversalNewlines�sT��
-�	=�J��%�%�n�z�&A�B�F�$�d�m�O��V�[�[�/�2����V�_�U�%;�<�		=r N)r:r;r<r=r`rirorur>r rrYrY�s���.�4�
4�	=r rYc��eZdZdZd�Zy)�PYPYTestz!
    Identification of PyPy.
    c�~�dtjvr|jt�y|j	t�y)z,
        On PyPy, L{_PYPY} is True.
        �PyPyN)�sys�version�
assertTruer�assertFalsers r�	test_PYPYzPYPYTest.test_PYPY�s*���S�[�[� ��O�O�E�"����U�#r N)r:r;r<r=r~r>r rrwrw�s���$r rwc��eZdZdZd�Zd�Zy)�
ComparablezE
    Objects that can be compared to each other, but not others.
    c��||_y�N)�value)rr�s  r�__init__zComparable.__init__�s	����
r c�n�t|t�stSt|j|j�Sr�)�
isinstancer��NotImplementedrr�)r�others  r�__cmp__zComparable.__cmp__�s'���%��,�!�!��4�:�:�u�{�{�+�+r N)r:r;r<r=r�r�r>r rr�r��s����,r r�c�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	�ComparableTestszR
    L{comparable} decorated classes emulate Python 2's C{__cmp__} semantics.
    c��|jtd�td�k(�|jtd�td�k(�y)zo
        Instances of a class that is decorated by C{comparable} support
        equality comparisons.
        rdreN�r|r�r}rs r�
test_equalityzComparableTests.test_equality�s8��	
���
�1�
��A��6�7�����A��*�Q�-�7�8r c��|jtd�td�k7�|jtd�td�k7�y)zq
        Instances of a class that is decorated by C{comparable} support
        inequality comparisons.
        rdreN)r}r�r|rs r�test_nonEqualityz ComparableTests.test_nonEquality�s8��	
����A��*�Q�-�7�8����
�1�
��A��6�7r c��|jtd�td�kD�|jtd�td�kD�y)zs
        Instances of a class that is decorated by C{comparable} support
        greater-than comparisons.
        rerdr�Nr�rs r�test_greaterThanz ComparableTests.test_greaterThan��8��
	
���
�1�
�
�1�
�5�6�����A���A��6�7r c���|jtd�td�k\�|jtd�td�k\�|jtd�td�k\�y)z|
        Instances of a class that is decorated by C{comparable} support
        greater-than-or-equal comparisons.
        rdrerr�Nr�rs r�test_greaterThanOrEqualz'ComparableTests.test_greaterThanOrEqual��Q��
	
���
�1�
��A��6�7����
�1�
��A��6�7�����A��*�Q�-�7�8r c��|jtd�td�k�|jtd�td�k�y)zp
        Instances of a class that is decorated by C{comparable} support
        less-than comparisons.
        rr�reNr�rs r�
test_lessThanzComparableTests.test_lessThan�r�r c���|jtd�td�k�|jtd�td�k�|jtd�td�k�y)zy
        Instances of a class that is decorated by C{comparable} support
        less-than-or-equal comparisons.
        r�rreNr�rs r�test_lessThanOrEqualz$ComparableTests.test_lessThanOrEqualr�r N)
r:r;r<r=r�r�r�r�r�r�r>r rr�r��s%���9�8�8�9�8�9r r�c�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	�Python3ComparableTestsz;
    Python 3-specific functionality of C{comparable}.
    c�p�|jtd�jt��t�y)z�
        Instances of a class that is decorated by C{comparable} support
        returning C{NotImplemented} from C{__eq__} if it is returned by the
        underlying C{__cmp__} call.
        rdN)rr��__eq__r8r�rs r�test_notImplementedEqualsz0Python3ComparableTests.test_notImplementedEquals�%��	
����A��-�-�f�h�7��Hr c�p�|jtd�jt��t�y)z�
        Instances of a class that is decorated by C{comparable} support
        returning C{NotImplemented} from C{__ne__} if it is returned by the
        underlying C{__cmp__} call.
        rdN)rr��__ne__r8r�rs r�test_notImplementedNotEqualsz3Python3ComparableTests.test_notImplementedNotEqualsr�r c�p�|jtd�jt��t�y)z�
        Instances of a class that is decorated by C{comparable} support
        returning C{NotImplemented} from C{__gt__} if it is returned by the
        underlying C{__cmp__} call.
        rdN)rr��__gt__r8r�rs r�test_notImplementedGreaterThanz5Python3ComparableTests.test_notImplementedGreaterThan$r�r c�p�|jtd�jt��t�y)z�
        Instances of a class that is decorated by C{comparable} support
        returning C{NotImplemented} from C{__lt__} if it is returned by the
        underlying C{__cmp__} call.
        rdN)rr��__lt__r8r�rs r�test_notImplementedLessThanz2Python3ComparableTests.test_notImplementedLessThan,r�r c�p�|jtd�jt��t�y)z�
        Instances of a class that is decorated by C{comparable} support
        returning C{NotImplemented} from C{__ge__} if it is returned by the
        underlying C{__cmp__} call.
        rdN)rr��__ge__r8r�rs r�$test_notImplementedGreaterThanEqualsz;Python3ComparableTests.test_notImplementedGreaterThanEquals4r�r c�p�|jtd�jt��t�y)z�
        Instances of a class that is decorated by C{comparable} support
        returning C{NotImplemented} from C{__le__} if it is returned by the
        underlying C{__cmp__} call.
        rdN)rr��__le__r8r�rs r�!test_notImplementedLessThanEqualsz8Python3ComparableTests.test_notImplementedLessThanEquals<r�r N)
r:r;r<r=r�r�r�r�r�r�r>r rr�r�s+���I�I�I�I�I�Ir r�c�"�eZdZdZd�Zd�Zd�Zy)�CmpTestszA
    L{cmp} should behave like the built-in Python 2 C{cmp}.
    c��|jtdd�d�|jtdd�d�|jtdgdg�d�y)z5
        L{cmp} returns 0 for equal objects.
        rDrrdN�rrrs r�test_equalszCmpTests.test_equalsJsJ��	
����S�#���*�����Q���A�&�����a�S�1�#���*r c�t�|jtdd�d�|jtdd�d�y)zS
        L{cmp} returns 1 if its first argument is bigger than its second.
        �rrd�z�aNr�rs rr�zCmpTests.test_greaterThanRs0��	
����Q���A�&�����T�4��!�,r c�t�|jtdd�d�|jtdd�d�y)zU
        L{cmp} returns -1 if its first argument is smaller than its second.
        g�������?gffffff@���r��dNr�rs rr�zCmpTests.test_lessThanYs0��	
����S�#���+�����T�4��"�-r N)r:r;r<r=r�r�r�r>r rr�r�Es���+�-�.r r�c�:�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�StringTestsz8
    Compatibility functions and types for strings.
    c�x�|jt|�|�|jt|�t�y)z�
        Raise an exception indicating a failed test if the output of
        C{nativeString(original)} is unequal to the expected string, or is not
        a native string.
        N)rr�assertIsInstancer)r�original�expecteds   r�assertNativeStringzStringTests.assertNativeStringfs.��	
����h�/��:����l�8�4�c�:r c�:�|jttd�y)zj
        C{nativeString} raises a C{UnicodeError} if input bytes are not ASCII
        decodable.
        ��N�rS�UnicodeErrorrrs r�test_nonASCIIBytesToStringz&StringTests.test_nonASCIIBytesToStringos��
	
���,��g�>r c�:�|jttd�y)zk
        C{nativeString} raises a C{UnicodeError} if input Unicode is not ASCII
        encodable.
        uሴNr�rs r�test_nonASCIIUnicodeToStringz(StringTests.test_nonASCIIUnicodeToStringvs��
	
���,��h�?r c�(�|jdd�y)z
        C{nativeString} converts bytes to the native string format, assuming
        an ASCII encoding if applicable.
        shello�helloN�r�rs r�test_bytesToStringzStringTests.test_bytesToString}s��
	
����'�2r c�(�|jdd�y)z�
        C{nativeString} converts unicode to the native string format, assuming
        an ASCII encoding if applicable.
        zGood dayNr�rs r�test_unicodeToStringz StringTests.test_unicodeToString�s��
	
���
�J�7r c�(�|jdd�y)zJ
        C{nativeString} leaves native strings as native strings.
        zHello!Nr�rs r�test_stringToStringzStringTests.test_stringToString�s��	
����(�3r c�:�|jttd�y)zu
        C{nativeString} raises a C{TypeError} if given an object that is not a
        string of some sort.
        rdN)rS�	TypeErrorrrs r�test_unexpectedTypezStringTests.test_unexpectedType�s��
	
���)�\�1�5r N)r:r;r<r=r�r�r�r�r�r�r�r>r rr�r�as+���;�?�@�3�8�4�6r r�c�"�eZdZdZd�Zd�Zd�Zy)�NetworkStringTestsz%
    Tests for L{networkString}.
    c�:�|jdtd��y)zu
        L{networkString} returns a C{unicode} object passed to it encoded into
        a C{bytes} instance.
        sfoorcN)rrrs r�test_strzNetworkStringTests.test_str�s��
	
�����u�!5�6r c�:�|jttd�y)z�
        L{networkString} raises L{UnicodeError} if passed a C{unicode} instance
        containing characters not encodable in ASCII.
        u☃N)rSr�rrs r�test_unicodeOutOfRangez)NetworkStringTests.test_unicodeOutOfRange�s��
	
���,�
�}�Er c��|jttt��|jttd�y)z�
        L{networkString} raises L{TypeError} if passed a non-string object or
        the wrong type of string object.
        sbytesN)rSr�rr8rs r�test_nonStringz!NetworkStringTests.test_nonString�s*��
	
���)�]�F�H�=����)�]�H�=r N)r:r;r<r=r�r�r�r>r rr�r��s���7�F�>r r�c��eZdZdZd�Zd�Zy)�ReraiseTestszH
    L{reraise} re-raises exceptions on both Python 2 and Python 3.
    c��	ddz	td�|j	d�y#t$rtj�\}}}Y�BwxYw#t$r�tj�\}}}|j|t�|j|�|jtj�dtj|�d�YywxYw)z�
        Calling L{reraise} with an exception instance and a traceback of
        L{None} re-raises it with a new traceback.
        rdrN�The exception was not raised.r�)�
BaseExceptionrz�exc_infor�failr�ZeroDivisionError�assertIs�assertNotEqual�	traceback�	format_tb�r�typr��tb�typ2�value2�tb2s       r�test_reraiseWithNonez!ReraiseTests.test_reraiseWithNone�s���
	,�
��E�
	7��E�4� �
�I�I�5�6���	,� �\�\�^�N�C���	,���	� #�����D�&�#����T�#4�5��M�M�%��(�����#�#�B�'��+�Y�-@�-@��-E�b�-I�
�		��!�&�A
�!A
�	A
�
BC�Cc��	ddz	t�|j	d�y#t$rtj�\}}}Y�BwxYw#t$r�tj�\}}}|j|t�|j|�|jtj�dtj|�d�YywxYw)z�
        Calling L{reraise} with an exception instance and a traceback
        re-raises the exception with the given traceback.
        rdrr�r�N)
r�rzr�rr�rr�r�r�r�r�s       r�test_reraiseWithTracebackz&ReraiseTests.test_reraiseWithTraceback�s���
	,�
��E�	7��E�2��
�I�I�5�6���	,� �\�\�^�N�C���	,���	X� #�����D�&�#����T�#4�5��M�M�%��(����Y�0�0��4�R�8�)�:M�:M�c�:R�SU�:V�W�		X�r�N)r:r;r<r=r�r�r>r rr�r��s���7�*7r r�c�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�Python3BytesTestszB
    Tests for L{iterbytes}, L{intToBytes}, L{lazyByteSlice}.
    c�X�d}tt|��}|j|gd��y)z�
        When L{iterbytes} is called with a bytestring, the returned object
        can be iterated over, resulting in the individual bytes of the
        bytestring.
        sabcd)r��b�cr�N)rJrr)r�input�results   r�test_iterationz Python3BytesTests.test_iteration�s)�����i��&�'������!9�:r c�:�|jtd�d�y)z�
        When L{intToBytes} is called with an integer, the result is an
        ASCII-encoded string representation of the number.
        ��s213N)rr
rs r�test_intToBytesz!Python3BytesTests.test_intToBytes�s��
	
����C��&�1r c�P�d}|jtt|��|�y)zv
        L{lazyByteSlice} called with some bytes returns a semantically equal
        version of these bytes.
        �123XYZN�rr#r
�r�datas  r�test_lazyByteSliceNoOffsetz,Python3BytesTests.test_lazyByteSliceNoOffset�s#��
������}�T�2�3�T�:r c�X�d}|jtt|d��|dd�y)z�
        L{lazyByteSlice} called with some bytes and an offset returns a
        semantically equal version of these bytes starting at the given offset.
        rreNrrs  r�test_lazyByteSliceOffsetz*Python3BytesTests.test_lazyByteSliceOffsets+��
������}�T�1�5�6��Q�R��Ar c	�Z�d}|jtt|dd��|dd�y)z�
        L{lazyByteSlice} called with some bytes, an offset and a length returns
        a semantically equal version of these bytes starting at the given
        offset, up to the given length.
        rrer��Nrrs  r�!test_lazyByteSliceOffsetAndLengthz3Python3BytesTests.test_lazyByteSliceOffsetAndLength	s-��������}�T�1�a�8�9�4��!�9�Er N)	r:r;r<r=r�r�rrr	r>r rr�r��s"���;�2�;�B�Fr r�c�L�eZdZdZeej�d�d��Zy)�BytesEnvironTestsz$
    Tests for L{BytesEnviron}.
    z+Environment vars are always str on Windows.c��t�}t�}|j�D]9\}}|jt	|��|jt	|���;|jt
|�tg�y)zz
        The output of L{BytesEnviron} should always be a L{dict} with L{bytes}
        values and L{bytes} keys.
        N)rrH�itemsrI�typerrJr#)rr��types�key�vals     r�test_alwaysBytesz"BytesEnvironTests.test_alwaysBytessc������������	!�H�C���I�I�d�3�i� ��I�I�d�3�i� �	!�	
����e��u�g�.r N)r:r;r<r=rr�	isWindowsrr>r rrrs0�����H��� �"O�P�/�Q�/r rc��eZdZdZd�Zd�Zy)�GetAsyncParamTestsz=
    Tests for L{twisted.python.compat._get_async_param}
    c�,�|jtd��d�|jtd��d�|jtdddiddi��d�|jtdddiddi��d�|jttdddi�y)z�
        L{twisted.python.compat._get_async_param} uses isAsync by default,
        or deprecated async keyword argument if isAsync is None.
        F)�isAsyncTrN�asyncr>)rrrSr�rs r�test_get_async_paramz'GetAsyncParamTests.test_get_async_param-s���
	
���)�%�8�%�@����)�$�7��>����)�K�$�K�7�E�:J�K�U�S����)�J�$�J�7�D�/�J�D�Q����)�%5�u�w��>N�Or c��|jtd	ddiddi��d�|j|jg��}|j|ddd�y)
z�
        L{twisted.python.compat._get_async_param} raises a deprecation
        warning if async keyword argument is passed.
        rNrF)�offendingFunctionsr�messagez:'async' keyword argument is deprecated, please use isAsyncr>)rr�
flushWarnings� test_get_async_param_deprecation)r�currentWarningss  rrz3GetAsyncParamTests.test_get_async_param_deprecation8sh��
	
���)�K�$�K�7�E�:J�K�U�S��,�,� $� E� E�F�-�
��	
����A��y�)�H�	
r N)r:r;r<r=rrr>r rrr(s���	P�
r r)*r=r1rrzr��unittestr�twisted.python.compatrrrrrr	r
rrr
rrr�twisted.python.filepathr�twisted.python.runtimer�twisted.trial.unittestrrrr@rYrwr�r�r�r�r�r�r�r�rrr>r r�<module>r%s��
�
�	�
�������-�+�@�30�%�30�l*2�%�*2�Z-=�-�-=�`$�"�$��,�,��,�79�)�79�t3I�0�3I�l.�"�.�856�%�56�p>�,�>�8+7�&�+7�\-F�+�-F�`/��/�*
�,�
r 

Zerion Mini Shell 1.0