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/web/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/web/test/__pycache__/test_util.cpython-310.pyc
o

5�@g�:�@s*dZddlZddlmZddlmZddlmZddlm	Z	m
Z
ddlmZm
Z
ddlmZdd	lmZdd
lmZddlmZmZmZddlmZmZdd
lmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$Gdd�de
�Z%Gdd�de	�Z&Gdd�de
�Z'Gdd�de
�Z(Gdd�dej)�Z*Gdd�de	�Z+dS)z 
Tests for L{twisted.web.util}.
�N)�defer)�
networkString)�Failure)�SynchronousTestCase�TestCase)�resource�util)�FlattenerError)�FOUND)�Request)�	TagLoader�
flattenString�tags)�DummyChannel�DummyRequest)	�DeferredResource�FailureElement�ParentRedirect�
_FrameElement�_SourceFragmentElement�_SourceLineElement�
_StackElement�
formatFailure�
redirectToc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�RedirectToTestsz"
    Tests for L{redirectTo}.
    cCs^tt�d�}d|_d}t||�|�|jt�|�|j�d�|g�|�|j�d�dg�dS)z�
        L{redirectTo} will set the C{Location} and C{Content-Type} headers on
        its request, and set the response code to C{FOUND}, so the browser will
        be redirected.
        T�GETshttp://target.example.com/4321slocationscontent-typestext/html; charset=utf-8N)	rr�methodr�assertEqual�coder
�responseHeaders�
getRawHeaders��self�request�	targetURL�r%�</usr/lib/python3/dist-packages/twisted/web/test/test_util.py�test_headersAndCode&s
�
�z#RedirectToTests.test_headersAndCodecCs*tt�d�}d|_d}|�tt||�dS)zW
        L{redirectTo} will raise TypeError if unicode object is passed in URL
        Trzhttp://target.example.com/4321N)rrr�assertRaises�	TypeErrorrr!r%r%r&�test_redirectToUnicodeURL9sz)RedirectToTests.test_redirectToUnicodeURLcC�(tdg�}td|�}d}|�||�dS)zq
        Legitimate URLs are fully interpolated in the `redirectTo` response body without transformation
        �shttps://twisted.org/s�
<html>
    <head>
        <meta http-equiv="refresh" content="0;URL=https://twisted.org/">
    </head>
    <body bgcolor="#FFFFFF" text="#000000">
    <a href="https://twisted.org/">click here</a>
    </body>
</html>
N�rrr�r"r#�html�expectedr%r%r&�test_legitimateRedirectBs


z'RedirectToTests.test_legitimateRedirectcCr+)zm
        Malicious URLs are HTML-escaped before interpolating them in the `redirectTo` response body
        r,s?https://twisted.org/"><script>alert(document.location)</script>sX
<html>
    <head>
        <meta http-equiv="refresh" content="0;URL=https://twisted.org/&quot;&gt;&lt;script&gt;alert(document.location)&lt;/script&gt;">
    </head>
    <body bgcolor="#FFFFFF" text="#000000">
    <a href="https://twisted.org/&quot;&gt;&lt;script&gt;alert(document.location)&lt;/script&gt;">click here</a>
    </body>
</html>
Nr-r.r%r%r&�test_maliciousRedirectTs
�
z&RedirectToTests.test_maliciousRedirectN)�__name__�
__module__�__qualname__�__doc__r'r*r1r2r%r%r%r&r!s	rc@s6eZdZdZdefdd�Zdd�Zdd�Zd	d
�ZdS)�ParentRedirectTestsz!
    Test L{ParentRedirect}.
    �requestPathcCsFtt�d�}d|_|�d��d�|_t�}|�|�|j�	d�\}|S)z�
        Render a response to a request with path *requestPath*

        @param requestPath: A slash-separated path like C{b'/foo/bar'}.

        @returns: The value of the I{Location} header.
        Tr�/sLocation)
rrr�lstrip�split�prepathr�renderrr )r"r8r#r�locationr%r%r&�doLocationTestns
z"ParentRedirectTests.doLocationTestcC�(|�d|�d��|�d|�d��dS)zi
        At the URL root issue a redirect to the current URL, removing any query
        string.
        �http://10.0.0.1/r9s/?biff=baffN�rr?�r"r%r%r&�test_locationRoot�sz%ParentRedirectTests.test_locationRootcCr@)zt
        A request for a resource one level down from the URL root produces
        a redirect to the root.
        rAs/foos/foo?bar=sproiiingNrBrCr%r%r&�test_locationToRoot�s
