
    \ez                     J   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 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.m/Z/ ddl0m1Z1m2Z2m3Z3m4Z4 ddl5m6Z6m7Z7m8Z8 d Z9de:de7de:fdZ; G d de(j<                  Z= G d de=          Z> G d de(j<                  Z? G d d e(j<                  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jG        ejH                  ZId.ee	e         eJf         ded/         fd0ZK ee8           G d1 d2                      ZL G d3 d4e*          ZMd5 ZNd6ZO e            ZP ee8           G d7 d8                      ZQ ee8           G d9 d:                      ZRh d;ZS G d< d=          ZT eT            ZU	 	 dDde7d?e6d@ee:         dAeee"gdBf                  deVf
dCZWdS )EzG
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)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    :lib/python3.11/site-packages/twisted/web/_template_util.py_PREr+   ,   s     (6$<<''''    URLrequestreturnc                     t          | t                    st          d          |                    dd           |                    |            d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)
isinstancebytes	TypeError	setHeaderredirect)r-   r.   contents      r*   
redirectTor7   ;   so    ( c5!! -+,,,o'BCCCS	 	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                 V    t                                                       || _        d S N)super__init__r:   )selfr:   	__class__s     r*   r>   zRedirect.__init__n   s$    r,   c                 ,    t          | j        |          S r<   )r7   r:   )r?   r.   s     r*   renderzRedirect.renderr   s    $(G,,,r,   c                     | S r<    r?   namer.   s      r*   getChildzRedirect.getChildu       r,   )
__name__
__module____qualname____doc__isLeafr2   r>   rB   rG   __classcell__)r@   s   @r*   r9   r9   d   ss          FE      - - -      r,   r9   c                       e Zd ZdZd Zd ZdS )ChildRedirectorFc                     |                     d          dk    r<|                    d          s'|                    d          st          d|z            t                              | |           d S )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
ValueErrorr9   r>   )r?   r:   s     r*   r>   zChildRedirector.__init__}   s     XXe__""^^D)) #^^C(( # R 	   	$$$$$$r,   c                 l    | j         }|                    d          s|dz  }||z  }t          |          S )NrS   )r:   endswithrP   )r?   rF   r.   newUrls       r*   rG   zChildRedirector.getChild   s=    s## 	cMF$v&&&r,   N)rI   rJ   rK   rM   r>   rG   rD   r,   r*   rP   rP   z   s7        F% % % ' ' ' ' 'r,   rP   c                   &    e Zd ZdZdZdedefdZdS )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.   r/   c                     t          t          j                            |                                                                        d          }t          ||          S )zN
        Respond to all requests by redirecting to nearest directory.
        ascii)strr   URLPathfromRequesthereencoder7   )r?   r.   rb   s      r*   rB   zParentRedirect.render   sK     7?..w77<<>>??FFwOO$(((r,   N)rI   rJ   rK   rL   rM   r&   r2   rB   rD   r,   r*   r[   r[      sG         $ F)h )5 ) ) ) ) ) )r,   r[   c                   4    e Zd ZdZdZd Zd Zd Zd Zd Z	dS )	DeferredResourcezT
    I wrap up a Deferred that will eventually result in a Resource
    object.
    r\   c                 R    t           j                            |            || _        d S r<   )r   Resourcer>   d)r?   rh   s     r*   r>   zDeferredResource.__init__   s$    ""4(((r,   c                     | S r<   rD   rE   s      r*   rG   zDeferredResource.getChild   rH   r,   c                     | j                             | j        |                              | j        |           ddlm} |S )Nr   )NOT_DONE_YET)rh   addCallback_cbChild
addErrback_ebChildtwisted.web.serverrk   )r?   r.   rk   s      r*   rB   zDeferredResource.render   sF    4='22==dmWUUU333333r,   c                 V    |                     t          j        ||                     d S r<   )rB   r   getChildForRequest)r?   childr.   s      r*   rm   zDeferredResource._cbChild   s'    x25'BBCCCCCr,   c                 0    |                     |           d S r<   )processingFailed)r?   reasonr.   s      r*   ro   zDeferredResource._ebChild   s      (((((r,   N)
rI   rJ   rK   rL   rM   r>   rG   rB   rm   ro   rD   r,   r*   re   re      ss         
 F      D D D) ) ) ) )r,   re   c                   D    e Zd ZdZd Zed             Zed             ZdS )_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        | |           || _        || _        d S r<   )r   r>   numbersource)r?   loaderrz   r{   s       r*   r>   z_SourceLineElement.__init__   s'    v&&&r,   c                 J     || j                             dd                    S )zA
        Render the line of source as a child of C{tag}.
        z  u     )r{   replacer?   r.   tags      r*   
sourceLinez_SourceLineElement.sourceLine   s'    
 s4;&&t-BCCDDDr,   c                 <     |t          | j                            S )z>
        Render the line number as a child of C{tag}.
        )r_   rz   r   s      r*   
lineNumberz_SourceLineElement.lineNumber   s    
 s3t{##$$$r,   N)rI   rJ   rK   rL   r>   r   r   r   rD   r,   r*   rx   rx      sf           
 E E XE % % X% % %r,   rx   c                   4    e Zd ZdZd Zd Zed             ZdS )_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        | |           || _        d S r<   r   r>   framer?   r|   r   s      r*   r>   z_SourceFragmentElement.__init__        v&&&


r,   c              #      K   | j         d         }| j         d         }t          |dz
  |dz             D ]-}|t          j        ||                                          fV  .dS )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)r   range	linecachegetlinerstrip)r?   filenamer   snipLineNumbers       r*   _getSourceLinesz&_SourceFragmentElement._getSourceLines   sz       :a=Z]
#JNJNCC 	Y 	YN!9#4X~#N#N#U#U#W#WXXXXX	Y 	Yr,   c           	   #      K   |                                  D ]Y\  }}|                                }|| j        d         k    rd}nd}t           |di d|i          }t	          |||          V  ZdS )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classNrD   )r   cloner   	TagLoaderrx   )r?   r.   r   r   r   newTagcssClassr|   s           r*   sourceLinesz"_SourceFragmentElement.sourceLines  s       '+&:&:&<&< 	E 	E"J
YY[[FTZ]**1(vv<<((;<<==F$VZDDDDDD	E 	Er,   N)rI   rJ   rK   rL   r>   r   r   r   rD   r,   r*   r   r      s_           Y Y Y E E XE E Er,   r   c                   p    e Zd ZdZd Zed             Zed             Zed             Ze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.
    c                 >    t          j        | |           || _        d S r<   r   r   s      r*   r>   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}.
        r\   r   r   s      r*   r   z_FrameElement.filename)      
 s4:a=!!!r,   c                 H     |t          | j        d                             S )zc
        Render the source line number this frame references as a child of
        C{tag}.
        r   )r_   r   r   s      r*   r   z_FrameElement.lineNumber0  s"     s3tz!}%%&&&r,   c                 .     || j         d                   S )zV
        Render the function name this frame references as a child of C{tag}.
        r   r   r   s      r*   functionz_FrameElement.function8  r   r,   c                 F    t          t          |          | j                  S )zn
        Render the source code surrounding the line this frame references,
        replacing C{tag}.
        )r   r   r   r   s      r*   r{   z_FrameElement.source?  s     &inndjAAAr,   N)
rI   rJ   rK   rL   r>   r   r   r   r   r{   rD   r,   r*   r   r     s            " " X" ' ' X' " " X" B B XB B Br,   r   c                   .    e Zd ZdZd Zed             ZdS )_StackElementzW
    L{_StackElement} renders an L{IRenderable} which can render a list of frames.
    c                 >    t          j        | |           || _        d S r<   )r   r>   stackFrames)r?   r|   r   s      r*   r>   z_StackElement.__init__M  s#    v&&&&r,   c                 *    fd| j         D             S )zW
        Render the list of frames in this L{_StackElement}, replacing C{tag}.
        c                 n    g | ]1}t          t                                                    |          2S rD   )r   r   r   ).0r   r   s     r*   
<listcomp>z(_StackElement.frames.<locals>.<listcomp>V  s@     
 
 
=BM)CIIKK00%88
 
 
r,   )r   r   s     `r*   framesz_StackElement.framesQ  s1    

 
 
 
FJFV
 
 
 	
r,   N)rI   rJ   rK   rL   r>   r   r   rD   r,   r*   r   r   H  sH         ' ' ' 
 
 X
 
 
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	dS )
_NSContextzL
    A mapping from XML namespaces onto their prefixes in the document.
    Nparentc                 `    || _         |t          |j                  | _        dS ddi| _        dS )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)r?   r   s     r*   r>   z_NSContext.__init__`  s6    
 ;Fvz;R;RDHHH>FDHHHr,   krh   r/   c                 8    | j                             ||          S )z\
        Get a prefix for a namespace.

        @param d: The default prefix value.
        )r   get)r?   r   rh   s      r*   r   z_NSContext.getk  s     x||Aq!!!r,   vc                 <    | j                             ||           dS )zH
        Proxy through to setting the prefix for the namespace.
        N)r   __setitem__)r?   r   r   s      r*   r   z_NSContext.__setitem__s  s"     	Q"""""r,   c                 6    | j                             |          S )zH
        Proxy through to getting the prefix for the namespace.
        )r   __getitem__)r?   r   s     r*   r   z_NSContext.__getitem__y  s     x##A&&&r,   r<   )
rI   rJ   rK   rL   r   r>   r_   r   r   r   rD   r,   r*   r   r   [  s         	G 	Gx5 	G 	G 	G 	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eee         ef         ef         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dS )#_ToStanzd
    A SAX parser which converts an XML document to the Twisted STAN
    Document Object Model.
    sourceFilenamec                 H    || _         t                      | _        d| _        dS )zP
        @param sourceFilename: the filename the XML was loaded out of.
        FN)r   r   	prefixMapinCDATA)r?   r   s     r*   r>   z_ToStan.__init__  s"     -#r,   locatorr/   Nc                     || _         dS )zY
        Set the document locator, which knows about line and character numbers.
        N)r   )r?   r   s     r*   setDocumentLocatorz_ToStan.setDocumentLocator  s     r,   c                 H    g | _         | j         | _        g | _        g | _        dS )z*
        Initialise the document.
        N)documentcurrentstack
xmlnsAttrsr?   s    r*   startDocumentz_ToStan.startDocument  s&     $&} "
13r,   c                     dS )z!
        Document ended.
        NrD   r   s    r*   endDocumentz_ToStan.endDocument        r,   targetdatac                     dS )z6
        Processing instructions are ignored.
        NrD   )r?   r   r   s      r*   processingInstructionz_ToStan.processingInstruction  r   r,   prefixuric                     t          | j                  | _        || j        |<   |t          k    rdS || j                            d|f           dS | j                            d|z  |f           dS )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)r?   r   r   s      r*   startPrefixMappingz_ToStan.startPrefixMapping  s     $DN33$s $$$F >O""GS>22222O""J$7#=>>>>>r,   c                 D    | j         j        }|
J d            || _         dS )zb
        "Pops the stack" on the prefix mapping.

        Gets called after endElementNS.
        Nz$More prefix mapping ends than starts)r   r   )r?   r   r   s      r*   endPrefixMappingz_ToStan.endPrefixMapping  s.     &!!#I!!!r,   namespaceAndNameqnameattrsc                 8   | j         }| j                                        }| j                                        }|\  }}|t          k    r|dk    rd}n~|dk    rx	 |d         }	n# t
          $ r d}	Y nw xY wt          |d         |	|||          }
| j                            |
           | j	                            |
           |
j
        | _	        dS d}t          |          }t          |                                          D ]!\  }}|\  }}|t          k    r|dk    r|}||= "t                      }|                                D ]3\  \  }}}| j                            |          }||}n| d	| }|||<   4|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
        | _	        dS | j        r.|                    t          | j                             g | _        |t          k    r#|!| j        |         }|| j        |          d	| }t#          |t          t+          t,          t.          t0          t2          f         t2          f         |                    ||||          }| j                            |           | j	                            |           |j
        | _	        dS )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)NrF   )r   r   r   columnNumberrB   :attrz<{z}attr> as top-level elementrF   z }attr> requires a name attribute)rB   r   r   r   rR   )
attributesrB   r   r   r   )r   r   getLineNumbergetColumnNumberr   KeyErrorr$   r   r   r   childrenr   listitemsr   r   AssertionErrorr#   r   r   updater   r   r   r2   r_   )r?   r   r   r   r   r   r   nsrF   r   slrB   r   r   attrNSjustTheNamenonTemplateAttrsattrNsattrNamensPrefixattrKeyelr   s                          r*   startElementNSz_ToStan.startElementNS  s     &\//11
|3355#D###}$$##$56GG # # # #GGG# .)#%)!-   
!!"%%%##B'''!{E""'' 	 	DAq"#FK+++h&&!H '==%*[[]] 	* 	*!VX~))&11H"%2222()W%%###: $J,JJJ   ---$O,OOO   !%)  B CEDJrN%&6v&>?Jb!!!;DLF ? 	!##K$@$@AAA DO ###^B'F!.,55t55"WU5#:.346FGG  !%	
 	
 	
 	
"B{s   A# #A21A2chc                     | j         r"| j        d                             |           dS | j                            |           dS )zm
        Called when we receive some characters.  CDATA characters get passed
        through as is.
        rR   N)r   r   r   r   )r?   r   s     r*   
