o
    >hw                     @   s  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d Z:de;de8de;fddZ<G dd de)j=Z>G dd de)j=Z?G dd  d e)j=Z@G d!d" d"e+ZAG d#d$ d$e+ZBG d%d& d&e+ZCG d'd( d(e+ZDG d)d* d*ZEd+ZFG d,d- d-ejGejHZId.ee	e eJf ded/ fd0d1ZKee9G d2d3 d3ZLG d4d5 d5e+ZMd6d7 ZNd8ZOe ZPee9G d9d: d:ZQee9G d;d< d<ZRh d=ZSG d>d? d?ZTeT ZU	@	dGde8dAe7dBee; dCeee#gdDf  deVf
dEdFZWdS )HzG
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                 C   s   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   )text r)   z/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/twisted/web/_template_util.py_PRE,   s   r+   URLrequestreturnc                 C   sH   t | ts	td|dd ||  ddt| ddi }|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-   contentr)   r)   r*   
redirectTo;   s   


r8   c                       s:   e Zd ZdZdZdef fddZdd Zdd	 Z  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                    s   t    || _d S N)super__init__r:   )selfr:   	__class__r)   r*   r=   n   s   

zRedirect.__init__c                 C   s   t | j|S r;   )r8   r:   )r>   r-   r)   r)   r*   renderr   s   zRedirect.renderc                 C      | S r;   r)   r>   namer-   r)   r)   r*   getChildu      zRedirect.getChild)
__name__
__module____qualname____doc__isLeafr1   r=   rA   rE   __classcell__r)   r)   r?   r*   r9   d   s    r9   c                   @   s&   e Zd ZdZdZdedefd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                 C   s$   t tj| d}t||S )zN
        Respond to all requests by redirecting to nearest directory.
        ascii)strr   URLPathfromRequestherer6   r8   )r>   r-   rS   r)   r)   r*   rA      s   
zParentRedirect.renderN)rG   rH   rI   rJ   rK   r&   r1   rA   r)   r)   r)   r*   rM   y   s    rM   c                   @   s<   e Zd ZdZdZdd Zdd Zdd Zd	d
 Zdd Z	dS )DeferredResourcezT
    I wrap up a Deferred that will eventually result in a Resource
    object.
    rN   c                 C   s   t j|  || _d S r;   )r   Resourcer=   d)r>   rV   r)   r)   r*   r=         
zDeferredResource.__init__c                 C   rB   r;   r)   rC   r)   r)   r*   rE      rF   zDeferredResource.getChildc                 C   s*   | j | j|| j| ddlm} |S )Nr   )NOT_DONE_YET)rV   addCallback_cbChild
addErrback_ebChildtwisted.web.serverrX   )r>   r-   rX   r)   r)   r*   rA      s   zDeferredResource.renderc                 C   s   | t|| d S r;   )rA   r   getChildForRequest)r>   childr-   r)   r)   r*   rZ      s   zDeferredResource._cbChildc                 C   s   | | d S r;   )processingFailed)r>   reasonr-   r)   r)   r*   r\         zDeferredResource._ebChildN)
rG   rH   rI   rJ   rK   r=   rE   rA   rZ   r\   r)   r)   r)   r*   rT      s    rT   c                   @   s0   e Zd ZdZdd Zedd Zed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                 C   s   t | | || _|| _d S r;   )r   r=   numbersource)r>   loaderrd   re   r)   r)   r*   r=      s   
z_SourceLineElement.__init__c                 C   s   || j ddS )zA
        Render the line of source as a child of C{tag}.
        z  u     )re   replacer>   r-   tagr)   r)   r*   
sourceLine   s   z_SourceLineElement.sourceLinec                 C   s   |t | jS )z>
        Render the line number as a child of C{tag}.
        )rP   rd   rh   r)   r)   r*   
lineNumber      z_SourceLineElement.lineNumberN)rG   rH   rI   rJ   r=   r   rj   rk   r)   r)   r)   r*   rc      s    	
rc   c                   @   s,   e Zd ZdZdd Zdd Zed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                 C      t | | || _d S r;   r   r=   framer>   rf   rp   r)   r)   r*   r=      rW   z_SourceFragmentElement.__init__c                 c   sH    | j d }| j d }t|d |d D ]}|t|| fV  q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.
        rN      N)rp   range	linecachegetlinerstrip)r>   filenamerk   snipLineNumberr)   r)   r*   _getSourceLines   s   

