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: //proc/self/root/lib/python3/dist-packages/twisted/test/__pycache__/test_twisted.cpython-38.pyc
U


W[�+�@sHdZddlmZmZddlZddlZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZGd	d
�d
e�Zdd�Zd
d�ZGdd�de�ZGdd�de�ZGdd�de�Zer�dddgZnddddddddgZeD]hZGdd�de�Ze��dZee_e�r$d �ej��dd!�eg�e_e ��!e��dei�[[q�[dS)"zt
Tests for miscellaneous behaviors of the top-level L{twisted} package (ie, for
the code in C{twisted/__init__.py}.
�)�division�absolute_importN)�
ModuleType)�_checkPythonVersion)�_PY3)�reflect)�TestCasec@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�SetAsideModulez�
    L{SetAsideModule} is a context manager for temporarily removing a module
    from C{sys.modules}.

    @ivar name: The name of the module to remove.
    cCs
||_dS�N)�name)�selfr�r
�;/usr/lib/python3/dist-packages/twisted/test/test_twisted.py�__init__szSetAsideModule.__init__cs6t�fdd�ttj���D��}|D]}tj|=q$|S)z�
        Find the given module and all of its hierarchically inferior modules in
        C{sys.modules}, remove them from it, and return whatever was found.
        cs2g|]*\}}|�jks&|��jd�r||f�qS)�.)r�
startswith)�.0Z
moduleName�module�rr
r�
<listcomp>(s
�z,SetAsideModule._unimport.<locals>.<listcomp>)�dict�list�sys�modules�items)rrrr
rr�	_unimport#s�
zSetAsideModule._unimportcCs|�|j�|_dSr
)rrrrr
r
r�	__enter__3szSetAsideModule.__enter__cCs|�|j�tj�|j�dSr
)rrrr�update)rZexcTypeZexcValue�	tracebackr
r
r�__exit__7szSetAsideModule.__exit__N)�__name__�
__module__�__qualname__�__doc__rrrrr
r
r
rr	s
r	cCs i}td||�tj�|�dS)a
    Take a mapping defining a package and turn it into real C{ModuleType}
    instances in C{sys.modules}.

    Consider these example::

        a = {"foo": "bar"}
        b = {"twisted": {"__version__": "42.6"}}
        c = {"twisted": {"plugin": {"getPlugins": stub}}}

    C{_install(a)} will place an item into C{sys.modules} with C{"foo"} as the
    key and C{"bar" as the value.

    C{_install(b)} will place an item into C{sys.modules} with C{"twisted"} as
    the key.  The value will be a new module object.  The module will have a
    C{"__version__"} attribute with C{"42.6"} as the value.

    C{_install(c)} will place an item into C{sys.modules} with C{"twisted"} as
    the key.  The value will be a new module object with a C{"plugin"}
    attribute.  An item will also be placed into C{sys.modules} with the key
    C{"twisted.plugin"} which refers to that module object.  That module will
    have an attribute C{"getPlugins"} with a value of C{stub}.

    @param modules: A mapping from names to definitions of modules.  The names
        are native strings like C{"twisted"} or C{"unittest"}.  Values may be
        arbitrary objects.  Any value which is not a dictionary will be added to
        C{sys.modules} unmodified.  Any dictionary value indicates the value is
        a new module and its items define the attributes of that module.  The
        definition of this structure is recursive, so a value in the dictionary
        may be a dictionary to trigger another level of processing.

    @return: L{None}
    N)�
_makePackagesrrr)r�resultr
r
r�_install=s"r&cCs�i}t|���D]�\}}|dkrZt|t�rPt|�}|j�t|||��|||<q�|||<qt|t�r�t|jd|�}|j�t|||��|||jd|<|||<q|||<q|S)a�
    Construct module objects (for either modules or packages).

    @param parent: L{None} or a module object which is the Python package
        containing all of the modules being created by this function call.  Its
        name will be prepended to the name of all created modules.

    @param attributes: A mapping giving the attributes of the particular module
        object this call is creating.

    @param result: A mapping which is populated with all created module names.
        This is suitable for use in updating C{sys.modules}.

    @return: A mapping of all of the attributes created by this call.  This is
        suitable for populating the dictionary of C{parent}.

    @see: L{_install}.
    Nr)	rr�
isinstancerr�__dict__rr$r )�parentZ
attributesr%Zattrsr�valuerr
r
rr$es





r$c@sPeZdZdZdZdZdZdZdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dS)�RequirementsTestsa�
    Tests for the import-time requirements checking.

    @ivar unsupportedPythonVersion: The newest version of Python 2.x which is
        not supported by Twisted.
    @type unsupportedPythonVersion: C{tuple}

    @ivar supportedPythonVersion: The oldest version of Python 2.x which is
        supported by Twisted.
    @type supportedPythonVersion: C{tuple}

    @ivar Py3unsupportedPythonVersion: The newest version of Python 3.x which
        is not supported by Twisted.
    @type Py3unsupportedPythonVersion: C{tuple}

    @ivar Py3supportedPythonVersion: The oldest version of Python 3.x which is
        supported by Twisted.
    @type supportedPythonVersion: C{tuple}
    )��)r,�)�r/)r/�cCstj|_dS)z|
        Save the original value of C{sys.version_info} so it can be restored
        after the tests mess with it.
        N)r�version_info�versionrr
