o ¯b£$ã@sÖdZddlmZGdd„deƒZGdd„dƒZGdd„dƒZGd d „d ƒZGd d „d ƒZd d„Z Gdd„dƒZ Gdd„dƒZ Gdd„dƒZ Gdd„dƒZ Gdd„dƒZiZdd„Zdd„Zdd„Zdd „Zd!d"„Zd#S)$z¢ XPath query support. This module provides L{XPathQuery} to match L{domish.Element} instances against XPath-like expressions. é)ÚStringIOc@seZdZdd„ZdS)Ú LiteralValuecCs|S©N©©ÚselfÚelemrrú:/usr/lib/python3/dist-packages/twisted/words/xish/xpath.pyÚvalueózLiteralValue.valueN)Ú__name__Ú __module__Ú __qualname__r rrrr rs rc@óeZdZdd„Zdd„ZdS)Ú IndexValuecCst|ƒd|_dS)Né)ÚintÚindex)rrrrr Ú__init__szIndexValue.__init__cCs |j|jSr)Úchildrenrrrrr r ó zIndexValue.valueN)r r rrr rrrr ró rc@ó$eZdZdd„Zdd„Zdd„ZdS)Ú AttribValuecCs ||_|jdkr|j|_dSdS)NÚxmlns)Ú attribnameÚvalue_nsr )rrrrr r s  ÿzAttribValue.__init__cCs|jSr)Úurirrrr r%szAttribValue.value_nscCs|j|jvr |j|jSdSr)rÚ attributesrrrr r (s  zAttribValue.valueN)r r rrrr rrrr rs rc@r)Ú CompareValuecCó,||_||_|dkr|j|_dS|j|_dS)Nú=)ÚlhsÚrhsÚ _compareEqualr Ú_compareNotEqual©rr"Úopr#rrr r0ó   zCompareValue.__init__cCs|j |¡|j |¡kSr©r"r r#rrrr r$8ózCompareValue._compareEqualcCs|j |¡|j |¡kSrr)rrrr r%;r*zCompareValue._compareNotEqualN)r r rrr$r%rrrr r/s rc@s(eZdZdZdd„Zdd„Zdd„ZdS) Ú BooleanValuea^ Provide boolean XPath expression operators. @ivar lhs: Left hand side expression of the operator. @ivar op: The operator. One of C{'and'}, C{'or'}. @ivar rhs: Right hand side expression of the operator. @ivar value: Reference to the method that will calculate the value of this expression given an element. cCr )NÚand)r"r#Ú _booleanAndr Ú _booleanOrr&rrr rJr(zBooleanValue.__init__cCs|j |¡o |j |¡S)z£ Calculate boolean and of the given expressions given an element. @param elem: The element to calculate the value of the expression from. r)rrrr r-RózBooleanValue._booleanAndcCs|j |¡p |j |¡S)z¢ Calculate boolean or of the given expressions given an element. @param elem: The element to calculate the value of the expression from. r)rrrr r.Zr/zBooleanValue._booleanOrN)r r rÚ__doc__rr-r.rrrr r+?s   r+cCsd|}tƒ|ƒ}|S)z; Internal method which selects the function object z _%s_Function)Úglobals)ÚfnameÚ klassnameÚcrrr ÚFunctioncs r5c@r)Ú _not_FunctioncCs d|_dSr©Ú baseValue©rrrr rmó z_not_Function.__init__cCs ||_dSrr7)rr8rrr Ú setParamspr:z_not_Function.setParamscCs|j |¡ Sr)r8r rrrr r sóz_not_Function.valueN)r r rrr;r rrrr r6ls r6c@r)Ú_text_FunctioncCsdSrrr9rrr r;xr z_text_Function.setParamscCst|ƒSr)Ústrrrrr r {óz_text_Function.valueN)r r rr;r rrrr r=wrr=c@ó<eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd S)Ú _LocationcCóg|_d|_d|_dSr©Ú predicatesÚ elementNameÚ childLocationr9rrr r€ó z_Location.__init__cCs:|jdkr |j|jkr dS|jD] }| |¡sdSqdS©Nrr)rEÚnamerDr ©rrÚprrr ÚmatchesPredicates…s  ÿz_Location.matchesPredicatescCs@| |¡sdS|jdkr| ¡D] }|j |¡rdSqdSdSrH)rLrFÚelementsÚmatches©rrr4rrr rNs    ÿþz_Location.matchescCsJ| |¡sdS|jdkr| ¡D] }|j ||¡qdS| t|ƒ¡dSr)rLrFrMÚqueryForStringÚwriter>)rrÚ resultbufr4rrr rPœs   ÿz_Location.queryForStringcCsF| |¡sdS|jdkr| ¡D] }|j ||¡qdS| |¡dSr)rLrFrMÚ queryForNodesÚappend©rrÚ resultlistr4rrr rS¦s   ÿz_Location.queryForNodescCs\| |¡sdS|jdkr| ¡D] }|j ||¡qdS|jD] }t|tƒr+| |¡qdSr)rLrFrMÚqueryForStringListrÚ isinstancer>rTrUrrr rW°s   ÿ   €þz_Location.queryForStringListN) r r rrrLrNrPrSrWrrrr rAs   rAc@sTeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dS)Ú _AnyLocationcCrBrrCr9rrr r¾rGz_AnyLocation.__init__cCs |jD] }| |¡s dSqdSrH)rDr rJrrr rLÃs  ÿz_AnyLocation.matchesPredicatescCs(|jdkr | |j|¡| |j¡dSr)ÚparentÚ listParentsrTrI)rrÚ parentlistrrr r[És z_AnyLocation.listParentscCsV|jdks |j|jkr)| |¡r)|jdkr'| ¡D] }|j |¡r$dSqdSdSdS©NTF©rErIrLrFrMrNrOrrr Ú isRootMatchÎsÿ   ÿÿz_AnyLocation.isRootMatchcCsx|jdks |j|jkr*| |¡r*|jdkr(| ¡D] }|j |¡r%|SqdS|S| ¡D] }| |¡r9|Sq.dSrr^rOrrr ÚfindFirstRootMatchÚsÿ   ÿ  ÿz_AnyLocation.findFirstRootMatchcCs0| |¡rdS| ¡D] }| |¡rdSq dSr])r_rMrNrOrrr rNôs   ÿz_AnyLocation.matchescCstdƒ‚)Nz2queryForString is not implemented for any location)ÚNotImplementedError)rrrRrrr rPr?z_AnyLocation.queryForStringcCs2| |¡r | |¡| ¡D]}| ||¡qdSr)r_rTrMrSrUrrr rSs   ÿz_AnyLocation.queryForNodescCsH| |¡r|jD] }t|tƒr| |¡q| ¡D]}| ||¡qdSr)r_rrXr>rTrMrWrUrrr rW s    € ÿz_AnyLocation.queryForStringListN) r r rrrLr[r_r`rNrPrSrWrrrr rY½s   rYc@r@)Ú XPathQuerycCs4||_ddlm}m}|||ƒƒ}t|dƒƒ|_dS)Nr)Ú XPathParserÚXPathParserScannerÚXPATH)ÚqueryStrÚtwisted.words.xish.xpathparserrcrdÚgetattrÚ baseLocation)rrfrcrdÚparserrrr rs zXPathQuery.__init__cCs |j ¡Sr)rfÚ__hash__r9rrr rkr:zXPathQuery.__hash__cCs |j |¡Sr)rirNrrrr rN"rzXPathQuery.matchescCstƒ}|j ||¡| ¡Sr)rrirPÚgetvalue©rrÚresultrrr rP%szXPathQuery.queryForStringcCó&g}|j ||¡t|ƒdkrdS|S©Nr)rirSÚlenrmrrr rS*ó  zXPathQuery.queryForNodescCrorp)rirWrqrmrrr rW2rrzXPathQuery.queryForStringListN) r r rrrkrNrPrSrWrrrr rbs rbcCs|tvr t|ƒt|<t|Sr)Ú__internedQueriesrb)Ú queryStringrrr Ú internQuery>s rucCót|ƒ |¡Sr)rurN©Úxpathstrrrrr rNDr<rNcCrvr)rurWrwrrr rWHr<rWcCrvr)rurPrwrrr rPLr<rPcCrvr)rurSrwrrr rSPr<rSN)r0Úiorr>rrrrr+r5r6r=rArYrbrsrurNrWrPrSrrrr Ús& $  >Y%