z&_SourceFragmentElement._getSourceLinesc                 c   s\    |   D ]&\}}| }|| jd krd}nd}t|di d|i}t|||V  qd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"}.
        rr   snippetHighlightLinesnippetLineclassNr)   )ry   clonerp   	TagLoaderrc   )r>   r-   ri   rk   rj   newTagcssClassrf   r)   r)   r*   sourceLines   s   z"_SourceFragmentElement.sourceLinesN)rG   rH   rI   rJ   r=   ry   r   r   r)   r)   r)   r*   rm      s    
rm   c                   @   sH   e Zd ZdZdd Zedd Zedd Zedd	 Zed
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                 C   rn   r;   ro   rq   r)   r)   r*   r=   	  rW   z_FrameElement.__init__c                 C      || j d S )zY
        Render the name of the file this frame references as a child of C{tag}.
        rN   rp   rh   r)   r)   r*   rw     rl   z_FrameElement.filenamec                 C   s   |t | jd S )zc
        Render the source line number this frame references as a child of
        C{tag}.
        rr   )rP   rp   rh   r)   r)   r*   rk     s   z_FrameElement.lineNumberc                 C   r   )zV
        Render the function name this frame references as a child of C{tag}.
        r   r   rh   r)   r)   r*   function  rl   z_FrameElement.functionc                 C   s   t t|| jS )zn
        Render the source code surrounding the line this frame references,
        replacing C{tag}.
        )rm   r~   rp   rh   r)   r)   r*   re   #  s   z_FrameElement.sourceN)
rG   rH   rI   rJ   r=   r   rw   rk   r   re   r)   r)   r)   r*   r      s    



r   c                   @   s$   e Zd ZdZdd Zedd ZdS )_StackElementzW
    L{_StackElement} renders an L{IRenderable} which can render a list of frames.
    c                 C   rn   r;   )r   r=   stackFrames)r>   rf   r   r)   r)   r*   r=   1  rW   z_StackElement.__init__c                    s    fdd| j D S )zW
        Render the list of frames in this L{_StackElement}, replacing C{tag}.
        c                    s   g | ]}t t  |qS r)   )r   r~   r}   ).0rp   ri   r)   r*   
<listcomp>:  s    z(_StackElement.frames.<locals>.<listcomp>)r   rh   r)   r   r*   frames5  s   
z_StackElement.framesN)rG   rH   rI   rJ   r=   r   r   r)   r)   r)   r*   r   ,  s
    r   c                   @   s   e Zd ZdZdded  fddZddee dee dee fd	d
Zdee dee ddfddZdee dee fddZ	dS )
_NSContextzL
    A mapping from XML namespaces onto their prefixes in the document.
    Nparentc                 C   s,   || _ |dur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   r)   r)   r*   r=   D  s   z_NSContext.__init__krV   r.   c                 C   s   | j ||S )z\
        Get a prefix for a namespace.

        @param d: The default prefix value.
        )r   get)r>   r   rV   r)   r)   r*   r   O  s   z_NSContext.getvc                 C   s   | j || dS )zH
        Proxy through to setting the prefix for the namespace.
        N)r   __setitem__)r>   r   r   r)   r)   r*   r   W  s   z_NSContext.__setitem__c                 C   s   | j |S )zH
        Proxy through to getting the prefix for the namespace.
        )r   __getitem__)r>   r   r)   r)   r*   r   ]  s   z_NSContext.__getitem__r;   )
rG   rH   rI   rJ   r   r=   rP   r   r   r   r)   r)   r)   r*   r   ?  s    $r   z4http://twistedmatrix.com/ns/twisted.web.template/0.1c                   @   s:  e Zd ZdZdee fddZdeddfdd	Zd1d
dZ	d1ddZ
dededdfddZdee deddfddZdee ddfddZdeeef dee deddfddZdeddfddZd eeef dee ddfd!d"Zd ed#ed$eddfd%d&Zd'eddfd(d)Zd1d*d+Zd1d,d-Zd.eddfd/d0ZdS )2_ToStanzd
    A SAX parser which converts an XML document to the Twisted STAN
    Document Object Model.
    sourceFilenamec                 C   s   || _ t | _d| _dS )zP
        @param sourceFilename: the filename the XML was loaded out of.
        FN)r   r   	prefixMapinCDATA)r>   r   r)   r)   r*   r=   m  s   
z_ToStan.__init__locatorr.   Nc                 C   
   || _ dS )zY
        Set the document locator, which knows about line and character numbers.
        N)r   )r>   r   r)   r)   r*   setDocumentLocatoru  s   