�z'ParentRedirectTests.test_locationToRootcCs:|�d|�d��|�d|�d��|�d|�d��dS)zp
        Requests for resources directly under the path C{/foo/} produce
        redirects to C{/foo/}.
        shttp://10.0.0.1/foo/s/foo/s/foo/bars/foo/bar?biz=bazNrBrCr%r%r&�test_locationUpOne�s

�z&ParentRedirectTests.test_locationUpOneN)	r3r4r5r6�bytesr?rDrErFr%r%r%r&r7is
r7c@sheZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�FailureElementTestszn
    Tests for L{FailureElement} and related helpers which can render a
    L{Failure} as an HTML string.
    cCsRdd�}|jjd|_z|�WdSty(tdd�|_|jjd|_YdSw)zO
        Create a L{Failure} which can be used by the rendering tests.
        cSsd}t|��)NzThis is a problem)�	Exception)�messager%r%r&�lineNumberProbeAlsoBroken�sz<FailureElementTests.setUp.<locals>.lineNumberProbeAlsoBroken�T)�captureVars���N)�__code__�co_firstlineno�base�
BaseExceptionr�failure�frames�frame)r"rKr%r%r&�setUp�s�zFailureElementTests.setUpcCsNttt�tjdd�tjdd���dd�}td|�}d}|�|j|�d��|S)	zN
        L{_SourceLineElement} renders a source line and line number.
        �
lineNumber�r=�
sourceLine�2z    print 'hello'Nu:<div><span>50</span><span>    print 'hello'</span></div>zutf-8)	rrr�div�spanr
�addCallbackr�encode)r"�element�dr0r%r%r&�test_sourceLineElement�s��
�z*FailureElementTests.test_sourceLineElementc	Cs�tttjtjdd�tjdd�dd��|j�}gd�}td|�}d}t|�D]-\}}d}|d	krD||�dd
g|d	k|j	|d|�7}q%||�d|j	|d|�7}q%|�
d�}|�|j|�|S)
z�
        L{_SourceFragmentElement} renders source lines at and around the line
        number indicated by a frame object.
        rWrXrY�sourceLines)u#    message = "This is a problem"u    raise Exception(message)�Nrcz?<div class="snippet{}Line"><span>{}</span><span>{}</span></div>rL�	Highlightu        �utf8)
rrrr[r\rUr
�	enumerate�formatrQr^r]r)	r"r_�sourcer`�stringToCheckForrWrY�template�bytesToCheckForr%r%r&�test_sourceFragmentElement�s6

���
��
z.FailureElementTests.test_sourceFragmentElementcCsFtttjdd��|j�}td|�}|�|jdtt	�
d��d�|S)z�
        The I{filename} renderer of L{_FrameElement} renders the filename
        associated with the frame object used to initialize the
        L{_FrameElement}.
        �filenamerXN�<span>�c�</span>)rrrr\rUr
r]rr�__file__�rstrip�r"r_r`r%r%r&�test_frameElementFilename�s
�z-FailureElementTests.test_frameElementFilenamecCs@tttjdd��|j�}td|�}|�|jd|jdf�|S)z�
        The I{lineNumber} renderer of L{_FrameElement} renders the line number
        associated with the frame object used to initialize the
        L{_FrameElement}.
        rWrXNs<span>%d</span>rL)	rrrr\rUr
r]rrQrsr%r%r&�test_frameElementLineNumbers
z/FailureElementTests.test_frameElementLineNumbercCs4tttjdd��|j�}td|�}|�|jd�|S)z�
        The I{function} renderer of L{_FrameElement} renders the line number
        associated with the frame object used to initialize the
        L{_FrameElement}.
        �functionrXNs&<span>lineNumberProbeAlsoBroken</span>)rrrr\rUr
r]rrsr%r%r&�test_frameElementFunctions
z-FailureElementTests.test_frameElementFunctioncCs\td|j�}|�d�}t��}|d|�}|�|t�|�|j|j�|�|g|j	�
��dS)z�
        The I{source} renderer of L{_FrameElement} renders the source code near
        the source filename/line number associated with the frame object used to
        initialize the L{_FrameElement}.
        Nrh)rrU�lookupRenderMethodrr[�assertIsInstancer�assertIdenticalr�loader�load�r"r_�renderer�tag�resultr%r%r&�test_frameElementSources

z+FailureElementTests.test_frameElementSourcecCs�td|jjdd��}|�d�}t��}|d|�}|�|t�|�|dt�|�	|dj
|jjd�|�|dt�|�	|dj
|jjd�|�|dj�
�|dj�
��|�dt|��dS)z�
        The I{frames} renderer of L{_StackElement} renders each stack frame in
        the list of frames used to initialize the L{_StackElement}.
        N�rTrrL)rrSrTrxrr[ry�listrrzrU�assertNotEqualr{r|r�lenr}r%r%r&�test_stackElement's

 z%FailureElementTests.test_stackElementcCs\t|j�}|�d�}t��}|d|�}|�|t�|�|j|jj	�|�
