Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/twisted/web/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/twisted/web/__pycache__/template.cpython-37.pyc

B

;��]�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/namespace�xml)�parentr�nss)�selfr �r#�G/opt/alt/python37/lib64/python3.7/site-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"r1r#r#r$r%hsz_ToStan.__init__cCs
||_dS)zY
        Set the document locator, which knows about line and character numbers.
        N)�locator)r"r4r#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#)r"r#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)rr2rr9�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)r2r )r"r@r#r#r$�endPrefixMapping�sz_ToStan.endPrefixMappingcCsJ|j}|j��}|j��}|\}}|tkr�|dkr8d}nh|dkr�y|d}	Wntk
rdd}	YnXt|d|	|||d�}
|j�|
�|j	�|
�|
j
|_	dSd}t|�}x8t|�D],\}}
|\}}|tkr�q�|dkr�|
}||=q�Wt�}xHt|�D]<\\}}}
|j
�|�}|dk�r|}nd	||f}|
||<q�W|tk�r�|d
k�r�|j�s`tdtf��d|k�rxtd
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)r1r4Z
getLineNumberZgetColumnNumberr�KeyErrorrr8r?r7�childrenrrr2r&�AssertionErrorrrMr9�update)r"ZnamespaceAndName�qname�attrsrGrHrI�nsrFrE�elrJr'r*ZattrNSZjustTheNameZnonTemplateAttrsZattrNs�attrNameZnsPrefixZattrKeyr@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)r3r8r?r7)r"�chr#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)r8�poprOr7r6)r"rFrRr#r#r$�endElementNSs
z_ToStan.endElementNScCsdS)z#
        DTDs are ignored.
        Nr#)r"rFZpublicIdZsystemIdr#r#r$�startDTD*sz_ToStan.startDTDcGsdS)z#
        DTDs are ignored.
        Nr#)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)r3r8r?)r"r#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)r3�joinr8rZr7r?r)r"�commentr#r#r$�endCDATA>sz_ToStan.endCDATAcCs|j�t|��dS)z=
        Add an XML comment which we've encountered.
        N)r7r?r)r"�contentr#r#r$raHsz_ToStan.commentN)r,r-r.r/r%r5r:r;r>rArBrWrYr[r\r^r_rbrar#r#r#r$r0bs 	
	c

r0cCs�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_pesr0�getattrZsetContentHandlerZsetEntityResolverZsetPropertyZproperty_lexical_handler�parser6)Zfl�parser�sr#r#r$�
_flatsaxParsePs	


rhc@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"rir#r#r$r%rszTagLoader.__init__cCs|jgS)N)ri)r"r#r#r$�loadzszTagLoader.loadN)r,r-r.r/r%rjr#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�decoderhr�_loadedTemplate)r"rgr#r#r$r%�s

zXMLString.__init__cCs|jS)zx
        Return the document.

        @return: the loaded document.
        @rtype: a C{list} of Stan objects.
        )ro)r"r#r#r$rj�szXMLString.loadN)r,r-r.r/r%rjr#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)rlr�warnings�warn�DeprecationWarningro�_path)r"�pathr#r#r$r%�s

zXMLFile.__init__c	Cs6t|jt�st|j�S|j�d��
}t|�SQRXdS)z{
        Read and parse the XML.

        @return: the loaded document.
        @rtype: a C{list} of Stan objects.
        �rN)rlrvrrh�open)r"�fr#r#r$�_loadDoc�s
zXMLFile._loadDoccCsd|jfS)Nz<XMLFile of %r>)rv)r"r#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)ror{)r"r#r#r$rj�s

zXMLFile.loadN)r,r-r.r/r%r{r|rjr#r#r#r$r	�s

�aZabbrZacronym�addressZappletZareaZarticleZasideZaudio�b�baseZbasefontZbdiZbdo�bigZ
blockquote�body�brZbuttonZcanvasZcaption�centerZcite�code�colZcolgroup�commandZdatalist�dd�del�detailsZdfn�dirZdivZdl�dtZemZembedZfieldsetZ
figcaptionZfigureZfontZfooterZform�frameZframesetZh1Zh2Zh3Zh4Zh5Zh6�head�headerZhgroup�hr�html�iZiframeZimg�inputZinsZisindexZkeygenZkbd�labelZlegendZli�link�mapZmarkZmenu�metaZmeterZnavZnoframesZnoscript�objectZolZoptgroup�option�output�p�param�preZprogress�qZrp�rtZrubyrgZsamp�script�section�selectZsmall�source�spanZstrikeZstrong�style�sub�summaryZsup�tableZtbody�tdZtextareaZtfoot�thZthead�time�title�tr�tt�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.)�failurerksr<div style="font-size:800%;background-color:#FFF;color:#F00">An error occurred while rendering the response.</div>)�
_moduleLogr��siteZdisplayTracebacksr�write�encode)r�)�_failElement�requestr#r$�eb(s
zrenderElement.<locals>.ebcs���S)N)Zfinish)r�)r�r#r$�<lambda>8�zrenderElement.<locals>.<lambda>)	r��twistedZweb�utilZFailureElementrZ
addErrbackZaddBoth�NOT_DONE_YET)r��elementZdoctyper�r(r�r#)r�r�r$rs



)rr
)rr)r�N)5r/�
__future__rr�__all__rs�collectionsrZzope.interfacerZxml.saxrrZtwisted.python.compatrrZtwisted.python.filepathrZtwisted.web._stanrrrrrZtwisted.web.iwebrZtwisted.loggerrrr�r�r�rZContentHandlerZEntityResolverr0rhrrr	�setrr�r
rZtwisted.web._elementrr
Ztwisted.web._flattenrrZtwisted.web.utilr�r#r#r#r$�<module>s`
)o >

-