z_ToStan.setDocumentLocatorc                 C   s   g | _ | j | _g | _g | _dS )z*
        Initialise the document.
        N)documentcurrentstack
xmlnsAttrsr>   r)   r)   r*   startDocument{  s   
z_ToStan.startDocumentc                 C      dS )z!
        Document ended.
        Nr)   r   r)   r)   r*   endDocument      z_ToStan.endDocumenttargetdatac                 C   r   )z6
        Processing instructions are ignored.
        Nr)   )r>   r   r   r)   r)   r*   processingInstruction  r   z_ToStan.processingInstructionprefixuric                 C   sV   t | j| _|| j|< |tkrdS |du r| jd|f dS | jd| |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   r)   r)   r*   startPrefixMapping  s   	
z_ToStan.startPrefixMappingc                 C   s"   | j j}|dus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   r)   r)   r*   endPrefixMapping  s   
z_ToStan.endPrefixMappingnamespaceAndNameqnameattrsc                 C   sP  | j }| j }| j }|\}}|tkrO|dkrd}n3|dkrOz|d }	W n ty1   d}	Y nw t|d |	|||d}
| j|
 | j	|
 |
j
| _	dS d}t|}t| D ]\}}|\}}|tkrhq[|dkrq|}||= q[t }| D ]\\}}}| j|}|du r|}n| d	| }|||< qy|tkr|d
kr| jstdt dd|vrtdt dtd||||d}|| jd j|d < | j| |j
| _	dS | jr|t| j g | _|tkr|dur| j| }|dur| j|  d	| }t|ttttttf tf |||||d}| 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)NrD   )r   rw   rk   columnNumberrA   :attrz<{z}attr> as top-level elementrD   z }attr> requires a name attribute)rA   rw   rk   r   )
attributesrA   rw   rk   r   )r   r   getLineNumbergetColumnNumberr   KeyErrorr$   r   r   r   childrenr   listitemsr   r   AssertionErrorr#   r   r   updater   r   r   r1   rP   )r>   r   r   r   rw   rk   r   nsrD   r   slrA   orderedr   r   attrNSjustTheNamenonTemplateAttrsattrNsattrNamensPrefixattrKeyelr   r)   r)   r*   startElementNS  s   

	




z_ToStan.startElementNSchc                 C   s*   | j r| jd | dS | j| dS )zm
        Called when we receive some characters.  CDATA characters get passed
        through as is.
        r   N)r   r   r   r   )r>   r   r)   r)   r*   
characters)  s   z_ToStan.charactersrD   c                 C   s.   | 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.
        r   N)r   popr   r   r   )r>   rD   r   r)   r)   r*   endElementNS3  s   
z_ToStan.endElementNSpublicIdsystemIdc                 C   r   z#
        DTDs are ignored.
        Nr)   )r>   rD   r   r   r)   r)   r*   startDTD>  r   z_ToStan.startDTDargsc                 G   r   r   r)   )r>   r   r)   r)   r*   endDTDC  r   z_ToStan.endDTDc                 C   s   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   r)   r)   r*   
startCDATAH  s   z_ToStan.startCDATAc                 C   s*   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>   commentr)   r)   r*   endCDATAO  s   z_ToStan.endCDATAr7   c                 C   s   | j t| dS )z=
        Add an XML comment which we've encountered.
        N)r   r   r"   )r>   r7   r)   r)   r*   r   X  s   z_ToStan.comment)r.   N)rG   rH   rI   rJ   r   rP   r=   r   r   r   r   r   r   r   r   r   r   r   r   r   objectr   r   r   r   r)   r)   r)   r*   r   g  s2    




x"


	r   flr   c                 C   s   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   rN   rD   N)r   
setFeaturer   feature_validationfeature_namespacesfeature_external_gesfeature_external_pesr   getattrsetContentHandlersetEntityResolversetPropertyproperty_lexical_handlerparser   )r   parsersr)   r)   r*   _flatsaxParse_  s   


r   c                   @   s8   e Zd ZdZdeeef fddZded fddZ	d	S )
	XMLStringzH
    An L{ITemplateLoader} that loads and parses XML from a string.
    r   c                 C   s(   t |ts
|d}tt|| _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)r0   rP   r5   r   ioStringIO_loadedTemplate)r>   r   r)   r)   r*   r=   }  s   

zXMLString.__init__r.   r   c                 C   s   | j S )zM
        Return the document.

        @return: the loaded document.
        )r   r   r)   r)   r*   load  s   zXMLString.loadN)
