HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/thread-self/root/lib/python3/dist-packages/twisted/web/__pycache__/template.cpython-38.pyc
U


W[�D�y@s�dZddlmZmZddddddd	d
ddd
dddddgZddlZddlmZddlm	Z	ddl
mZmZddl
mZmZddlmZddlmZmZmZmZmZddlmZddlmZdZdZe�ZGdd�de�Z Gd d!�d!ej!ej"�Z#d"d#�Z$e	e�Gd$d�de��Z%e	e�Gd%d�de��Z&e	e�Gd&d�de��Z'e(d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~dd�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�gx�Z)Gd�d��d�e�Z*e*�Z+d�d�d�Z,dd�l-m.Z.m/Z/dd�l0m1Z1m2Z2ddl3Z4dS)�a0
HTML rendering for twisted.web.

@var VALID_HTML_TAG_NAMES: A list of recognized HTML tag names, used by the
    L{tag} object.

@var TEMPLATE_NAMESPACE: The XML namespace used to identify attributes and
    elements used by the templating system, which should be removed from the
    final output document.

@var tags: A convenience object which can produce L{Tag} objects on demand via
    attribute access.  For example: C{tags.div} is equivalent to C{Tag("div")}.
    Tags not specified in L{VALID_HTML_TAG_NAMES} will result in an
    L{AttributeError}.
�)�division�absolute_import�TEMPLATE_NAMESPACE�VALID_HTML_TAG_NAMES�Element�	TagLoader�	XMLString�XMLFile�renderer�flatten�
flattenString�tags�Comment�CDATA�Tag�slot�CharRef�
renderElementN)�OrderedDict)�implementer)�make_parser�handler)�NativeStringIO�items)�FilePath)rrrrr)�ITemplateLoader)�Loggerz4http://twistedmatrix.com/ns/twisted.web.template/0.1�c@s4eZdZdZddd�Zddd�Zdd�Zd	d
�ZdS)
�
_NSContextzL
    A mapping from XML namespaces onto their prefixes in the document.
    NcCs*||_|dk	rt|j�|_n
ddi|_dS)ze
        Pull out the parent's namespaces, if there's no parent then default to
        XML.
        Nz$http://www.w3.org/XML/1998/namespaceZxml)�parentr�nss)�selfr�r"�6/usr/lib/python3/dist-packages/twisted/web/template.py�__init__>sz_NSContext.__init__cCs|j�||�S)z\
        Get a prefix for a namespace.

        @param d: The default prefix value.
        )r �get)r!�k�dr"r"r#r%Jsz_NSContext.getcCs|j�||�dS)zH
        Proxy through to setting the prefix for the namespace.
        N)r �__setitem__)r!r&�vr"r"r#r(Ssz_NSContext.__setitem__cCs|j�|�S)zH
        Proxy through to getting the prefix for the namespace.
        )r �__getitem__)r!r&r"r"r#r*Zsz_NSContext.__getitem__)N)N)�__name__�
__module__�__qualname__�__doc__r$r%r(r*r"r"r"r#r9s


	rc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd S)!�_ToStanzd
    A SAX parser which converts an XML document to the Twisted STAN
    Document Object Model.
    cCs||_t�|_d|_dS)zM
        @param sourceFilename: the filename to load the XML out of.
        FN)�sourceFilenamer�	prefixMap�inCDATA)r!r0r"r"r#r$hsz_ToStan.__init__cCs
||_dS)zY
        Set the document locator, which knows about line and character numbers.
        N)�locator)r!r3r"r"r#�setDocumentLocatorqsz_ToStan.setDocumentLocatorcCsg|_|j|_g|_g|_dS)z*
        Initialise the document.
        N)�document�current�stack�
xmlnsAttrs�r!r"r"r#�
startDocumentxsz_ToStan.startDocumentcCsdS)z!
        Document ended.
        Nr"r9r"r"r#�endDocument�sz_ToStan.endDocumentcCsdS)z6
        Processing instructions are ignored.
        Nr")r!�target�datar"r"r#�processingInstruction�sz_ToStan.processingInstructioncCsTt|j�|_||j|<|tkr"dS|dkr<|j�d|f�n|j�d||f�dS)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.
        NZxmlnszxmlns:%s)rr1rr8�append)r!�prefixZurir"r"r#�startPrefixMapping�s	
z_ToStan.startPrefixMappingcCs|jj|_dS)zb
        "Pops the stack" on the prefix mapping.

        Gets called after endElementNS.
        N)r1r)r!r@r"r"r#�endPrefixMapping�sz_ToStan.endPrefixMappingcCsB|j}|j��}|j��}|\}}|tkr�|dkr8d}nh|dkr�z|d}	Wntk
