U
    
W[&*                     @   sx   d Z ddlmZmZ ddlmZ G dd deZG dd deZdZ	G d	d
 d
eZ
G dd deZG dd deZdS )aC  
An s-expression-like syntax for expressing xml in pure python.

Stan tags allow you to build XML documents using Python.

Stan is a DOM, or Document Object Model, implemented using basic Python types
and functions called "flatteners". A flattener is a function that knows how to
turn an object of a specific type into something that is closer to an HTML
string. Stan differs from the W3C DOM by not being as cumbersome and heavy
weight. Since the object model is built using simple python types such as lists,
strings, and dictionaries, the API is simpler and constructing a DOM less
cumbersome.

@var voidElements: the names of HTML 'U{void
    elements<http://www.whatwg.org/specs/web-apps/current-work/multipage/syntax.html#void-elements>}';
    those which can't have contents and can therefore be self-closing in the
    output.
    )absolute_importdivision)	iteritemsc                   @   s"   e Zd ZdZdddZdd ZdS )slota}  
    Marker for markup insertion in a template.

    @type name: C{str}
    @ivar name: The name of this slot.  The key which must be used in
        L{Tag.fillSlots} to fill it.

    @type children: C{list}
    @ivar children: The L{Tag} objects included in this L{slot}'s template.

    @type default: anything flattenable, or L{None}
    @ivar default: The default contents of this slot, if it is left unfilled.
        If this is L{None}, an L{UnfilledSlot} will be raised, rather than
        L{None} actually being used.

    @type filename: C{str} or L{None}
    @ivar filename: The name of the XML file from which this tag was parsed.
        If it was not parsed from an XML file, L{None}.

    @type lineNumber: C{int} or L{None}
    @ivar lineNumber: The line number on which this tag was encountered in the
        XML file from which it was parsed.  If it was not parsed from an XML
        file, L{None}.

    @type columnNumber: C{int} or L{None}
    @ivar columnNumber: The column number at which this tag was encountered in
        the XML file from which it was parsed.  If it was not parsed from an
        XML file, L{None}.
    Nc                 C   s(   || _ g | _|| _|| _|| _|| _d S N)namechildrendefaultfilename
lineNumbercolumnNumber)selfr   r	   r
   r   r    r   3/usr/lib/python3/dist-packages/twisted/web/_stan.py__init__=   s    zslot.__init__c                 C   s   d| j f S )Nzslot(%r))r   r   r   r   r   __repr__G   s    zslot.__repr__)NNNN__name__
__module____qualname____doc__r   r   r   r   r   r   r      s
     

r   c                   @   s\   e Zd ZdZdZdZdZdZdddZdd Z	dd Z
d	d
 ZdddZdd Zdd ZdS )Taga  
    A L{Tag} represents an XML tags with a tag name, attributes, and children.
    A L{Tag} can be constructed using the special L{twisted.web.template.tags}
    object, or it may be constructed directly with a tag name. L{Tag}s have a
    special method, C{__call__}, which makes representing trees of XML natural
    using pure python syntax.

    @ivar tagName: The name of the represented element.  For a tag like
        C{<div></div>}, this would be C{"div"}.
    @type tagName: C{str}

    @ivar attributes: The attributes of the element.
    @type attributes: C{dict} mapping C{str} to renderable objects.

    @ivar children: The child L{Tag}s of this C{Tag}.
    @type children: C{list} of renderable objects.

    @ivar render: The name of the render method to use for this L{Tag}.  This
        name will be looked up at render time by the
        L{twisted.web.template.Element} doing the rendering, via
        L{twisted.web.template.Element.lookupRenderMethod}, to determine which
        method to call.
    @type render: C{str}

    @type filename: C{str} or L{None}
    @ivar filename: The name of the XML file from which this tag was parsed.
        If it was not parsed from an XML file, L{None}.

    @type lineNumber: C{int} or L{None}
    @ivar lineNumber: The line number on which this tag was encountered in the
        XML file from which it was parsed.  If it was not parsed from an XML
        file, L{None}.

    @type columnNumber: C{int} or L{None}
    @ivar columnNumber: The column number at which this tag was encountered in
        the XML file from which it was parsed.  If it was not parsed from an
        XML file, L{None}.

    @type slotData: C{dict} or L{None}
    @ivar slotData: The data which can fill slots.  If present, a dictionary
        mapping slot names to renderable values.  The values in this dict might
        be anything that can be present as the child of a L{Tag}; strings,
        lists, L{Tag}s, generators, etc.
    Nc                 C   sf   || _ || _|d kri | _n|| _|d kr2g | _n|| _|d k	rF|| _|d k	rT|| _|d k	rb|| _d S r   )tagNamerender
attributesr   r
   r   r   )r   r   r   r   r   r
   r   r   r   r   r   r      s    zTag.__init__c                 K   s    | j dkri | _ | j | | S )a@  
        Remember the slots provided at this position in the DOM.

        During the rendering of children of this node, slots with names in
        C{slots} will be rendered as their corresponding values.

        @return: C{self}. This enables the idiom C{return tag.fillSlots(...)} in
            renderers.
        N)slotDataupdate)r   slotsr   r   r   	fillSlots   s    

