
    Vhw                        d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	m
Z
mZmZmZmZmZmZmZmZmZ ddlmZmZ ddlmZmZ ddlmZ dd	lmZ dd
lmZ ddl m!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z) ddl*m+Z+m,Z, ddl-m.Z.m/Z/m0Z0 ddl1m2Z2m3Z3m4Z4m5Z5 ddl6m7Z7m8Z8m9Z9 d Z:de;de8de;fdZ< G d de)jz                        Z> G d de)jz                        Z? G d de)jz                        Z@ G d d e+      ZA G d! d"e+      ZB G d# d$e+      ZC G d% d&e+      ZD G d' d(      ZEd)ZF G d* d+ej                  ej                        ZId,ee	e   eJf   ded-   fd.ZK ee9       G d/ d0             ZL G d1 d2e+      ZMd3 ZNd4ZO e       ZP ee9       G d5 d6             ZQ ee9       G d7 d8             ZRh d9ZS G d: d;      ZT eT       ZU	 	 dAde8d<e7d=ee;   d>eee#gd?f      deVf
d@ZWy)BzG
twisted.web.util and twisted.web.template merged to avoid cyclic deps
    N)OrderedDictescape)IOAnyAnyStrCallableDictListMappingOptionalTupleUnioncast)handlermake_parser)AttributesNSImplLocator)implementer)Deferred)Logger)urlpath)Failure)FilePath)fullyQualifiedName)resource)Elementrenderer)FlattenableflattenflattenString)CDATACommentTagslot)IRenderableIRequestITemplateLoaderc                      dt        |        dS )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>z</pre>r   )texts    J/home/dcms/DCMS/lib/python3.12/site-packages/twisted/web/_template_util.py_PREr,   ,   s     6$<.''    URLrequestreturnc                     t        | t              st        d      |j                  dd       |j	                  |        ddt        | j                  d            j                  d      iz  }|S )a  
    Generate a redirect to the given location.

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

    @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{str} instead of L{bytes}.

    @return: A L{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URL must be bytess   Content-Types   text/html; charset=utf-8s   
<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>
s   urlutf-8)
isinstancebytes	TypeError	setHeaderredirectr   decodeencode)r.   r/   contents      r+   
redirectTor;   ;   sq    ( c5!+,,o'BCS	 	szz'*+227;G Nr-   c                   8     e Zd ZdZdZdef fdZd Zd Z xZ	S )Redirectz
    Resource that redirects to a specific URL.

    @ivar url: Redirect target URL to put in the I{Location} response header.
    @type url: L{bytes}
    Turlc                 0    t         |           || _        y N)super__init__r>   )selfr>   	__class__s     r+   rB   zRedirect.__init__n   s    r-   c                 .    t        | j                  |      S r@   )r;   r>   )rC   r/   s     r+   renderzRedirect.renderr   s    $((G,,r-   c                     | S r@    rC   namer/   s      r+   getChildzRedirect.getChildu       r-   )
__name__
__module____qualname____doc__isLeafr4   rB   rF   rK   __classcell__)rD   s   @r+   r=   r=   d   s%     FE -r-   r=   c                   $    e Zd ZdZdZdedefdZy)ParentRedirectu  
    Redirect to the nearest directory and strip any query string.

    This generates redirects like::

        /              →  /
        /foo           →  /
        /foo?bar       →  /
        /foo/          →  /foo/
        /foo/bar       →  /foo/
        /foo/bar?baz   →  /foo/

    However, the generated I{Location} header contains an absolute URL rather
    than a path.

    The response is the same regardless of HTTP method.
       r/   r0   c                     t        t        j                  j                  |      j	                               j                  d      }t        ||      S )zN
        Respond to all requests by redirecting to nearest directory.
        ascii)strr   URLPathfromRequestherer9   r;   )rC   r/   r[   s      r+   rF   zParentRedirect.render   s>     7??..w7<<>?FFwO$((r-   N)rM   rN   rO   rP   rQ   r'   r4   rF   rH   r-   r+   rT   rT   y   s!    $ F)h )5 )r-   rT   c                   2    e Zd ZdZdZd Zd Zd Zd Zd Z	y)	DeferredResourcezT
    I wrap up a Deferred that will eventually result in a Resource
    object.
    rU   c                 P    t         j                  j                  |        || _        y r@   )r   ResourcerB   d)rC   r`   s     r+   rB   zDeferredResource.__init__   s    ""4(r-   c                     | S r@   rH   rI   s      r+   rK   zDeferredResource.getChild   rL   r-   c                     | j                   j                  | j                  |      j                  | j                  |       ddlm} |S )Nr   )NOT_DONE_YET)r`   addCallback_cbChild
