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: //lib/python3/dist-packages/twisted/web/__pycache__/util.cpython-38.pyc
U

s�@g�0�@s@dZddlmZmZddlZddlmZddlmZm	Z	m
Z
mZddlm
Z
ddlmZddlmZmZmZmZdd	lmZd
d�Zdd
�ZGdd�dej�ZGdd�de�ZGdd�dej�ZGdd�dej�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Z Gdd�de�Z!d d!�Z"d
dddddd!gZ#dS)"z0
An assortment of web server-related utilities.
�)�division�absolute_importN)�urlpath)�_PY3�unicode�nativeString�escape)�fullyQualifiedName)�resource)�	TagLoader�	XMLString�Element�renderer)�
flattenStringcCsdt|�fS)aK
    Wraps <pre> tags around some text and HTML-escape it.

    This is here since once twisted.web.html was deprecated it was hard to
    migrate the html.PRE from current code to twisted.web.template.

    For new code consider using twisted.web.template.

    @return: Escaped text wrapped in <pre> tags.
    @rtype: C{str}
    z
<pre>%s</pre>)r)�text�r�2/usr/lib/python3/dist-packages/twisted/web/util.py�_PREsrcCsZt|t�rtd��|�dd�|�|�ddtt|�d���d��i}t	rV|�d�}|S)a�
    Generate a redirect to the given location.

    @param URL: A L{bytes} giving the location to which to redirect.
    @type URL: L{bytes}

    @param request: The request object to use to generate the redirect.
    @type request: L{IRequest<twisted.web.iweb.IRequest>} provider

    @raise TypeError: If the type of C{URL} a L{unicode} instead of L{bytes}.

    @return: A C{bytes} containing HTML which tries to convince the client agent
        to visit the new location even if it doesn't respect the I{FOUND}
        response code.  This is intended to be returned from a render method,
        eg::

            def render_GET(self, request):
                return redirectTo(b"http://example.com/", request)
    z!Unicode object not allowed as URLsContent-Typestext/html; charset=utf-8z�
<html>
    <head>
        <meta http-equiv="refresh" content="0;URL=%(url)s">
    </head>
    <body bgcolor="#FFFFFF" text="#000000">
    <a href="%(url)s">click here</a>
    </body>
</html>
�url�utf-8�utf8)
�
isinstancer�	TypeErrorZ	setHeaderZredirectrr�decode�encoder)ZURL�requestZcontentrrr�
redirectTo(s

	�

rc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�RedirectTcCstj�|�||_dS�N)r
�Resource�__init__r��selfrrrrr RszRedirect.__init__cCst|j|�Sr)rr�r"rrrr�renderVszRedirect.rendercCs|Srr�r"�namerrrr�getChildYszRedirect.getChildN)�__name__�
__module__�__qualname__�isLeafr r$r'rrrrrOsrc@s eZdZdZdd�Zdd�ZdS)�ChildRedirectorrcCs>|�d�dkr.|�d�s.|�d�s.td|��t�||�dS)Nz://���z..�/zvIt seems you've given me a redirect (%s) that is a child of myself! That's not good, it'll cause an infinite redirect.)�find�
startswith�
ValueErrorrr r!rrrr _s��zChildRedirector.__init__cCs(|j}|�d�s|d7}||7}t|�S)Nr.)r�endswithr,)r"r&rZnewUrlrrrr'gs

zChildRedirector.getChildN)r(r)r*r+r r'rrrrr,]sr,c@s$eZdZdZdZdd�Zdd�ZdS)�ParentRedirectz'
    I redirect to URLPath.here().
    �cCsttj�|���|�Sr)rrZURLPathZfromRequest�herer#rrrr$tszParentRedirect.rendercCs|Srrr#rrrr'wszParentRedirect.getChildN)r(r)r*�__doc__r+r$r'rrrrr3osr3c@s<eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
S)�DeferredResourcezT
    I wrap up a Deferred that will eventually result in a Resource
    object.
    r4cCstj�|�||_dSr)r
