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: //lib/python3/dist-packages/twisted/web/__pycache__/domhelpers.cpython-38.pyc
U


W[�!�@sdZddlmZddlmZddlmZmZmZeeGdd�de	�Z
dd�Zd9d
d�Zdd
�Z
dd�Zdd�Zdd�Zd:dd�Zdd�Zdd�Zdd�Zd;dd�ZGd d!�d!ej�Zd<d#d$�Zd=d%d&�Zd>d'd(�Zd)d*�Zd+d,�Zd?d-d.�Zd/d0�Zd1d2�Zd3d4�Z d5d6�Z!d7d8�Z"d"S)@z>
A library for performing interesting tasks with DOM objects.
�)�StringIO)�microdom)�getElementsByTagName�escape�unescapec@seZdZdS)�NodeLookupErrorN)�__name__�
__module__�__qualname__�rr�8/usr/lib/python3/dist-packages/twisted/web/domhelpers.pyrsrcCsF|jD]:}t|d�r4|jr4|�dt|j�|j|�t|||�qdS)z�
    Look through the given node's children for strings, and
    attempt to do string substitution with the given parameter.
    �	nodeValuerN)�
childNodes�hasattrr
ZreplaceData�len�
substitute)Zrequest�nodeZsubs�childrrrrs
r��id�classZmodel�patterncCs�t|d�r6|��r6|D]}t|�|��|kr|Sq|��r�t|jd�rT|jj}n
t|j�}t|�D] }t	|j||�}|rf|SqfdS)zx
    (internal) Get a node with the specified C{nodeId} as any of the C{class},
    C{id} or C{pattern} attributes.
    �
hasAttributes�lengthN)
rr�str�getAttribute�
hasChildNodesrrr�range�_get)r�nodeIdZ	nodeAttrsZnodeAttrrZchildNum�resultrrrr!s


rcCst||�}|r|St|��dS)z�
    Get a node with the specified C{nodeId} as any of the C{class},
    C{id} or C{pattern} attributes. If there is no such node, raise
    L{NodeLookupError}.
    N)rr�rrr rrr�get4s
r"cCs
t||�S)z�
    Get a node with the specified C{nodeId} as any of the C{class},
    C{id} or C{pattern} attributes.  If there is no such node, return
    L{None}.
    )r)rrrrr�getIfExists>sr#cCst||�}|rt|�|S)z�Get a node with the specified C{nodeId} as any of the C{class},
    C{id} or C{pattern} attributes. If there is no such node, raise
    L{NodeLookupError}. Remove all child nodes before returning.
    )r"�	clearNoder!rrr�getAndClearFs
r%cCsg|jdd�<dS)z2
    Remove all children from the given node.
    N�r)rrrrr$Psr$�cCsrg}t|tg��s"t|j|||�S|D]F}t|d�s6q&t|�|��|krX|�|�|rXq&|�t||||��q&|S)z\
    Find subnodes in the given node where the given attribute
    has the given value.
    r)	�
isinstance�type�locateNodesrrrr�append�extend)ZnodeList�key�valueZ	noNestingZ
returnListZ	childNoderrrr*Vs

r*cCs>t|d�sdS|�||�|��r:|jD]}t|||�q(dS)N�setAttribute)rr/rr�superSetAttribute)rr-r.rrrrr0hs

r0cCsbt|d�sdS|�|�}|r2|�||d|�n|�||�|��r^|jD]}t|||�qLdS�Nr/�/)rrr/rr�superPrependAttribute�rr-r.�oldrrrrr3os


r3cCsbt|d�sdS|�|�}|r2|�||d|�n|�||�|��r^|jD]}t|||�qLdSr1)rrr/rr�superAppendAttributer4rrrr6zs


r6�cCsrg}|j}|g}t|�dkrh|�d�}t|d�rX|jdk	rX|rJt|j�}n|j}||�|j|dd�<q|�|�S)aMVisit each child node and collect its text data, if any, into a string.
For example::
    >>> doc=microdom.parseString('<a>1<b>2<c>3</c>4</b></a>')
    >>> gatherTextNodes(doc.documentElement)
    '1234'