addErrback_ebChildtwisted.web.serverrc   )rC   r/   rc   s      r+   rF   zDeferredResource.render   s4    4=='2==dmmWU3r-   c                 N    |j                  t        j                  ||             y r@   )rF   r   getChildForRequest)rC   childr/   s      r+   re   zDeferredResource._cbChild   s    x225'BCr-   c                 &    |j                  |       y r@   )processingFailed)rC   reasonr/   s      r+   rg   zDeferredResource._ebChild   s      (r-   N)
rM   rN   rO   rP   rQ   rB   rK   rF   re   rg   rH   r-   r+   r]   r]      s(    
 FD)r-   r]   c                   6    e Zd ZdZd Zed        Zed        Zy)_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.
    c                 L    t        j                  | |       || _        || _        y r@   )r   rB   numbersource)rC   loaderrr   rs   s       r+   rB   z_SourceLineElement.__init__   s     v&r-   c                 F     || j                   j                  dd            S )zA
        Render the line of source as a child of C{tag}.
        z  u     )rs   replacerC   r/   tags      r+   
sourceLinez_SourceLineElement.sourceLine   s!    
 4;;&&t-BCDDr-   c                 8     |t        | j                              S )z>
        Render the line number as a child of C{tag}.
        )rX   rr   rw   s      r+   
lineNumberz_SourceLineElement.lineNumber   s    
 3t{{#$$r-   N)rM   rN   rO   rP   rB   r   ry   r{   rH   r-   r+   rp   rp      s6    
 E E % %r-   rp   c                   ,    e Zd ZdZd Zd Zed        Zy)_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.
    c                 >    t        j                  | |       || _        y r@   r   rB   framerC   rt   r   s      r+   rB   z_SourceFragmentElement.__init__       v&
r-   c              #      K   | j                   d   }| j                   d   }t        |dz
  |dz         D ]*  }|t        j                  ||      j	                         f , yw)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.
        rU      N)r   range	linecachegetlinerstrip)rC   filenamer{   snipLineNumbers       r+   _getSourceLinesz&_SourceFragmentElement._getSourceLines   sc      ::a=ZZ]
#JNJNC 	YN!9#4#4X~#N#U#U#WXX	Ys   AA!c           	   #      K   | j                         D ]N  \  }}|j                         }|| j                  d   k(  rd}nd}t         |di d|i      }t	        |||       P yw)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"}.
        r   snippetHighlightLinesnippetLineclassNrH   )r   cloner   	TagLoaderrp   )rC   r/   rx   r{   ry   newTagcssClassrt   s           r+   sourceLinesz"_SourceFragmentElement.sourceLines   sr      '+&:&:&< 	E"J
YY[FTZZ]*1(v<((;<=F$VZDD	Es   A#A%N)rM   rN   rO   rP   rB   r   r   r   rH   r-   r+   r}   r}      s(    Y E Er-   r}   c                   V    e Zd ZdZd Zed        Zed        Zed        Zed        Z	y)_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.
    c                 >    t        j                  | |       || _        y r@   r   r   s      r+   rB   z_FrameElement.__init__	  r   r-   c                 ,     || j                   d         S )zY
        Render the name of the file this frame references as a child of C{tag}.
        rU   r   rw   s      r+   r   z_FrameElement.filename      
 4::a=!!r-   c                 >     |t        | j                  d               S )zc
        Render the source line number this frame references as a child of
        C{tag}.
        r   )rX   r   rw   s      r+   r{   z_FrameElement.lineNumber  s     3tzz!}%&&r-   c                 ,     || j                   d         S )zV
        Render the function name this frame references as a child of C{tag}.
        r   r   rw   s      r+   functionz_FrameElement.function  r   r-   c                 @    t        t        |      | j                        S )zn
        Render the source code surrounding the line this frame references,
        replacing C{tag}.
        )r}   r   r   rw   s      r+   rs   z_FrameElement.source#  s     &indjjAAr-   N)