rr �d)r"r8rrrr �szDeferredResource.__init__cCs|Srrr%rrrr'�szDeferredResource.getChildcCs*|j�|j|��|j|�ddlm}|S)Nr)�NOT_DONE_YET)r8ZaddCallback�_cbChildZ
addErrback�_ebChildZtwisted.web.serverr9)r"rr9rrrr$�s�zDeferredResource.rendercCs|�t�||��dSr)r$r
ZgetChildForRequest)r"Zchildrrrrr:�szDeferredResource._cbChildcCs|�|�dSr)ZprocessingFailed)r"�reasonrrrrr;�szDeferredResource._ebChildN)
r(r)r*r6r+r r'r$r:r;rrrrr7{sr7c@s0eZdZdZdd�Zedd��Zedd��ZdS)	�_SourceLineElementa
    L{_SourceLineElement} is an L{IRenderable} which can render a single line of
    source code.

    @ivar number: A C{int} giving the line number of the source code to be
        rendered.
    @ivar source: A C{str} giving the source code to be rendered.
    cCst�||�||_||_dSr)r
r �number�source)r"�loaderr>r?rrrr �sz_SourceLineElement.__init__cCs||j�dd��S)zA
        Render the line of source as a child of C{tag}.
        z  u  )r?�replace�r"r�tagrrr�
sourceLine�sz_SourceLineElement.sourceLinecCs|t|j��S)z>
        Render the line number as a child of C{tag}.
        )�strr>rBrrr�
lineNumber�sz_SourceLineElement.lineNumberN)r(r)r*r6r rrDrFrrrrr=�s
r=c@s,eZdZdZdd�Zdd�Zedd��ZdS)	�_SourceFragmentElementa�
    L{_SourceFragmentElement} is an L{IRenderable} which can render several lines
    of source code near the line number of a particular frame object.

    @ivar frame: A L{Failure<twisted.python.failure.Failure>}-style frame object
        for which to load a source line to render.  This is really a tuple
        holding some information from a frame object.  See
        L{Failure.frames<twisted.python.failure.Failure>} for specifics.
    cCst�||�||_dSr�r
r �frame�r"r@rIrrrr �sz_SourceFragmentElement.__init__ccsF|jd}|jd}t|d|d�D]}|t�||���fVq&dS)a$
        Find the source line references by C{self.frame} and yield, in source
        line order, it and the previous and following lines.

        @return: A generator which yields two-tuples.  Each tuple gives a source
            line number and the contents of that source line.
        r4�N)rI�range�	linecache�getline�rstrip)r"�filenamerFZsnipLineNumberrrr�_getSourceLines�s

�z&_SourceFragmentElement._getSourceLinesccsV|��D]H\}}|��}||jdkr,d}nd}t|fd|i��}t|||�VqdS)z�
        Render the source line indicated by C{self.frame} and several
        surrounding lines.  The active line will be given a I{class} of
        C{"snippetHighlightLine"}.  Other lines will be given a I{class} of
        C{"snippetLine"}.
        rKZsnippetHighlightLineZsnippetLine�classN)rQ�clonerIrr=)r"rrCrFrDZnewTagZcssClassr@rrr�sourceLines�sz"_SourceFragmentElement.sourceLinesN)r(r)r*r6r rQrrTrrrrrG�s
	rGc@sHeZdZdZdd�Zedd��Zedd��Zedd	��Zed
d��Z	dS)
�
_FrameElementa�
    L{_FrameElement} is an L{IRenderable} which can render details about one
    frame from a L{Failure<twisted.python.failure.Failure>}.

    @ivar frame: A L{Failure<twisted.python.failure.Failure>}-style frame object
        for which to load a source line to render.  This is really a tuple
        holding some information from a frame object.  See
        L{Failure.frames<twisted.python.failure.Failure>} for specifics.
    cCst�||�||_dSrrHrJrrrr �sz_FrameElement.__init__cCs||jd�S)zY
        Render the name of the file this frame references as a child of C{tag}.
        r4�rIrBrrrrP�sz_FrameElement.filenamecCs|t|jd��S)zc
        Render the source line number this frame references as a child of
        C{tag}.
        rK)rErIrBrrrrF�sz_FrameElement.lineNumbercCs||jd�S)zV
        Render the function name this frame references as a child of C{tag}.
        rrVrBrrr�functionsz_FrameElement.functioncCstt|�|j�S)zn
        Render the source code surrounding the line this frame references,
        replacing C{tag}.
        )rGrrIrBrrrr?sz_FrameElement.sourceN)