With dounescape=1, also convert entities back into normal characters.
@return: the gathered nodes as a single string
@rtype: str
rr
N)r+r�poprr
rr�join)ZiNodeZ
dounescapeZjoinWithZgatheredZgathered_append�slice�c�valrrr�gatherTextNodes�s

r=c@seZdZdZddd�ZdS)�RawTexta7This is an evil and horrible speed hack. Basically, if you have a big
    chunk of XML that you want to insert into the DOM, but you don't want to
    incur the cost of parsing it, you can construct one of these and insert it
    into the DOM. This will most certainly only work with microdom as the API
    for converting nodes to xml is different in every DOM implementation.

    This could be improved by making this class a Lazy parser, so if you
    inserted this into the DOM and then later actually tried to mutate this
    node, it would be parsed then.
    r7rNcCs|�d||j|f�dS)Nz%s%s%s)�write�data)�self�writer�indentZ	addindentZnewl�stripZ
nsprefixes�	namespacerrr�writexml�szRawText.writexml)r7r7r7rNN)rr	r
�__doc__rFrrrrr>�sr>NcCsF|dkrg}|��s|S|jD]"}||�r4|�|�t|||�q|S�N�rrr+�	findNodes��parent�matcher�accumrrrrrJ�s

rJcCsP|dkrg}|��s|S|jD],}||�r4|�|�||�rt||||�q|SrH)rrr+�findNodesShallowOnMatch)rLrMZrecurseMatcherrNrrrrrO�s

rOcCsH|dkrg}|��s|S|jD]$}||�r6|�|�qt|||�q|SrHrIrKrrr�findNodesShallow�s
rPcst|�fdd��S)z�
    Return an iterable of the elements which are direct children of C{parent}
    and which have the C{attribute} attribute.
    cst|dd�dk	o|���S�N�tagName)�getattr�hasAttribute)�n��	attributerr�<lambda>�sz2findElementsWithAttributeShallow.<locals>.<lambda>)rP)rLrWrrVr� findElementsWithAttributeShallow�s
�rYcCst||fdd��S)z�
    Return an iterable of the elements which are children of C{parent} for
    which the predicate C{matcher} returns true.
    cSst|dd�dk	o||�SrQ�rS)rUrMrrrrX�szfindElements.<locals>.<lambda>�rJ)rLrMrrr�findElements�s
�r\cCs.|rt|||fdd��St||fdd��SdS)NcSs|�|�o|�|�|kSrH)rTr)rUrWr.rrrrX�sz+findElementsWithAttribute.<locals>.<lambda>cSs
|�|�SrH)rT)rUrWrrrrX��)r\)rLrWr.rrr�findElementsWithAttribute�s�
�r^cCst||fdd��S)NcSs
|j|kSrH��nodeName)rU�namerrrrX�r]z findNodesNamed.<locals>.<lambda>r[)rLrarrr�findNodesNamed�srbcCs6|jD]*}t|d�r&|�d|j�qt||�qdS)Nr@r7)rrr?r@�
writeNodeData)r�oldioZsubnoderrrrc�s

rccCst�}t||�|��SrH)rrc�getvalue)rrdrrr�getNodeText�s
rfcCsg}|r|�|�|j}q|SrH)r+Z
parentNode)r�lrrr�
getParentss

rhcs�fdd�|jD�S)znnamedChildren(parent, nodeName) -> children (not descendants) of parent
    that have tagName == nodeName
    cs g|]}t|dd��kr|�qS)rRr7rZ)�.0rUr_rr�
<listcomp>sz!namedChildren.<locals>.<listcomp>r&)rLr`rr_r�
namedChildrensrk)r)r')rr7)N)N)N)N)#rG�iorZtwisted.webrZtwisted.web.microdomrrr�	Exceptionrrrr"r#r%r$r*r0r3r6r=ZTextr>rJrOrPrYr\r^rbrcrfrhrkrrrr�<module>s: