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.opt-1.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)ZURL�requestZcontentrrr�
redirectTo(s



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


zChildRedirector.__init__cCs(|j}|�d�s|d7}||7}t|�S)Nr()r�endswithr&)rr 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)rrrrrrtszParentRedirect.rendercCs|S)Nr)rrrrrr!wszParentRedirect.getChildN)r"r#r$�__doc__r%rr!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.
    r.cCstj�|�||_dS)N)r
rr�d)rr2rrrr�szDeferredResource.__init__cCs|S)Nr)rr rrrrr!�szDeferredResource.getChildcCs*|j�|j|��|j|�ddlm}|S)Nr)�NOT_DONE_YET)r2ZaddCallback�_cbChildZ
addErrback�_ebChildZtwisted.web.serverr3)rrr3rrrr�s
zDeferredResource.rendercCs|�t�||��dS)N)rr
ZgetChildForRequest)rZchildrrrrr4�szDeferredResource._cbChildcCs|�|�dS)N)ZprocessingFailed)r�reasonrrrrr5�szDeferredResource._ebChildN)
r"r#r$r0r%rr!rr4r5rrrrr1{sr1c@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�loaderr8r9rrrr�sz_SourceLineElement.__init__cCs||j�dd��S)zA
        Render the line of source as a child of C{tag}.
        z  u  )r9�replace)rr�tagrrr�
sourceLine�sz_SourceLineElement.sourceLinecCs|t|j��S)z>
        Render the line number as a child of C{tag}.
        )�strr8)rrr<rrr�
lineNumber�sz_SourceLineElement.lineNumberN)r"r#r$r0rrr=r?rrrrr7�sr7c@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)rr:rArrrr�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.
        r.�N)rA�range�	linecache�getline�rstrip)r�filenamer?ZsnipLineNumberrrr�_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"}.
        rBZsnippetHighlightLineZsnippetLine�classN)rH�clonerArr7)rrr<r?r=ZnewTagZcssClassr:rrr�sourceLines�sz"_SourceFragmentElement.sourceLinesN)r"r#r$r0rrHrrKrrrrr@�s	r@c@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
rrA)rr:rArrrr�sz_FrameElement.__init__cCs||jd�S)zY
        Render the name of the file this frame references as a child of C{tag}.
        r.)rA)rrr<rrrrG�sz_FrameElement.filenamecCs|t|jd��S)zc
        Render the source line number this frame references as a child of
        C{tag}.
        rB)r>rA)rrr<rrrr?�sz_FrameElement.lineNumbercCs||jd�S)zV
        Render the function name this frame references as a child of C{tag}.
        r)rA)rrr<rrr�functionsz_FrameElement.functioncCstt|�|j�S)zn
        Render the source code surrounding the line this frame references,
        replacing C{tag}.
        )r@rrA)rrr<rrrr9sz_FrameElement.sourceN)
r"r#r$r0rrrGr?rMr9rrrrrL�s		rLc@s$eZdZdZdd�Zedd��ZdS)�
_StackElementzW
    L{_StackElement} renders an L{IRenderable} which can render a list of frames.
    cCst�||�||_dS)N)r
r�stackFrames)rr:rOrrrrsz_StackElement.__init__cs�fdd�|jD�S)zW
        Render the list of frames in this L{_StackElement}, replacing C{tag}.
        csg|]}tt����|��qSr)rLrrJ)�.0rA)r<rr�
<listcomp>)sz(_StackElement.frames.<locals>.<listcomp>)rO)rrr<r)r<r�frames#s
z_StackElement.framesN)r"r#r$r0rrrRrrrrrNsrNc@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)rrTr:rrrr�szFailureElement.__init__cCs|t|jj��S)zA
        Render the exception type as a child of C{tag}.
        )r	rT�type)rrr<rrrrU�szFailureElement.typecCs|t|jj��d��S)zB
        Render the exception value as a child of C{tag}.
        r)rrT�valuer)rrr<rrrrV�szFailureElement.valuecCstt|�|jj�S)z�
        Render all the frames in the wrapped
        L{Failure<twisted.python.failure.Failure>}'s traceback stack, replacing
        C{tag}.
        )rNrrTrR)rrr<rrr�	traceback�szFailureElement.traceback)N)r"r#r$r0rr:rrrUrVrWrrrrrS/s	I
rScCsNg}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)	rrSZaddBoth�appendr�bytes�decoderZraiseException)Z	myFailure�resultrrr�
formatFailure�s
r^)$r0Z
__future__rrrDZtwisted.pythonrZtwisted.python.compatrrrrZtwisted.python.reflectr	Ztwisted.webr
Ztwisted.web.templaterrr
rrrrrrr&r-r1r7r@rLrNrSr^�__all__rrrr�<module>s,' 12u