charactersz_ToStan.charactersE  sI    
 < 	JrN!!"%%%FBr,   rF   c                     | j                                          | j         r| j         d         j        | _        dS | j        | _        dS )z
        A namespace tag is closed.  Pop the stack, if there's anything left in
        it, otherwise return to the document's namespace.
        rR   N)r   popr   r   r   )r?   rF   r   s      r*   endElementNSz_ToStan.endElementNSO  sA    
 	
: 	):b>2DLLL=DLLLr,   publicIdsystemIdc                     dS z#
        DTDs are ignored.
        NrD   )r?   rF   r  r  s       r*   startDTDz_ToStan.startDTDZ  r   r,   argsc                     dS r  rD   )r?   r  s     r*   endDTDz_ToStan.endDTD_  r   r,   c                 H    d| _         | j                            g            dS )zO
        We're starting to be in a CDATA element, make a note of this.
        TN)r   r   r   r   s    r*   
startCDATAz_ToStan.startCDATAd  s'     
"r,   c                     d| _         d                    | j                                                  }| j                            t          |                     dS )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!   )r?   comments     r*   endCDATAz_ToStan.endCDATAk  sJ    
 ''$*..**++E'NN+++++r,   r6   c                 T    | j                             t          |                     dS )z=
        Add an XML comment which we've encountered.
        N)r   r   r"   )r?   r6   s     r*   r  z_ToStan.commentt  s(     	GG,,-----r,   )r/   N)rI   rJ   rK   rL   r   r_   r>   r   r   r   r   r   r   r   r   r   r   r   r  r  objectr	  r  r  r  rD   r,   r*   r   r     s]        