zTag.fillSlotsc                 O   sT   | j | t|D ]:\}}|d dkr4|dd }|dkrD|| _q|| j|< q| S )a  
        Add children and change attributes on this tag.

        This is implemented using __call__ because it then allows the natural
        syntax::

          table(tr1, tr2, width="100%", height="50%", border="1")

        Children may be other tag instances, strings, functions, or any other
        object which has a registered flatten.

        Attributes may be 'transparent' tag instances (so that
        C{a(href=transparent(data="foo", render=myhrefrenderer))} works),
        strings, functions, or any other object which has a registered
        flattener.

        If the attribute is a python keyword, such as 'class', you can add an
        underscore to the name, like 'class_'.

        There is one special keyword argument, 'render', which will be used as
        the name of the renderer and saved as the 'render' attribute of this
        instance, rather than the DOM 'render' attribute in the attributes
        dictionary.
        _Nr   )r   extendr   r   r   )r   r   kwkvr   r   r   __call__   s    zTag.__call__c                    s>   t |dr| S t|ttfr6 fdd|D S |S dS )ad  
        Clone an arbitrary object; used by L{Tag.clone}.

        @param obj: an object with a clone method, a list or tuple, or something
            which should be immutable.

        @param deep: whether to continue cloning child objects; i.e. the
            contents of lists, the sub-tags within a tag.

        @return: a clone of C{obj}.
        clonec                    s   g | ]} | qS r   _clone.0xdeepr   r   r   
<listcomp>   s     zTag._clone.<locals>.<listcomp>N)hasattrr'   
isinstancelisttuple)r   objr.   r   r-   r   r)      s
    

z
Tag._cloneTc              	      s   |r fdd j D }n j dd } j }| D ]} || d||< q:d} jr j }|D ]} || d||< qlt j|| j j	 j
 jd}||_|S )z
        Return a clone of this tag. If deep is True, clone all of this tag's
        children. Otherwise, just shallow copy the children list without copying
        the children themselves.
        c                    s   g | ]}  |d qS )Tr(   r*   r   r   r   r/      s     zTag.clone.<locals>.<listcomp>NT)r   r   r   r
   r   r   )r   r   copykeysr)   r   r   r   r   r
   r   r   )r   r.   ZnewchildrenZnewattrskeyZnewslotdataZnewtagr   r   r   r'      s,    

z	Tag.clonec                 C   s
   g | _ | S )z<
        Clear any existing children from this tag.
        )r   r   r   r   r   clear   s    z	Tag.clearc                 C   s:   d}| j r|d| j  7 }| jr,|d| j 7 }d| j|f S )N z, attributes=%rz, children=%rz	Tag(%r%s))r   r   r   )r   Zrstrr   r   r   r     s    zTag.__repr__)NNNNNN)T)r   r   r   r   r   r
   r   r   r   r   r&   r)   r'   r8   r   r   r   r   r   r   L   s    -      
&
!r   )ZimgbrZhrbasemetalinkZparamZareainputcolZbasefontZisindexframeZcommandZembedZkeygensourceZtrackZwbsc                   @   s    e Zd ZdZdd Zdd ZdS )CDATAa  
    A C{<![CDATA[]]>} block from a template.  Given a separate representation in
    the DOM so that they may be round-tripped through rendering without losing
    information.

    @ivar data: The data between "C{<![CDATA[}" and "C{]]>}".
    @type data: C{unicode}
    c                 C   s
   || _ d S r   datar   rD   r   r   r   r     s    zCDATA.__init__c                 C   s   d| j f S )Nz	CDATA(%r)rC   r   r   r   r   r   "  s    zCDATA.__repr__Nr   r   r   r   r   rB     s   rB   c                   @   s    e Zd ZdZdd Zdd ZdS )Commenta	  
    A C{<!-- -->} comment from a template.  Given a separate representation in
    the DOM so that they may be round-tripped through rendering without losing
    information.

    @ivar data: The data between "C{<!--}" and "C{-->}".
    @type data: C{unicode}
    c                 C   s
   || _ d S r   rC   rE   r   r   r   r   1  s    zComment.__init__c                 C   s   d| j f S )NzComment(%r)rC   r   r   r   r   r   5  s    zComment.__repr__Nr   r   r   r   r   rF   '  s   	rF   c                   @   s    e Zd ZdZdd Zdd ZdS )CharRefa%  
    A numeric character reference.  Given a separate representation in the DOM
    so that non-ASCII characters may be output as pure ASCII.

    @ivar ordinal: The ordinal value of the unicode character to which this is
        object refers.
    @type ordinal: C{int}

    @since: 12.0
    c                 C   s
   || _ d S r   ordinal)r   rI   r   r   r   r   E  s    zCharRef.__init__c                 C   s   d| j f S )NzCharRef(%d)rH   r   r   r   r   r   I  s    zCharRef.__repr__Nr   r   r   r   r   rG   :  s   
rG   N)r   Z
__future__r   r   Ztwisted.python.compatr   objectr   r   ZvoidElementsrB   rF   rG   r   r   r   r   <module>   s   . E