rM   rN   rO   rP   rB   r   r   r{   r   rs   rH   r-   r+   r   r      s^     " " ' ' " " B Br-   r   c                   &    e Zd ZdZd Zed        Zy)_StackElementzW
    L{_StackElement} renders an L{IRenderable} which can render a list of frames.
    c                 >    t        j                  | |       || _        y r@   )r   rB   stackFrames)rC   rt   r   s      r+   rB   z_StackElement.__init__1  s    v&&r-   c           	          | j                   D cg c]%  }t        t        |j                               |      ' c}S c c}w )zW
        Render the list of frames in this L{_StackElement}, replacing C{tag}.
        )r   r   r   r   )rC   r/   rx   r   s       r+   framesz_StackElement.frames5  s;     GKFVFV
=BM)CIIK0%8
 	
 
s   *<N)rM   rN   rO   rP   rB   r   r   rH   r-   r+   r   r   ,  s     ' 
 
r-   r   c                       e Zd ZdZdded    fdZddee   dee   dee   fdZdee   d	ee   ddfd
Zdee   dee   fdZ	y)
_NSContextzL
    A mapping from XML namespaces onto their prefixes in the document.
    Nparentc                 ^    || _         |t        |j                        | _        yddi| _        y)ze
        Pull out the parent's namespaces, if there's no parent then default to
        XML.
        Nz$http://www.w3.org/XML/1998/namespacexml)r   r   nss)rC   r   s     r+   rB   z_NSContext.__init__D  s-    
 ;Fvzz;RDH>FDHr-   kr`   r0   c                 :    | j                   j                  ||      S )z\
        Get a prefix for a namespace.

        @param d: The default prefix value.
        )r   get)rC   r   r`   s      r+   r   z_NSContext.getO  s     xx||Aq!!r-   vc                 <    | j                   j                  ||       y)zH
        Proxy through to setting the prefix for the namespace.
        N)r   __setitem__)rC   r   r   s      r+   r   z_NSContext.__setitem__W  s     	Q"r-   c                 8    | j                   j                  |      S )zH
        Proxy through to getting the prefix for the namespace.
        )r   __getitem__)rC   r   s     r+   r   z_NSContext.__getitem__]  s     xx##A&&r-   r@   )
rM   rN   rO   rP   r   rB   rX   r   r   r   rH   r-   r+   r   r   ?  s}    	Gx5 	G"Xc] "x} " "#Xc] #x} # #'Xc] 'x} 'r-   r   z4http://twistedmatrix.com/ns/twisted.web.template/0.1c                   *   e Zd ZdZdee   fdZdeddfdZd"dZ	d"d	Z
d
ededdfdZdee   deddfdZdee   ddfdZdeeef   dee   deddfdZdeddfdZdeeef   dee   ddfdZdedededdfdZdeddfdZd"dZd"dZd eddfd!Zy)#_ToStanzd
    A SAX parser which converts an XML document to the Twisted STAN
    Document Object Model.
    sourceFilenamec                 >    || _         t               | _        d| _        y)zP
        @param sourceFilename: the filename the XML was loaded out of.
        FN)r   r   	prefixMapinCDATA)rC   r   s     r+   rB   z_ToStan.__init__m  s     -#r-   locatorr0   Nc                     || _         y)zY
        Set the document locator, which knows about line and character numbers.
        N)r   )rC   r   s     r+   setDocumentLocatorz_ToStan.setDocumentLocatoru  s     r-   c                 P    g | _         | j                   | _        g | _        g | _        y)z*
        Initialise the document.
        N)documentcurrentstack