x}    ' d    
4 
4 
4 
4   
C s t    
?# ?S ?T ? ? ? ?, x}          v#S/v# }v# uXc]C/0#56	v#
 
v# v# v# v#p S  T        	)sCx 	)# 	)4 	) 	) 	) 	)S C 3 4    
F t    
   , , , ,.s .t . . . . . .r,   r   flr   c                 &   t                      }|                    t          j        d           |                    t          j        d           |                    t          j        d           |                    t          j        d           t          t          | dd                    }|	                    |           |
                    |           |                    t          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   r\   rF   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!444
g0!444
g2A666
g2A666FD))**A
Q
Q
w7;;;
LL:r,   c                   F    e Zd ZdZdeeef         fdZded         fdZ	dS )	XMLStringzH
    An L{ITemplateLoader} that loads and parses XML from a string.
    r   c                     t          |t                    s|                    d          }t          t	          j        |                    | _        dS )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)r1   r_   decoder!  ioStringIO_loadedTemplate)r?   r   s     r*   r>   zXMLString.__init__  sE     !S!! 	!  A4A"+a..4Q4Q""r,   r/   r   c                     | j         S )zM
        Return the document.

        @return: the loaded document.
        )r)  r   s    r*   loadzXMLString.load  s     ##r,   N)
rI   rJ   rK   rL   r   r_   r2   r>   r   r+  rD   r,   r*   r#  r#    sb         #%U
+ # # # #$d=) $ $ $ $ $ $r,   r#  c                   r    e Zd ZdZ ed          ZddZed             Zed             Z	ed             Z
dS )	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        | |           || _        d S r<   )r   r>   failure)r?   r/  r|   s      r*   r>   zFailureElement.__init__  s     v&&&r,   c                 F     |t          | j        j                            S )zA
        Render the exception type as a child of C{tag}.
        )r   r/  typer   s      r*   r1  zFailureElement.type  s"    
 s%dl&788999r,   c                 l     |t          | j        j                                      d                    S )zB
        Render the exception value as a child of C{tag}.
        r%  )r_   r/  valuerc   r   s      r*   r3  zFailureElement.value  s/    
 s3t|)**11&99:::r,   c                 P    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   r   s      r*   	tracebackzFailureElement.traceback  s     Ys^^T\-@AAAr,   r<   )rI   rJ   rK   rL   r#  r|   r>   r   r1  r3  r5  rD   r,   r*   r-  r-    s          YI	K KFZ    : : X: ; ; X; B B XB B Br,   r-  c                 <   g }t          dt          |                                         |j                   t	          |d         t
                    r/|d                             d                              dd          S |d                                          dS )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   zutf-8r^   xmlcharrefreplace)	r    r-  addBothr   r1   r2   r&  rc   raiseException)	myFailureresults     r*   formatFailurer<  #  s     F$y1122::6=III&)U## N ay((//9LMMM