rG   rH   rI   rJ   r   rP   r1   r=   r
   r   r)   r)   r)   r*   r   w  s    r   c                   @   sF   e Zd ZdZedZdddZedd Zedd	 Z	ed
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                 C   s   t | | || _d S r;   )r   r=   failure)r>   r   rf   r)   r)   r*   r=     rW   zFailureElement.__init__c                 C   s   |t | jjS )zA
        Render the exception type as a child of C{tag}.
        )r   r   typerh   r)   r)   r*   r     s   zFailureElement.typec                 C   s   |t | jjdS )zB
        Render the exception value as a child of C{tag}.
        r   )rP   r   valuer6   rh   r)   r)   r*   r     s   zFailureElement.valuec                 C   s   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   rh   r)   r)   r*   	traceback  s   zFailureElement.tracebackr;   )rG   rH   rI   rJ   r   rf   r=   r   r   r   r   r)   r)   r)   r*   r     s    

M

r   c                 C   sN   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   r/   rO   xmlcharrefreplace)	r    r   addBothr   r0   r1   r5   r6   raiseException)	myFailureresultr)   r)   r*   formatFailure  s
   r   rN   c                   @   s,   e Zd ZdZd
ddZded fddZd	S )r~   zJ
    An L{ITemplateLoader} that loads an existing flattenable object.
    ri   r   c                 C   r   )z>
        @param tag: The object which will be loaded.
        Nr   )r>   ri   r)   r)   r*   r=   -  s   zTagLoader.__init__r.   c                 C   s   | j gS r;   r   r   r)   r)   r*   r   5  s   zTagLoader.loadN)ri   r   )rG   rH   rI   rJ   r=   r
   r   r)   r)   r)   r*   r~   '  s    
r~   c                   @   sT   e Zd ZdZdee fddZded fddZde	fd	d
Z
ded fddZdS )XMLFilezF
    An L{ITemplateLoader} that loads and parses XML from a file.
    pathc                 C   s,   t |tstjdtd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.rr   )category
stacklevelN)r0   r   warningswarnDeprecationWarningr   _path)r>   r   r)   r)   r*   r=   ?  s   
zXMLFile.__init__r.   r   c                 C   sN   t | jtst| jS | jd}t|W  d   S 1 s w   Y  dS )zP
        Read and parse the XML.

        @return: the loaded document.
        rN)r0   r  r   r   open)r>   fr)   r)   r*   _loadDocS  s
   
$zXMLFile._loadDocc                 C   s   d| j dS )Nz<XMLFile of >)r  r   r)   r)   r*   __repr___  rb   zXMLFile.__repr__c                 C   s   | j du r
|  | _ | j S )zl
        Return the document, first loading it if necessary.

        @return: the loaded document.
        N)r   r  r   r)   r)   r*   r   b  s   

zXMLFile.loadN)rG   rH   rI   rJ   r   r   r=   r
   r  rP   r
  r   r)   r)   r)   r*   r   9  s    r   >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embedrp   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selectre   strikestrongacronymaddressarticlecaptioncommanddetailsisindexsectionsummarybasefontcolgroupdatalistfieldsetframesetnoframesnoscriptoptgroupprogresstextarea
blockquote
figcaptionc                   @   s"   e Zd ZdZdedefd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                 C   s8   |dkrt dS |d}|tvrtd|t |S )Nr   r   _zunknown tag )r#   rv   VALID_HTML_TAG_NAMESAttributeError)r>   r  r)   r)   r*   __getattr__  s   
z_TagFactory.__getattr__N)rG   rH   rI   rJ   rP   r#   r  r)   r)   r)   r*   r    s    r     <!DOCTYPE html>elementdoctype_failElementr   c                    s   |dur |  d  du rt t|j }dtdttd  f fdd}ddtd	tdtfd
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                    sT   t jd| d tdd }|d ur#|jr# d us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-   r)   r*   eb%  s   zrenderElement.<locals>.eb)r-   r   r-   c                S   s   |   | S r;   )finish)r   r-   r)   r)   r*   r  6  s   zrenderElement.<locals>.finish)r  r   r   r   r   r   r   r&   r[   r   rX   )r-   r  r  r  rV   r  r  r)   r  r*   renderElement  s   

 

r  )r  N)XrJ   r   rt   r  collectionsr   rA  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+   r1   r8   rU   r9   rM   rT   rc   rm   r   r   r   r   ContentHandlerEntityResolverr   rP   r   r   r   r   rX   r  r~   r   r  r  tagsr   r  r)   r)   r)   r*   <module>   sz   4)..% "yt7|