|g|j���dS)z�
        The I{traceback} renderer of L{FailureElement} renders the failure's
        stack frames using L{_StackElement}.
        �	tracebackN)
rrSrxrr[ryrrz�stackFramesrTrr{r|r}r%r%r&�test_failureElementTraceback9s


z0FailureElementTests.test_failureElementTracebackcCs@t|jttjdd���}td|�}d}|�|jd|d�|S)zi
        The I{type} renderer of L{FailureElement} renders the failure's
        exception type.
        �typerXNsbuiltins.Exceptionrnrp�rrSrrr\r
r]r)r"r_r`�excr%r%r&�test_failureElementTypeFs

z+FailureElementTests.test_failureElementTypecCs4t|jttjdd���}td|�}|�|jd�|S)zi
        The I{value} renderer of L{FailureElement} renders the value's exception
        value.
        �valuerXNs<span>This is a problem</span>r�rsr%r%r&�test_failureElementValueQs
z,FailureElementTests.test_failureElementValueN)r3r4r5r6rVrarlrtrurwr�r�r�r�r�r%r%r%r&rH�s*
rHc@s eZdZdZdd�Zdd�ZdS)�FormatFailureTestsz�
    Tests for L{twisted.web.util.formatFailure} which returns an HTML string
    representing the L{Failure} instance passed to it.
    cCs|�ttt��dS)z}
        If there is an error flattening the L{Failure} instance,
        L{formatFailure} raises L{FlattenerError}.
        N)r(r	r�objectrCr%r%r&�test_flattenerErrorbsz&FormatFailureTests.test_flattenerErrorcCsZztd��tytt��}Ynw|�|t�|�tdd�|D���|�d|�dS)z�
        The return value of L{formatFailure} is a C{str} instance (not a
        C{unicode} instance) with numeric character references for any non-ASCII
        characters meant to appear in the output.
        zFake bugcss�|]}|dkVqdS)�Nr%)�.0�chr%r%r&�	<genexpr>us�z7FormatFailureTests.test_returnsBytes.<locals>.<genexpr>s&#160;N)	rIrRrrryrG�
assertTrue�all�assertIn)r"r�r%r%r&�test_returnsBytesis�z$FormatFailureTests.test_returnsBytesN)r3r4r5r6r�r�r%r%r%r&r�\sr�c@seZdZdd�Zdd�ZdS)�
SDResourcecCs
||_dS�N)�default)r"r�r%r%r&�__init__{s
zSDResource.__init__cCs"t�|j�}t�|�}|�||�Sr�)r�succeedr�rr�getChildWithDefault)r"�namer#r`rr%r%r&r�~s
zSDResource.getChildWithDefaultN)r3r4r5r�r�r%r%r%r&r�zsr�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�DeferredResourceTestsz(
    Tests for L{DeferredResource}.
    cCsDt��}d|_t|�}tgd��}t�||�|�|jddg�dS)NrL)�foo�bar�bazr�r�)r�Resource�isLeafr�r�getChildForRequestr�postpath)r"�r�sr`r%r%r&�testDeferredResource�sz*DeferredResourceTests.testDeferredResourcecCsFg}tg�}|j|_t��}tt�|��}|�|�|�||g�dS)z�
        L{DeferredResource} uses the request object's C{render} method to
        render the resource which is the result of the L{Deferred} being
        handled.
        N)	r�appendr=rr�rrr�r)r"�renderedr#r��deferredResourcer%r%r&�test_render�s
z!DeferredResourceTests.test_rendercCshtg�}|��}tt��}tt�|��}|�|�|�|�	|�|�~t
��|�t�}|�|g�dS)z�
        If the L{Deferred} fails, L{DeferredResource} reports the failure via
        C{processingFailed}, and does not cause an unhandled error to be
        logged.
        N)
r�notifyFinishr�RuntimeErrorrr�failr=r�failureResultOf�gc�collect�flushLoggedErrors)r"r#r`rSr��errorsr%r%r&�test_renderNoFailure�s


z*DeferredResourceTests.test_renderNoFailureN)r3r4r5r6r�r�r�r%r%r%r&r��s
r�),r6r��twisted.internetr�twisted.python.compatr�twisted.python.failurer�twisted.trial.unittestrr�twisted.webrr�twisted.web.errorr	�twisted.web.httpr
�twisted.web.serverr�twisted.web.templaterr
r�twisted.web.test.requesthelperrr�twisted.web.utilrrrrrrrrrrr7rHr�r�r�r�r%r%r%r&�<module>s(,
H5?

Anon7 - 2022
AnonSec Team