1Ir,   r\   c                   2    e Zd ZdZddZded         fdZdS )	r   zJ
    An L{ITemplateLoader} that loads an existing flattenable object.
    r   r   c                     || _         dS )z>
        @param tag: The object which will be loaded.
        Nr   )r?   r   s     r*   r>   zTagLoader.__init__I  s    
 #&..r,   r/   c                     | j         gS r<   r?  r   s    r*   r+  zTagLoader.loadQ  s    zr,   N)r   r   )rI   rJ   rK   rL   r>   r   r+  rD   r,   r*   r   r   C  sR         / / / /d=)      r,   r   c                   f    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d	S )
XMLFilezF
    An L{ITemplateLoader} that loads and parses XML from a file.
    pathc                     t          |t                    st          j        dt          d           d| _        	 || _        dS )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)r1   r   warningswarnDeprecationWarningr)  _path)r?   rC  s     r*   r>   zXMLFile.__init__[  sV     $)) 	M@+	    ?C=$(
11r,   r/   r   c                     t          | j        t                    st          | j                  S | j                            d          5 }t          |          cddd           S # 1 swxY w Y   dS )zP
        Read and parse the XML.

        @return: the loaded document.
        rN)r1   rJ  r   r!  open)r?   fs     r*   _loadDoczXMLFile._loadDoco  s     $*h// 	( ,,,%% ($Q''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (s   	A%%A),A)c                     d| j         dS )Nz<XMLFile of >)rJ  r   s    r*   __repr__zXMLFile.__repr__{  s    -dj----r,   c                 P    | j         |                                 | _         | j         S )zl
        Return the document, first loading it if necessary.

        @return: the loaded document.
        )r)  rO  r   s    r*   r+  zXMLFile.load~  s&     '#'==??D ##r,   N)rI   rJ   rK   rL   r   r   r>   r   rO  r_   rR  r+  rD   r,   r*   rB  rB  U  s         2Xc] 2 2 2 2(