r(r)r*r6r rrPrFrWr?rrrrrU�s	


rUc@s$eZdZdZdd�Zedd��ZdS)�
_StackElementzW
    L{_StackElement} renders an L{IRenderable} which can render a list of frames.
    cCst�||�||_dSr)r
r �stackFrames)r"r@rYrrrr sz_StackElement.__init__cs�fdd�|jD�S)zW
        Render the list of frames in this L{_StackElement}, replacing C{tag}.
        csg|]}tt����|��qSr)rUrrS)�.0rI�rCrr�
<listcomp>(s�z(_StackElement.frames.<locals>.<listcomp>)rYrBrr[r�frames#s
�z_StackElement.framesN)r(r)r*r6r rr]rrrrrXsrXc@sFeZdZdZed�Zddd�Zedd��Zedd	��Z	ed
d��Z
dS)
�FailureElementa
    L{FailureElement} is an L{IRenderable} which can render detailed information
    about a L{Failure<twisted.python.failure.Failure>}.

    @ivar failure: The L{Failure<twisted.python.failure.Failure>} instance which
        will be rendered.

    @since: 12.1
    ao
<div xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1">
  <style type="text/css">
    div.error {
      color: red;
      font-family: Verdana, Arial, helvetica, sans-serif;
      font-weight: bold;
    }

    div {
      font-family: Verdana, Arial, helvetica, sans-serif;
    }

    div.stackTrace {
    }

    div.frame {
      padding: 1em;
      background: white;
      border-bottom: thin black dashed;
    }

    div.frame:first-child {
      padding: 1em;
      background: white;
      border-top: thin black dashed;
      border-bottom: thin black dashed;
    }

    div.location {
    }

    span.function {
      font-weight: bold;
      font-family: "Courier New", courier, monospace;
    }

    div.snippet {
      margin-bottom: 0.5em;
      margin-left: 1em;
      background: #FFFFDD;
    }

    div.snippetHighlightLine {
      color: red;
    }

    span.code {
      font-family: "Courier New", courier, monospace;
    }
  </style>

  <div class="error">
    <span t:render="type" />: <span t:render="value" />
  </div>
  <div class="stackTrace" t:render="traceback">
    <div class="frame" t:render="frames">
      <div class="location">
        <span t:render="filename" />:<span t:render="lineNumber" /> in
        <span class="function" t:render="function" />
      </div>
      <div class="snippet" t:render="source">
        <div t:render="sourceLines">
          <span class="lineno" t:render="lineNumber" />
          <code class="code" t:render="sourceLine" />
        </div>
      </div>
    </div>
  </div>
  <div class="error">
    <span t:render="type" />: <span t:render="value" />
  </div>
</div>
NcCst�||�||_dSr)r
r �failure)r"r_r@rrrr �szFailureElement.__init__cCs|t|jj��S)zA
        Render the exception type as a child of C{tag}.
        )r	r_�typerBrrrr`�szFailureElement.typecCs|t|jj��d��S)zB
        Render the exception value as a child of C{tag}.
        r)rr_�valuerrBrrrra�szFailureElement.valuecCstt|�|jj�S)z�
        Render all the frames in the wrapped
        L{Failure<twisted.python.failure.Failure>}'s traceback stack, replacing
        C{tag}.
        )rXrr_r]rBrrr�	traceback�szFailureElement.traceback)N)r(r)r*r6rr@r rr`rarbrrrrr^/s	K


r^cCsNg}tdt|���|j�t|dt�r>|d�d��dd�S|d��dS)a
    Construct an HTML representation of the given failure.

    Consider using L{FailureElement} instead.

    @type myFailure: L{Failure<twisted.python.failure.Failure>}

    @rtype: C{bytes}
    @return: A string containing the HTML representation of the given failure.
    Nrr�ascii�xmlcharrefreplace)	rr^ZaddBoth�appendr�bytesrrZraiseException)Z	myFailure�resultrrr�
formatFailure�s
rh)$r6Z
__future__rrrMZtwisted.pythonrZtwisted.python.compatrrrrZtwisted.python.reflectr	Ztwisted.webr
Ztwisted.web.templaterrr
rrrrrrr,r3r7r=rGrUrXr^rh�__all__rrrr�<module>s8' 12u