r
r�setUp�szRequirementsTests.setUpcCs|jt_dS)z@
        Restore the original values saved in L{setUp}.
        N)r2rr1rr
r
r�tearDown�szRequirementsTests.tearDownc	Cs@|jt_|�t��}t�W5QRX|�d|jt|j	��dS)�w
        L{_checkPythonVersion} raises L{ImportError} when run on a version of
        Python that is too old.
        z'Twisted requires Python %d.%d or later.N)
�unsupportedPythonVersionrr1�assertRaises�ImportErrorr�assertEqual�supportedPythonVersion�str�	exception�rZraisedr
r
r�test_oldPython�s��z RequirementsTests.test_oldPythoncCs|jt_|�t��dS�zz
        L{_checkPythonVersion} returns L{None} when run on a version of Python
        that is sufficiently new.
        N)r:rr1�assertIsNonerrr
r
r�test_newPython�sz RequirementsTests.test_newPythonc	Cs@|jt_|�t��}t�W5QRX|�d|jt|j	��dS)r5z3Twisted on Python 3 requires Python %d.%d or later.N)
�Py3unsupportedPythonVersionrr1r7r8rr9�Py3supportedPythonVersionr;r<r=r
r
r�test_oldPythonPy3�s��z#RequirementsTests.test_oldPythonPy3cCs|jt_|�t��dSr?)rCrr1r@rrr
r
r�test_newPythonPy3�sz#RequirementsTests.test_newPythonPy3N)r r!r"r#r6r:rBrCr3r4r>rArDrEr
r
r
rr+�s
	
r+c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�MakePackagesTestszh
    Tests for L{_makePackages}, a helper for populating C{sys.modules} with
    fictional modules.
    cCs,i}tdtdd�|�|�|tdd��dS)z�
        A non-C{dict} value in the attributes dictionary passed to L{_makePackages}
        is preserved unchanged in the return value.
        N�reactor)rG)r$rr9�rrr
r
r�test_nonModule�sz MakePackagesTests.test_nonModulecCs`i}tdttdd�d�|�|�|t�|�|dt�|�d|dj�|�d|dj�dS)z�
        A C{dict} value in the attributes dictionary passed to L{_makePackages}
        is turned into a L{ModuleType} instance with attributes populated from
        the items of that C{dict} value.
        NZ123�r2��twistedrL)r$r�assertIsInstancerr9r r2rHr
r
r�test_moduleWithAttribute�sz*MakePackagesTests.test_moduleWithAttributecCs�i}tdtttdd�d�d�|�|�|t�|�|dt�|�d|dj�|�|djt�|�d|djj�|�d|djj�dS)z�
        Processing of the attributes dictionary is recursive, so a C{dict} value
        it contains may itself contain a C{dict} value to the same effect.
        NZ321rJ)�webrKrLztwisted.web)r$rrMrr9r rOr2rHr
r
r�test_packageWithModulesz(MakePackagesTests.test_packageWithModuleN)r r!r"r#rIrNrPr
r
r
rrF�s
rFc@s$eZdZdZdZdd�Zdd�ZdS)�OldSubprojectDeprecationBasez�
    Base L{TestCase} for verifying each former subproject has a deprecated
    C{__version__} and a removed C{_version.py}.
    NcCsZt�d�|j��}|�|jtj�|��}|�dt|��|�d�|j�|dd�dS)zS
        The C{__version__} attribute of former subprojects is deprecated.
        z
twisted.{}�zYtwisted.{}.__version__ was deprecated in Twisted 16.0.0: Use twisted.__version__ instead.r�messageN)	r�namedAny�format�
subprojectr9�__version__rLZ
flushWarnings�len)rrZ
warningsShownr
r
r�test_deprecateds�
�z,OldSubprojectDeprecationBase.test_deprecatedc	Cs,|�t��t�d�|j��W5QRXdS)zQ
        Former subprojects no longer have an importable C{_version.py}.
        ztwisted.{}._versionN)r7�AttributeErrorrrTrUrVrr
r
r�test_noversionpy&s
�z-OldSubprojectDeprecationBase.test_noversionpy)r r!r"r#rVrYr[r
r
r
rrQsrQZconchrO�namesZmailZrunnerZwordsZnewsZpairc@seZdZdZeZdS)�SubprojectTestCasez6
        See L{OldSubprojectDeprecationBase}.
        N)r r!r"r#rVr
r
r
rr]7sr]ZVersionDeprecationTestsr���)"r#Z
__future__rrrrL�typesrZtwisted.python._setuprZtwisted.python.compatrZtwisted.pythonrZtwisted.trial.unittestr�objectr	r&r$r+rFrQZsubprojectsrVr]�titleZnewNamer �joinr"�split�globalsrr
r
r
r�<module>sJ%((V-�����