($}- 
( 
( 
( 
(.# . . . .$d=) $ $ $ $ $ $r,   rB  >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selectr{   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dS )_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}
    tagNamer/   c                     |dk    rt          d          S |                    d          }|t          vrt          d|          t          |          S )Nr   r   _zunknown tag )r#   r   VALID_HTML_TAG_NAMESAttributeError)r?   r  s     r*   __getattr__z_TagFactory.__getattr__  sX    m##r77N..%%... !;!;!;<<<7||r,   N)rI   rJ   rK   rL   r_   r#   r  rD   r,   r*   r  r  	  s@         3 3      r,   r     <!DOCTYPE html>elementdoctype_failElementr   c                     |*                      |                                 d           t          t           | j                   }dt          dt          t
          d                  f fd} ddt          dt          dt          fd	}|                    |           |	                    |           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/  r/   c                     t                               d|            t          dd           }|*|j        r#J t	           |           j                  S                     d           d S )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>.ebA  s    =w 	 	
 	
 	
 w-- 6+++7LL$9$97=IIIMMK   4r,   )r.   r;  r.   c                .    |                                  | S r<   )finish)r;  r.   s     r*   r  zrenderElement.<locals>.finishR  s    r,   )r  r-  r   r   r   r   r  r&   rn   r8  rk   )r.   r  r  r  rh   r  r  s   `  `   r*   renderElementr  $  s    ( ge%'-00AG $ 8       " 7>   v 8 &     LLIIfr,   )r  N)XrL   r'  r   rG  collectionsr   r  r   typingr   r   r   r	   r
   r   r   r   r   r   r   xml.saxr   r   xml.sax.xmlreaderr   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+   r2   r7   rg   r9   rP   r[   re   rx   r   r   r   r   r   ContentHandlerEntityResolverr   r_   r!  r#  r-  r<  rk   r  r   rB  r  r  tagsr  r  rD   r,   r*   <module>r     s!    
			      # # # # # #                                ) ( ( ( ( ( ( ( % % % % % % & & & & & & + + + + + + ! ! ! ! ! ! " " " " " " * * * * * * , , , , , , 5 5 5 5 5 5             2 2 2 2 2 2 2 2 D D D D D D D D D D 7 7 7 7 7 7 7 7 7 7 7 7 C C C C C C C C C C( ( (&E &H & & & & &R    x    ,' ' ' ' 'h ' ' '6) ) ) ) )X& ) ) ):) ) ) ) )x( ) ) )8% % % % % % % %<+E +E +E +E +EW +E +E +E\+B +B +B +B +BG +B +B +B\
 
 
 
 
G 
 
 
&"' "' "' "' "' "' "' "'J L u. u. u. u. u.g$g&< u. u. u.peBvJO, m1D    0 _$ $ $ $ $ $ $ $6qB qB qB qB qBW qB qB qBh  8 VXX
 _       " _0$ 0$ 0$ 0$ 0$ 0$ 0$ 0$ny y y x       0 {}}  2=A	4 444 e_4 8WIy$89:	4
 4 4 4 4 4 4r,   