xmlnsAttrsrC   s    r+   startDocumentz_ToStan.startDocument{  s$     $&}} "
13r-   c                      y)z!
        Document ended.
        NrH   r   s    r+   endDocumentz_ToStan.endDocument      r-   targetdatac                      y)z6
        Processing instructions are ignored.
        NrH   )rC   r   r   s      r+   processingInstructionz_ToStan.processingInstruction  r   r-   prefixuric                     t        | j                        | _        || j                  |<   |t        k(  ry|| j                  j	                  d|f       y| j                  j	                  d|z  |f       y)z
        Set up the prefix mapping, which maps fully qualified namespace URIs
        onto namespace prefixes.

        This gets called before startElementNS whenever an C{xmlns} attribute
        is seen.
        Nxmlnszxmlns:%s)r   r   TEMPLATE_NAMESPACEr   append)rC   r   r   s      r+   startPrefixMappingz_ToStan.startPrefixMapping  si     $DNN3$s $$ >OO""GS>2OO""J$7#=>r-   c                 P    | j                   j                  }|J d       || _         y)zb
        "Pops the stack" on the prefix mapping.

        Gets called after endElementNS.
        Nz$More prefix mapping ends than starts)r   r   )rC   r   r   s      r+   endPrefixMappingz_ToStan.endPrefixMapping  s,     &&!I#II!r-   namespaceAndNameqnameattrsc                    | j                   }| j                  j                         }| j                  j                         }|\  }}|t        k(  rn|dk(  rd}nf|dk(  ra	 |d   }	t        |d   |	|||      }
| j                  j                  |
       | j                  j                  |
       |
j                  | _	        yd}t        |      }t        |j                               D ]  \  }}|\  }}|t        k7  r|dk(  s|}||= ! t               }|j                         D ]4  \  \  }}}| j                  j                  |      }||}n| d	| }|||<   6 |t        k(  r|d
k(  r| j                  st!        dt         d      d|vrt!        dt         d      t#        d||||      }|| j                  d   j$                  |d   <   | j                  j                  |       |j                  | _	        y| j&                  r+|j)                  t        | j&                               g | _        |t        k7  r'|%| j                  |   }|| j                  |    d	| }t#        |t        t+        t,        t.        t0        t2        f   t2        f   |            ||||      }| j                  j                  |       | j                  j                  |       |j                  | _	        y# t
        $ r d}	Y w xY w)a]  
        Gets called when we encounter a new xmlns attribute.

        @param namespaceAndName: a (namespace, name) tuple, where name
            determines which type of action to take, if the namespace matches
            L{TEMPLATE_NAMESPACE}.
        @param qname: ignored.
        @param attrs: attributes on the element being started.
        transparent r%   )NdefaultN)NrJ   )r   r   r{   columnNumberrF   :attrz<{z}attr> as top-level elementrJ   z }attr> requires a name attribute)rF   r   r{   r   )
attributesrF   r   r{   r   )r   r   getLineNumbergetColumnNumberr   KeyErrorr%   r   r   r   childrenr   listitemsr   r   AssertionErrorr$   r   r   updater   r   r   r4   rX   )rC   r   r   r   r   r{   r   nsrJ   r   slrF   orderedr   r   attrNSjustTheNamenonTemplateAttrsattrNsattrNamensPrefixattrKeyelr   s                           r+   startElementNSz_ToStan.startElementNS  s     &&\\//1
||335#D##}$##$56G
 .)#%)!- 

!!"%##B'!{{e$) 	DAq"#FK++h&AJ	 '=%,]]_ 	*!VX~~))&1H"%Jaz2()W%	* ##::$,--IJ  --$,--NO  !%)B CEDJJrN%%&6v&>?JJb!;;DL ??##K$@A DO ##^^B'F!..,-Qtf5"WU5#:.346FG !%	
 	

"B{{s   # #G#s   K' 'K65K6chc                     | j                   r| j                  d   j                  |       y| j                  j                  |       y)zm
        Called when we receive some characters.  CDATA characters get passed
        through as is.
        r   N)r   r   r   r   )rC   r   s     r+   