rdd}	YnXt|d|	|||d�}
|j�|
�|j	�|
�|
j
|_	dSd}t|�}t|�D],\}}
|\}}|tkr�q�|dkr�|
}||=q�t�}t|�D]<\\}}}
|j
�|�}|dk�r|}nd	||f}|
||<q�|tk�r�|d
k�r�|j�sXtdtf��d|k�rptd
tf��td||||d�}
|
|jdj|d<|j�|
�|
j
|_	dS|j�r�|�t|j��g|_|tk�r|dk	�r|j
|}|dk	�rd	|j
||f}t|t|�||||d�}
|j�|
�|j	�|
�|
j
|_	dS)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)N�name)rE�filename�
lineNumber�columnNumber�renderz%s:%s�attrz<{%s}attr> as top-level elementrFz$<{%s}attr> requires a name attribute)rJrGrHrI���)�
attributesrJrGrHrI)r0r3Z
getLineNumberZgetColumnNumberr�KeyErrorrr7r?r6�childrenrrr1r%�AssertionErrorrrMr8�update)r!ZnamespaceAndName�qnameZattrsrGrHrI�nsrFrEZelrJr&r)ZattrNSZjustTheNameZnonTemplateAttrsZattrNsZattrNameZnsPrefixZattrKeyr@r"r"r#�startElementNS�s�


�	

�
��

�z_ToStan.startElementNScCs*|jr|jd�|�dS|j�|�dS)z�
        Called when we receive some characters.  CDATA characters get passed
        through as is.

        @type ch: C{string}
        rLN)r2r7r?r6)r!Zchr"r"r#�
characterssz_ToStan.characterscCs,|j��|jr |jdj|_n|j|_dS)z�
        A namespace tag is closed.  Pop the stack, if there's anything left in
        it, otherwise return to the document's namespace.
        rLN)r7�poprOr6r5)r!rFrRr"r"r#�endElementNSs
z_ToStan.endElementNScCsdS�z#
        DTDs are ignored.
        Nr")r!rFZpublicIdZsystemIdr"r"r#�startDTD*sz_ToStan.startDTDcGsdSrXr")r!�argsr"r"r#�endDTD0sz_ToStan.endDTDcCsd|_|j�g�dS)zO
        We're starting to be in a CDATA element, make a note of this.
        TN)r2r7r?r9r"r"r#�
startCDATA6sz_ToStan.startCDATAcCs*d|_d�|j���}|j�t|��dS)z�
        We're no longer in a CDATA element.  Collect up the characters we've
        parsed and put them in a new CDATA object.
        FrDN)r2�joinr7rVr6r?r)r!�commentr"r"r#�endCDATA>sz_ToStan.endCDATAcCs|j�t|��dS)z=
        Add an XML comment which we've encountered.
        N)r6r?r)r!Zcontentr"r"r#r^Hsz_ToStan.commentN)r+r,r-r.r$r4r:r;r>rArBrTrUrWrYr[r\r_r^r"r"r"r#r/bs 	
	c

r/cCs�t�}|�tjd�|�tjd�|�tjd�|�tjd�tt|dd��}|�	|�|�
|�|�tj|�|�
|�|jS)z�
    Perform a SAX parse of an XML document with the _ToStan class.

    @param fl: The XML document to be parsed.
    @type fl: A file object or filename.

    @return: a C{list} of Stan objects.
    rrrFN)rZ
setFeaturerZfeature_validationZfeature_namespacesZfeature_external_gesZfeature_external_pesr/�getattrZsetContentHandlerZsetEntityResolverZsetPropertyZproperty_lexical_handler�parser5)Zfl�parser�sr"r"r#�
_flatsaxParsePs	


rdc@s eZdZdZdd�Zdd�ZdS)rz�
    An L{ITemplateLoader} that loads existing L{IRenderable} providers.

    @ivar tag: The object which will be loaded.
    @type tag: An L{IRenderable} provider.
    cCs
||_dS)zm
        @param tag: The object which will be loaded.
        @type tag: An L{IRenderable} provider.
        N��tag)r!rfr"r"r#r$rszTagLoader.__init__cCs|jgS�Nrer9r"r"r#�loadzszTagLoader.loadN�r+r,r-r.r$rhr"r"r"r#risc@s eZdZdZdd�Zdd�ZdS)rz�
    An L{ITemplateLoader} that loads and parses XML from a string.

    @ivar _loadedTemplate: The loaded document.
    @type _loadedTemplate: a C{list} of Stan objects.
    cCs&t|t�s|�d�}tt|��|_dS)z�
        Run the parser on a L{NativeStringIO} copy of the string.

        @param s: The string from which to load the XML.
        @type s: C{str}, or a UTF-8 encoded L{bytes}.
        �utf8N)�
