Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/twisted/web/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/twisted/web/__pycache__/util.cpython-37.pyc

B

;��]|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�C/opt/alt/python37/lib64/python3.7/site-packages/twisted/web/util.py�_PREsrcCsJt|t�rtd��|�dd�|�|�ddt|�i}trF|�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�utf8)�
isinstancer�	TypeErrorZ	setHeaderZredirectrr�encode)�URL�request�contentrrr�
redirectTo(s



rc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�RedirectTcCstj�|�||_dS)N)r
�Resource�__init__r)�selfrrrrrRszRedirect.__init__cCst|j|�S)N)rr)r rrrr�renderVszRedirect.rendercCs|S)Nr)r �namerrrr�getChildYszRedirect.getChildN)�__name__�
__module__�__qualname__�isLeafrr!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 rrrrr_s


zChildRedirector.__init__cCs(|j}|�d�s|d7}||7}t|�S)Nr*)r�endswithr()r r"rZnewUrlrrrr#gs

zChildRedirector.getChildN)r$r%r&r'rr#rrrrr(]sr(c@s$eZdZdZdZdd�Zdd�ZdS)�ParentRedirectz'
    I redirect to URLPath.here().
    �cCsttj�|���|�S)N)rrZURLPathZfromRequest�here)r rrrrr!tszParentRedirect.rendercCs|S)Nr)r rrrrr#wszParentRedirect.getChildN)r$r%r&�__doc__r'r!r#rrrrr/osr/c@s<eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
S)�DeferredResourcezT
    I wrap up a Deferred that will eventually result in a Resource
    object.
    r0cCstj�|�||_dS)N)r
rr�d)r r4rrrr�szDeferredResource.__init__cCs|S)Nr)r r"rrrrr#�szDeferredResource.getChildcCs*|j�|j|��|j|�ddlm}|S)Nr)�NOT_DONE_YET)r4ZaddCallback�_cbChildZ
addErrback�_ebChildZtwisted.web.serverr5)r rr5rrrr!�s
zDeferredResource.rendercCs|�t�||��dS)N)r!r
ZgetChildForRequest)r �childrrrrr6�szDeferredResource._cbChildcCs|�|�dS)N)ZprocessingFailed)r �reasonrrrrr7�szDeferredResource._ebChildN)
r$r%r&r2r'rr#r!r6r7rrrrr3{sr3c@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�||�||_||_dS)N)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;)r rr?rrr�
lineNumber�sz_SourceLineElement.lineNumberN)r$r%r&r2rrr@rBrrrrr:�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�||�||_dS)N)r
r�frame)r r=rDrrrr�sz_SourceFragmentElement.__init__ccsJ|jd}|jd}x0t|d|d�D]}|t�||���fVq(WdS)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.
        r0�N)rD�range�	linecache�getline�rstrip)r �filenamerBZsnipLineNumberrrr�_getSourceLines�s


z&_SourceFragmentElement._getSourceLinesccsZxT|��D]H\}}|��}||jdkr.d}nd}t|fd|i��}t|||�Vq
WdS)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"}.
        rEZsnippetHighlightLineZsnippetLine�classN)rK�clonerDrr:)r rr?rBr@ZnewTagZcssClassr=rrr�sourceLines�sz"_SourceFragmentElement.sourceLinesN)r$r%r&r2rrKrrNrrrrrC�s	rCc@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�||�||_dS)N)r
rrD)r r=rDrrrr�sz_FrameElement.__init__cCs||jd�S)zY
        Render the name of the file this frame references as a child of C{tag}.
        r0)rD)r rr?rrrrJ�sz_FrameElement.filenamecCs|t|jd��S)zc
        Render the source line number this frame references as a child of
        C{tag}.
        rE)rArD)r rr?rrrrB�sz_FrameElement.lineNumbercCs||jd�S)zV
        Render the function name this frame references as a child of C{tag}.
        r)rD)r rr?rrr�functionsz_FrameElement.functioncCstt|�|j�S)zn
        Render the source code surrounding the line this frame references,
        replacing C{tag}.
        )rCrrD)r rr?rrrr<sz_FrameElement.sourceN)
r$r%r&r2rrrJrBrPr<rrrrrO�s		rOc@s$eZdZdZdd�Zedd��ZdS)�
_StackElementzW
    L{_StackElement} renders an L{IRenderable} which can render a list of frames.
    cCst�||�||_dS)N)r
r�stackFrames)r r=rRrrrrsz_StackElement.__init__cs�fdd�|jD�S)zW
        Render the list of frames in this L{_StackElement}, replacing C{tag}.
        csg|]}tt����|��qSr)rOrrM)�.0rD)r?rr�
<listcomp>)sz(_StackElement.frames.<locals>.<listcomp>)rR)r rr?r)r?r�frames#s
z_StackElement.framesN)r$r%r&r2rrrUrrrrrQsrQc@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�||�||_dS)N)r
r�failure)r rWr=rrrr�szFailureElement.__init__cCs|t|jj��S)zA
        Render the exception type as a child of C{tag}.
        )r	rW�type)r rr?rrrrX�szFailureElement.typecCs|t|jj��d��S)zB
        Render the exception value as a child of C{tag}.
        r)rrW�valuer)r rr?rrrrY�szFailureElement.valuecCstt|�|jj�S)z�
        Render all the frames in the wrapped
        L{Failure<twisted.python.failure.Failure>}'s traceback stack, replacing
        C{tag}.
        )rQrrWrU)r rr?rrr�	traceback�szFailureElement.traceback)N)r$r%r&r2rr=rrrXrYrZrrrrrV/s	I
rVcCsNg}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.
    Nrzutf-8�ascii�xmlcharrefreplace)	rrVZaddBoth�appendr�bytes�decoderZraiseException)Z	myFailure�resultrrr�
formatFailure�s
ra)$r2�
__future__rrrGZtwisted.pythonrZtwisted.python.compatrrrrZtwisted.python.reflectr	Ztwisted.webr
Ztwisted.web.templaterrr
rrrrrrr(r/r3r:rCrOrQrVra�__all__rrrr�<module>s,' 12u