charactersz_ToStan.characters)  s6    
 <<JJrN!!"%Br-   rJ   c                     | j                   j                          | j                   r| j                   d   j                  | _        y| j                  | _        y)z
        A namespace tag is closed.  Pop the stack, if there's anything left in
        it, otherwise return to the document's namespace.
        r   N)r   popr   r   r   )rC   rJ   r   s      r+   endElementNSz_ToStan.endElementNS3  s9    
 	

::::b>22DL==DLr-   publicIdsystemIdc                      yz#
        DTDs are ignored.
        NrH   )rC   rJ   r   r   s       r+   startDTDz_ToStan.startDTD>  r   r-   argsc                      yr   rH   )rC   r   s     r+   endDTDz_ToStan.endDTDC  r   r-   c                 H    d| _         | j                  j                  g        y)zO
        We're starting to be in a CDATA element, make a note of this.
        TN)r   r   r   r   s    r+   
startCDATAz_ToStan.startCDATAH  s     

"r-   c                     d| _         dj                  | j                  j                               }| j                  j                  t        |             y)z
        We're no longer in a CDATA element.  Collect up the characters we've
        parsed and put them in a new CDATA object.
        Fr   N)r   joinr   r   r   r   r"   )rC   comments     r+   endCDATAz_ToStan.endCDATAO  s:    
 ''$**..*+E'N+r-   r:   c                 L    | j                   j                  t        |             y)z=
        Add an XML comment which we've encountered.
        N)r   r   r#   )rC   r:   s     r+   r  z_ToStan.commentX  s     	GG,-r-   )r0   N)rM   rN   rO   rP   r   rX   rB   r   r   r   r   r   r   r   r   r   r   r   r   r   objectr   r  r  r  rH   r-   r+   r   r   g  sJ   
x} ' d 
4
C s t 
?# ?S ?T ?, x}    v#S/v# }v#  	v#
 
v#p S  T  	)sCx 	)# 	)4 	)S C 3 4 
F t 
,.s .t .r-   r   flr   c                     t               }|j                  t        j                  d       |j                  t        j                  d       |j                  t        j
                  d       |j                  t        j                  d       t        t        | dd            }|j                  |       |j                  |       |j                  t        j                  |       |j                  |        |j                  S )z
    Perform a SAX parse of an XML document with the _ToStan class.

    @param fl: The XML document to be parsed.

    @return: a C{list} of Stan objects.
    r   rU   rJ   N)r   
setFeaturer   feature_validationfeature_namespacesfeature_external_gesfeature_external_pesr   getattrsetContentHandlersetEntityResolversetPropertyproperty_lexical_handlerparser   )r	  parserss      r+   _flatsaxParser  _  s     ]F
g00!4
g00!4
g22A6
g22A6FD)*A
Q
Q
w77;
LL::r-   c                   8    e Zd ZdZdeeef   fdZded   fdZ	y)	XMLStringzH
    An L{ITemplateLoader} that loads and parses XML from a string.
    r  c                     t        |t              s|j                  d      }t        t	        j
                  |            | _        y)z
        Run the parser on a L{io.StringIO} copy of the string.

        @param s: The string from which to load the XML.
        @type s: L{str}, or a UTF-8 encoded L{bytes}.
        utf8N)r3   rX   r8   r  ioStringIO_loadedTemplate)rC   r  s     r+   rB   zXMLString.__init__}  s4     !S! A4A"++a.4Q"r-   r0   r   c                     | j                   S )zM
        Return the document.

        @return: the loaded document.
        )r  r   s    r+   loadzXMLString.load  s     ###r-   N)