isinstance�str�decoderdr�_loadedTemplate)r!rcr"r"r#r$�s

zXMLString.__init__cCs|jS)zx
        Return the document.

        @return: the loaded document.
        @rtype: a C{list} of Stan objects.
        )rnr9r"r"r#rh�szXMLString.loadNrir"r"r"r#rs
c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)r	a3
    An L{ITemplateLoader} that loads and parses XML from a file.

    @ivar _loadedTemplate: The loaded document, or L{None}, if not loaded.
    @type _loadedTemplate: a C{list} of Stan objects, or L{None}.

    @ivar _path: The L{FilePath}, file object, or filename that is being
        loaded from.
    cCs*t|t�stjdtdd�d|_||_dS)z�
        Run the parser on a file.

        @param path: The file from which to load the XML.
        @type path: L{FilePath}
        zhPassing filenames or file objects to XMLFile is deprecated since Twisted 12.1.  Pass a FilePath instead.�)�category�
stacklevelN)rkr�warnings�warn�DeprecationWarningrn�_path)r!�pathr"r"r#r$�s
�zXMLFile.__init__c
CsBt|jt�st|j�S|j�d��}t|�W5QR�SQRXdS)z{
        Read and parse the XML.

        @return: the loaded document.
        @rtype: a C{list} of Stan objects.
        �rN)rkrurrd�open)r!�fr"r"r#�_loadDoc�s
zXMLFile._loadDoccCsd|jfS)Nz<XMLFile of %r>)rur9r"r"r#�__repr__�szXMLFile.__repr__cCs|jdkr|��|_|jS)z�
        Return the document, first loading it if necessary.

        @return: the loaded document.
        @rtype: a C{list} of Stan objects.
        N)rnrzr9r"r"r#rh�s

zXMLFile.loadN)r+r,r-r.r$rzr{rhr"r"r"r#r	�s

�aZabbrZacronymZaddressZappletZareaZarticleZasideZaudio�b�baseZbasefontZbdiZbdoZbigZ
blockquoteZbody�brZbuttonZcanvasZcaption�centerZcite�code�colZcolgroupZcommandZdatalistZdd�delZdetailsZdfn�dirZdivZdlZdtZemZembedZfieldsetZ
figcaptionZfigureZfontZfooterZform�frameZframesetZh1Zh2Zh3Zh4Zh5Zh6�head�headerZhgroupZhrZhtml�iZiframeZimg�inputZinsZisindexZkeygenZkbdZlabelZlegendZli�link�mapZmarkZmenu�metaZmeterZnavZnoframesZnoscript�objectZolZoptgroupZoption�output�pZparamZpreZprogress�qZrpZrtZrubyrcZsampZscriptZsectionZselectZsmall�source�spanZstrikeZstrongZstyle�subZsummaryZsup�tableZtbodyZtdZtextareaZtfootZthZthead�time�titleZtrZtt�uZul�varZvideoZwbrc@seZdZdZdd�ZdS)�_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.html 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}
    cCs8|dkrtd�S|�d�}|tkr0td|f��t|�S)NrCrD�_zunknown tag %r)r�rstripr�AttributeError)r!ZtagNamer"r"r#�__getattr__s
z_TagFactory.__getattr__N)r+r,r-r.r�r"r"r"r#r��sr��<!DOCTYPE html>csj|dk	r��|���d��dkr.tjjj�t�|�j�}��fdd�}|�|�|��fdd��tS)a�
    Render an element or other C{IRenderable}.

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

    @returns: NOT_DONE_YET

    @since: 12.1
    N�
cs<tjd|d��jjr.t��|��j��d�S��d�dS)Nz/An error occurred while rendering the response.��failurerjsr<div style="font-size:800%;background-color:#FFF;color:#F00">An error occurred while rendering the response.</div>)�
_moduleLogr�ZsiteZdisplayTracebacksr�write�encoder���_failElement�requestr"r#�eb(s�
���zrenderElement.<locals>.ebcs���Srg)Zfinish)r�)r�r"r#�<lambda>8�zrenderElement.<locals>.<lambda>)	r��twistedZweb�utilZFailureElementrZ
addErrbackZaddBoth�NOT_DONE_YET)r��elementZdoctyper�r'r�r"r�r#rs



)rr
)rr)r�N)5r.Z
__future__rr�__all__rr�collectionsrZzope.interfacerZxml.saxrrZtwisted.python.compatrrZtwisted.python.filepathrZtwisted.web._stanrrrrrZtwisted.web.iwebrZtwisted.loggerrrr�r�r�rZContentHandlerZEntityResolverr/rdrrr	�setrr�r
rZtwisted.web._elementrr
Ztwisted.web._flattenrrZtwisted.web.utilr�r"r"r"r#�<module>sT�
)o >��
.