Ϫf# dZddlZddlmZddlmZmZddlmZddl m Z m Z m Z djeedd d dZejeed e e Gd deZdZd'dZdZdZdZdZd(dZdZdZdZd)dZGddej<Zd*dZ d*dZ!d*dZ"dZ#d Z$d*d!Z%d"Z&d#Z'd$Z(d%Z)d&Z*y)+z^ A library for performing interesting tasks with DOM objects. This module is now deprecated. N)StringIO)VersiongetVersionString)microdom)escapegetElementsByTagNameunescapez+twisted.web.domhelpers was deprecated at {}Twisted ) stacklevelc eZdZy)NodeLookupErrorN)__name__ __module__ __qualname__8/usr/lib/python3/dist-packages/twisted/web/domhelpers.pyrrsrrc|jD]Z}t|dr?|jr3|jdt |j|j|zt |||\y)z Look through the given node's children for strings, and attempt to do string substitution with the given parameter. nodeValuerN) childNodeshasattrr replaceDatalen substitute)requestnodesubschilds rrr!sW ) 5+ &5??   aU__!5u7M N7E4()rct|dr8|jr(|D]#}t|j||k(s!|cS|j rrt|j dr|j j }nt|j }t|D]!}t|j ||}|s|cSyy)zx (internal) Get a node with the specified C{nodeId} as any of the C{class}, C{id} or C{pattern} attributes. hasAttributeslengthN) rr#str getAttribute hasChildNodesrr$rrange_get)rnodeId nodeAttrsnodeAttrr$childNumresults rr)r),s t_%$*<*<*>! H4$$X./69    4??H -__++F)Ff  H$//(3V>> doc=microdom.parseString('1234') >>> gatherTextNodes(doc.documentElement) '1234' With dounescape=1, also convert entities back into normal characters. @return: the gathered nodes as a single string @rtype: strrrN)r<rpoprrr rjoin)iNode dounescapejoinWithgatheredgathered_appendslicecvals rgatherTextNodesrZsHooO GE e*q. IIaL 1k "q{{'>q{{+kk C LLbq  e*q. == ""rc$eZdZdZ ddZy)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. NcF|j||j|yN)writedata)selfwriterindent addindentnewlstrip nsprefixes namespaces rwritexmlzRawText.writexmls!  x {4&12r)rjrjrNN)rrr__doc__rirrrr\r\s    3rr\c|g}|js|S|jD](}||r|j|t|||*|Sr^r'rr< findNodesparentmatcheraccumr!s rrnrnsX }    ! "") 5> LL %%( ) Lrc|g}|js|S|jD]2}||r|j|||s%t||||4|Sr^)r'rr<findNodesShallowOnMatch)rprqrecurseMatcherrrr!s rrtrtsd }    ! ""K 5> LL  % #E7NE J K Lrc|g}|js|S|jD])}||r|j|t|||+|Sr^rmros rfindNodesShallowrwsX }    ! ""- 5> LL  eWe , - Lrc"t|fdS)z Return an iterable of the elements which are direct children of C{parent} and which have the C{attribute} attribute. cHt|ddduxr|jSNtagName)getattr hasAttributen attributes rz2findElementsWithAttributeShallow..s#'!Y-T9WannY>Wr)rw)rprs `r findElementsWithAttributeShallowrs W rc t||fdS)z Return an iterable of the elements which are children of C{parent} for which the predicate C{matcher} returns true. c4t|ddduxr||Srz)r|)rrqs rrzfindElements.. s#71i#>d#J$ AJrrn)rprqs r findElementsrs !  rcD|rt|||fdSt||fdS)NcP|j|xr|j||k(Sr^)r}r&)rrr@s rrz+findElementsWithAttribute..s(y8Q93y)U2rc$|j|Sr^)r}r~s rrz+findElementsWithAttribute..s1>>)3Lr)r)rprr@s rfindElementsWithAttributers6   ) 3    L  rc t||fdS)Nc |j|k(Sr^)nodeName)rnames rrz findNodesNamed..s!**2Drr)rprs rfindNodesNamedrs VDD EErc|jD]9}t|dr|jd|jz.t ||;y)Nr`rj)rrr_r` writeNodeData)roldiosubnodes rrrs>??* 7F # KKW\\) * '5 ) *rcNt}t|||jSr^)rrgetvalue)rrs r getNodeTextr's JE$ >> rcNg}|r |j||j}|r |Sr^)r< parentNode)rls r getParentsr-s* A    Hrcb|jDcgc]}t|dd|k(s|c}Scc}w)znnamedChildren(parent, nodeName) -> children (not descendants) of parent that have tagName == nodeName r{rj)rr|)rprrs r namedChildrenr5s.(( R!GAy",E,QA RR Rs,,))idclassmodelpattern))rrjr^)+rkwarningsior incrementalrr twisted.webrtwisted.web.microdomrrr format warningStringwarnDeprecationWarning Exceptionrrr)r1r3r6r5r;rFrJrNrZTextr\rnrtrwrrrrrrrrrrrrs  1 GG=DDWYB23  m/A> i )* "&1 5 4#03hmm32      F*  Sr