rM   rN   rO   rP   r   rX   r4   rB   r   r!  rH   r-   r+   r  r  w  s-    #%U
+ #$d=) $r-   r  c                   X    e Zd ZdZ ed      ZddZed        Zed        Z	ed        Z
y)	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>
Nc                 >    t        j                  | |       || _        y r@   )r   rB   failure)rC   r%  rt   s      r+   rB   zFailureElement.__init__  s    v&r-   c                 L     |t        | j                  j                              S )zA
        Render the exception type as a child of C{tag}.
        )r   r%  typerw   s      r+   r'  zFailureElement.type  s    
 %dll&7&7899r-   c                 j     |t        | j                  j                        j                  d            S )zB
        Render the exception value as a child of C{tag}.
        r  )rX   r%  valuer9   rw   s      r+   r)  zFailureElement.value  s)    
 3t||))*11&9::r-   c                 T    t        t        |      | j                  j                        S )z
        Render all the frames in the wrapped
        L{Failure<twisted.python.failure.Failure>}'s traceback stack, replacing
        C{tag}.
        )r   r   r%  r   rw   s      r+   	tracebackzFailureElement.traceback  s     Ys^T\\-@-@AAr-   r@   )rM   rN   rO   rP   r  rt   rB   r   r'  r)  r+  rH   r-   r+   r#  r#    s^     I	KFZ : : ; ; B Br-   r#  c                     g }t        dt        |             j                  |j                         t	        |d   t
              r$|d   j                  d      j                  dd      S |d   j                          y)a  
    Construct an HTML representation of the given failure.

    Consider using L{FailureElement} instead.

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

    @rtype: L{bytes}
    @return: A string containing the HTML representation of the given failure.
    Nr   r2   rW   xmlcharrefreplace)	r!   r#  addBothr   r3   r4   r8   r9   raiseException)	myFailureresults     r+   formatFailurer2    sj     F$y12::6==I&)U# ay(//9LMM
1Ir-   rU   c                   *    e Zd ZdZddZded   fdZy)r   zJ
    An L{ITemplateLoader} that loads an existing flattenable object.
    r   c                     || _         y)z>
        @param tag: The object which will be loaded.
        Nrx   )rC   rx   s     r+   rB   zTagLoader.__init__-  s    
 #&.r-   r0   c                     | j                   gS r@   r5  r   s    r+   r!  zTagLoader.load5  s    zr-   N)rx   r   )rM   rN   rO   rP   rB   r   r!  rH   r-   r+   r   r   '  s    /d=) r-   r   c                   R    e Zd ZdZdee   fdZded   fdZde	fdZ
ded   fdZy	)
XMLFilezF
    An L{ITemplateLoader} that loads and parses XML from a file.
    pathc                 z    t        |t              st        j                  dt        d       d| _        	 || _        y)zf
        Run the parser on a file.

        @param path: The file from which to load the XML.
        zhPassing filenames or file objects to XMLFile is deprecated since Twisted 12.1.  Pass a FilePath instead.r   )category
stacklevelN)r3   r   warningswarnDeprecationWarningr  _path)rC   r9  s     r+   rB   zXMLFile.__init__?  s>     $)MM@+	 ?C=$(
1r-   r0   r   c                     t        | j                  t              st        | j                        S | j                  j	                  d      5 }t        |      cddd       S # 1 sw Y   yxY w)zP
        Read and parse the XML.

        @return: the loaded document.
        rN)r3   r@  r   r  open)rC   fs     r+   _loadDoczXMLFile._loadDocS  sP     $**h/ ,,% ($Q'( ( (s   A  A)c                 "    d| j                   dS )Nz<XMLFile of >)r@  r   s    r+   __repr__zXMLFile.__repr___  s    djj^1--r-   c                 \    | j                   | j                         | _         | j                   S )zl
        Return the document, first loading it if necessary.

        @return: the loaded document.
        )r  rE  r   s    r+   r!  zXMLFile.loadb  s*     '#'==?D ###r-   N)rM   rN   rO   rP   r   r   rB   r   rE  rX   rH  r!  rH   r-   r+   r8  r8  9  sE    2Xc] 2(
($}- 
(.# .$d=) $r-   r8  >x   abipqr  ubrdddldtemh1h2h3h4h5h6hrliolrprttdthtrttulbdibdobigcoldeldfndirdivimginskbdmapnavpresubsupvarwbrabbrareabasebodycitecodefontformheadhtmllinkmarkmenumetarubysampspantimeasideaudioembedr   inputlabelmeterparamsmallstyletabletbodytfoottheadtitlevideoappletbuttoncanvascenterfigurefooterheaderhgroupiframekeygenlegendr  optionoutputscriptselectrs   strikestrongacronymaddressarticlecaptioncommanddetailsisindexsectionsummarybasefontcolgroupdatalistfieldsetframesetnoframesnoscriptoptgroupprogresstextarea
blockquote
figcaptionc                        e Zd ZdZdedefdZy)_TagFactorya  
    A factory for L{Tag} objects; the implementation of the L{tags} object.

    This allows for the syntactic convenience of C{from twisted.web.template
    import tags; tags.a(href="linked-page.html")}, where 'a' can be basically
    any HTML tag.

    The class is not exposed publicly because you only ever need one of these,
    and we already made it for you.

    @see: L{tags}
    tagNamer0   c                     |dk(  rt        d      S |j                  d      }|t        vrt        d|      t        |      S )Nr   r   _zunknown tag )r$   r   VALID_HTML_TAG_NAMESAttributeError)rC   r  s     r+   __getattr__z_TagFactory.__getattr__  sF    m#r7N..%.. <{!;<<7|r-   N)rM   rN   rO   rP   rX   r$   r  rH   r-   r+   r  r    s    3 3 r-   r  elementdoctype_failElementr   c                 H    |" j                  |        j                  d       t        t         | j                         }dt        dt        t
        d      f fd} ddt        dt        dt        fd	}|j                  |       |j                  |       t        S )
a  
    Render an element or other L{IRenderable}.

    @param request: The L{IRequest} being rendered to.
    @param element: An L{IRenderable} which will be rendered.
    @param doctype: A L{bytes} which will be written as the first line of
        the request, or L{None} to disable writing of a doctype.  The argument
        should not include a trailing newline and will default to the HTML5
        doctype C{'<!DOCTYPE html>'}.

    @returns: NOT_DONE_YET

    @since: 12.1
    N   
r%  r0   c                     t         j                  d|        t        dd       }|-|j                  r!J t	         |       j
                        S j                  d       y )Nz/An error occurred while rendering the response.)r%  sitesr   <div style="font-size:800%;background-color:#FFF;color:#F00">An error occurred while rendering the response.</div>)
_moduleLogr%  r  displayTracebacksr    write)r%  r  r  r/   s     r+   ebzrenderElement.<locals>.eb%  st    =w 	 	
 w- 6 6+++7L$97==IIMMK r-   )r/   r1  r/   c                &    |j                          | S r@   )finish)r1  r/   s     r+   r  zrenderElement.<locals>.finish6  s    r-   )r  r#  r    r   r   r   r  r'   rf   r.  rc   )r/   r  r  r  r`   r  r  s   `  `   r+   renderElementr    s    ( ge%'--0AG $ 8 " 7> v 8 &  LLIIfr-   )s   <!DOCTYPE html>N)XrP   r  r   r=  collectionsr   r  r   typingr   r   r   r	   r
   r   r   r   r   r   r   xml.saxr   r   xml.sax.xmlreaderr   r   zope.interfacer   twisted.internet.deferr   twisted.loggerr   twisted.pythonr   twisted.python.failurer   twisted.python.filepathr   twisted.python.reflectr   twisted.webr   twisted.web._elementr   r   twisted.web._flattenr   r    r!   twisted.web._stanr"   r#   r$   r%   twisted.web.iwebr&   r'   r(   r,   r4   r;   r_   r=   rT   r]   rp   r}   r   r   r   r   ContentHandlerEntityResolverr   rX   r  r  r#  r2  rc   r  r   r8  r  r  tagsr  r  rH   r-   r+   <module>r     s2   
   #     ) 7 & + ! " * , 5   2 D D 7 7 C C(&E &H & &Rx   *)X&& ):)x(( )8% %<+EW +E\+BG +B\
G 
&"' "'J L u.g$$g&<&< u.peBvJO, m1D 0 _$ $ $6qBW qBh8 X
 _  " _0$ 0$ 0$ny x 0 }  2=A	444 e_4 8WIy$89:	4
 4r-   