o !b8@sdZddlmZddlmZddlmZmZddlZddl Z ddl m Z ddl Z ddl mZddlmZmZmZmZdd lmZmZmZmZmZmZmZmZmZd d gZd ZGd ddeZ e j!Z!e j"Z"e j#Z#e j$Z$e j%Z%GdddeZ&GdddeZ'GdddeZ(Gdd d eZ)Gdd d e*Z+GdddeZ,ddZ-ddZ.ddZ/dd Z0d!d"Z1Gd#d$d$eZ2Gd%d&d&eZ3Gd'd(d(eZ4Gd)d*d*eZ5Gd+d,d,eZ6Gd-d.d.eZ7Gd/d0d0eZ8Gd1d2d2eZ9e6e7e8e9d3Z:Gd4d5d5eZ;Gd6d7d7e;ZGdd?d?e;Z@Gd@dAdAe;ZAGdBdCdCe;ZBGdDdEdEe;ZCGdFdGdGe;ZDGdHdIdIe;ZEGdJdKdKe;ZFGdLdMdMe;ZGGdNdOdOe;ZHGdPdQdQe;ZIGdRdSdSe;ZJGdTdUdUe;ZKGdVdWdWe;ZLGdXdYdYe;ZMGdZd[d[e;ZNGd\d]d]e;ZOGd^d_d_e;ZPid`e<dae=dbe>dce?dde@deeAdfeBdgeCdheDdieEdjeGdkeFdleHdmeIdneJdoeKdpeLeMeNeOePdqZQGdrdsdseZRGdtdudueRZSGdvdwdweRZTGdxdydyeRZUGdzd{d{eZVGd|d}d}eZWGd~ddeZXGdddeZYGdddeZZGdddeZ[GdddeZ\GdddeZ]eWeXeZe[e\e]dZ^e$e2ddfZ_e%e2ddfZ`dS)aDBasic support for evaluating XPath expressions against streams. >>> from genshi.input import XML >>> doc = XML(''' ... ... ... Foo ... ... ... Bar ... ... ... Baz ... ... ... Waz ... ... ... ''') >>> print(doc.select('items/item[@status="closed" and ' ... '(@resolution="invalid" or not(@resolution))]/summary/text()')) BarBaz Because the XPath engine operates on markup streams (as opposed to tree structures), it only implements a subset of the full XPath 1.0 language. )deque)reduce)ceilfloorN)chain) IS_PYTHON2)StreamAttrs NamespaceQName) STARTENDTEXTSTART_NSEND_NSCOMMENTPI START_CDATA END_CDATAPathPathSyntaxErrorzrestructuredtext enc@s0eZdZdZdZdZdZdZdZe ddZ d S) Axisz7Defines constants for the various supported XPath axes. attributechild descendantzdescendant-or-selfselfcCst||dddS)zdReturn the axis constant for the given name, or `None` if no such axis was defined. -_N)getattrupperreplace)clsnamer#-/usr/lib/python3/dist-packages/genshi/path.pyfornameDsz Axis.fornameN) __name__ __module__ __qualname____doc__ ATTRIBUTECHILD DESCENDANTDESCENDANT_OR_SELFSELF classmethodr%r#r#r#r$r;src@(eZdZeddZddZddZdS)GenericStrategycCdSNTr#r!pathr#r#r$supportsUszGenericStrategy.supportscC ||_dSNr5rr5r#r#r$__init__Y zGenericStrategy.__init__cs|j}|r(|ddturtg|n5t|dd|ddfg|ddn |ddtus@|ddtus@|ddturFtg|n|dggfggdfdd }|S)NrFcs|dd\}}}d}|turrdS|tus'|tus'|tus'|tur)dStdddD}g} tddtkpBd} d} |r\| \} } }| \}}}|t us_|t ur|| r|| ru| dd| kru| dd | n| | | f||||||sqFt}t| t|}d}d}|r|D]U}||||||}t|turtt| |D]+\}}||vrqt||dkr| d||d7<||t|kr||qt||krd}|d7}|sd}nq|sqFg}| d| krd}d\}}}|tur||||||}|r|}nD| dd}|t us(|turK|r6|dd| dkrB|| dg|gfn |dd  ||turZ| | d|gf|sI|turf | |S) NcSsg|] \}}||gfqSr#r#).0poscour#r#r$ z7GenericStrategy.test.._test..rr=TFr>)r poprrrrrlenr*popleftr,r-extendappendsettypefloat enumeraterintaddr. appendleftr )event namespaces variables updateonlykinddatarAretval pos_queuenext_posreal_len last_checkedxpcoumcouaxisnodetest predicatesmissed counters_lencnummatched predicatepretvalirB child_counter next_axisstackstepsr#r$_testss        Z z#GenericStrategy.test.._testF)r5r*_DOTSLASHSLASHr-r+r, _DOTSLASH)rignore_contextpror#rlr$test\s *   vzGenericStrategy.testNr&r'r(r/r6r;rur#r#r#r$r1S   r1c@s,eZdZdZeddZddZddZdS) SimplePathStrategyzCStrategy for path with only local names, attributes and text nodes.cCsL|ddtur dStttf}|D]\}}}|rdSt||s#dSqdS)NrFT)r* LocalNameTestCommentNodeTest TextNodeTest isinstance)r!r5 allowed_testsrrarbr#r#r$r6s  zSimplePathStrategy.supportscs$g|_d}g}ddfdd}|D]n}|dtur.nodes_equalcst|dkrgSdg}d}tdt|D]4}|dkr6||||s6||d}|dkr6||||r#||||rC|d7}||q|S)z KMP prefix calculation for tablerr=)rGrangerJ)fpisrirr#r$ calculate_pis   z1SimplePathStrategy.__init__..calculate_pirr=rET) fragmentsr.rGrJr+r*r,)rr5self_beginningfragmentrr`rr#rr$r;s8       zSimplePathStrategy.__init__cs:gjj|jtdfdd }|S)NFcsdurdS|dd\}}}|turrdS|tus*|tus*|tus*|tur,dSs^d}|ds@|d7}|dr6d}pG|dk} |ds]rT|dkr]||| fdSnd\}}} |dur| s|\} } } } t| }||kr|n| ||||||r|d7}nd\}}||kr|dkr|d7}d}d} |dur|tur||| fdS| r |\} } } } t| }|dkr||ks| ||||||s| |d}|dkr||ks| ||||||r| ||||||r|d7}||kr|dkrn|d7}d}d} |dsnnnq|tur=| s6|dkr6||kr6dd| fn||| f|dkrV||krV| rT| |||||SdSdS)Nr?rr=rENNT)r rrrrrGr )rRrSrTrUrVrWrAfidrticfragrattribrfrag_lenfrags frags_lenrsrm stack_pop stack_pushr#r$roJs        z&SimplePathStrategy.test.._testrp)rJrFrrGrrsror#rr$ru?snzSimplePathStrategy.testN)r&r'r(r)r/r6r;rur#r#r#r$rxs   Drxc@r0)SingleStepStrategycCs t|dkSNr=)rGr4r#r#r$r6 zSingleStepStrategy.supportscCr7r8r9r:r#r#r$r;r<zSingleStepStrategy.__init__csd|jddturtgddturddpdgdgdfdd }|S)NrrEr=Fcs|dd\}}}|tursdd8<dS|tus)|tus)|tus)|tur+dSsgddtur;ddkpVddtuoHddkpVddtuoVddk}|turcdd7<|rgdSd\}} } | |||||sxdS| rd} | D]8} | |||||} t | t urt | dkr d| d7<| t | krd} | d7} | sdSq~r|||||SdS)Nr?rr=FT)r rrrrr.r+r,r rLrMrGrJrO)rRrSrTrUrVrWrAoutsider`rarbrergrhcountersdepthrs select_attrrnr#r$rosL  z&SingleStepStrategy.test.._testrp)r5r*rrrr#rr$rus  /zSingleStepStrategy.testNrvr#r#r#r$rrwrc@s@eZdZdZeeefZd ddZddZ ddd Z dd d Z dS)rzImplements basic XPath support on streams. Instances of this class represent a "compiled" XPath expression, and provide methods for testing the path against a stream, as well as extracting a substream matching that path. NrEcCs`||_t||||_g|_|jD]}|jD]}||r(|j||nqtdqdS)a)Create the path object from a string. :param text: the path expression :param filename: the name of the file in which the path expression was found (used in error messages) :param lineno: the line on which the expression was found zNo strategy found for pathN) source PathParserparsepaths strategies STRATEGIESr6rJNotImplementedError)rtextfilenamelinenor5strategy_classr#r#r$r; s   z Path.__init__cCs|g}|jD],}g}|D]\}}}|d||f|D] }|dd|7<qq |d|qdt|jd|fS)Nz%s::%srEz[%s]/z <%s "%s">|)rrJjoinrLr&)rrr5rnr`rarbrgr#r#r$__repr__s z Path.__repr__csJ|duri}|dur i}t|}|||ffdd }t|t|dddS)aReturns a substream of the given stream that matches the path. If there are no matches, this method returns an empty stream. >>> from genshi.input import XML >>> xml = XML('Text') >>> print(Path('.//child').select(xml)) Text >>> print(Path('.//child/text()').select(xml)) Text :param stream: the stream to select from :param namespaces: (optional) a mapping of namespace prefixes to URIs :param variables: (optional) a mapping of variable names to values :return: the substream matching the path, or an empty stream :rtype: `Stream` Nc 3sfdd}}D]H}||||}|durP|V|dturOd}|dkrO|}|dtur6|d7}n |dtur@|d8}|V||||dd|dks(q |rU|Vq dS)NcstSr8)nextr#streamr#r$Csz0Path.select.._generate..Trr=rU)rur r ) rnsvs_nextrurRresultrsubeventrrr$ _generateBs.      zPath.select.._generate serializer)r)iterrr)rrrSrTrr#rr$select)s z Path.selectFcs:fdd|jDtdkrdSd fdd }|S) a1Returns a function that can be used to track whether the path matches a specific stream event. The function returned expects the positional arguments ``event``, ``namespaces`` and ``variables``. The first is a stream event, while the latter two are a mapping of namespace prefixes to URIs, and a mapping of variable names to values, respectively. In addition, the function accepts an ``updateonly`` keyword argument that default to ``False``. If it is set to ``True``, the function only updates its internal state, but does not perform any tests or return a result. If the path matches the event, the function returns the match (for example, a `START` or `TEXT` event.) Otherwise, it returns ``None``. >>> from genshi.input import XML >>> xml = XML('') >>> test = Path('child').test() >>> namespaces, variables = {}, {} >>> for event in xml: ... if test(event, namespaces, variables): ... print('%s %r' % (event[0], event[1])) START (QName('child'), Attrs([(QName('id'), '2')])) :param ignore_context: if `True`, the path is interpreted like a pattern in XSLT, meaning for example that it will match at any depth :return: a function that can be used to test individual events in a stream against the path :rtype: ``function`` csg|]}|qSr#)ru)r@r)rsr#r$rCwzPath.test..r=rFcs.d}D]}|||||d}|dur|}q|S)Nrr#)rRrSrTrUrXruval)testsr#r$_multi{szPath.test.._multiNrp)rrG)rrsrr#)rsrr$ruXs  z Path.testNrErrp) r&r'r(r)rrxr1rr;rrrur#r#r#r$rs   /c@seZdZdZdddZdS)rzEException raised when an XPath expression is syntactically incorrect.NrEcCs4|r d|||f}t||||_||_||_dS)Nz%s (%s, line %d)) Exceptionr;rroffset)rmessagerrrr#r#r$r;s   zPathSyntaxError.__init__)NrErE)r&r'r(r)r;r#r#r#r$rsc@seZdZdZdZdZeddddeDdd deDfj Z d0d d Z e ddZ e ddZddZddZddZddZddZd1ddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd S)2rz)Tokenizes and parses an XPath expression.))'r)"r):::...//r[]()()@=!=!r,>=>z<=<$z7("[^"]*")|('[^']*')|((?:\d+)?\.\d+)|(%s)|([^%s\s]+)|\s+rcCsg|]}t|qSr#reescaper@tr#r#r$rCrzPathParser.cCsg|] }t|dqS)rrrr#r#r$rCrDNrEcCs6||_||_dddd||DD|_d|_dS)NcSsg|]}|r|qSr#r#rr#r#r$rCs z'PathParser.__init__..cSs*g|]\}}}}}|p|p|p|p|qSr#r#)r@dqstrsqstrnumbertokenr"r#r#r$rCs r)rr _tokenizetokensrA)rrrrr#r#r$r;s   zPathParser.__init__cCs|jt|jdkSr)rArGrrr#r#r$at_endszPathParser.at_endcCs |j|jSr8)rrArr#r#r$ cur_tokenrzPathParser.cur_tokencCs|jd7_|j|jSr)rArrr#r#r$ next_tokens zPathParser.next_tokencCs|js |j|jdSdSr)rrrArr#r#r$ peek_tokenszPathParser.peek_tokencCsT|g}|jdkr||||jdks |js(td|j|j|j|S)aParses the XPath expression and returns a list of location path tests. For union expressions (such as `*|text()`), this function returns one test for each operand in the union. For patch expressions that don't use the union operator, the function always returns a list of size 1. Each path test in turn is a sequence of tests that correspond to the location steps, each tuples of the form `(axis, testfunc, predicates)` rz+Unexpected token %r after end of expression)_location_pathrrrJrrrr)rrr#r#r$rs  zPathParser.parsecCsg} |jdrJ|s8|jdkr0||\}}}|t||f|js,|jds/ |Sqtd|j|j |jdkrF|tt gf||\}}}|sUt }||||f|jsf|jdsi |Sq)NTrrz%Absolute location paths not supported) r startswithr_location_steprJr-rrrrNodeTestr+)rrnr`rarbr#r#r$rs:   zPathParser._location_pathcCs|jdkr t}|n:|jdkrt}n2|jdkr!td|j|j|dkrDt |j}|dur;td||j|j||nd}| |pKt }g}|jdkr`| | |jdksT|||fS)NrrrzUnsupported axis "parent"rzUnsupport axis "%s"r)rr*rr.rrrrrr% _node_testr+rJ _predicate)rr`rarbr#r#r$rs0         zPathParser._location_stepcCsd}}|}|dvr|}n9|dkr1|j}||}|dkr*t||}n t|||}n|jdkr;t|}n|jdkrDt}nt||j}|j sQ||S)N)rrr*r) r _node_typerrQualifiedPrincipalTypeTestQualifiedNameTestPrincipalTypeTestrryr)rr`ruprefixr localnamer#r#r$rs&      zPathParser._node_testcCs|j}|g}|jdkr0||jdkr0|j}|d|df|jvr+|dd}||t|}|sAtd||j|j||S)NrrrrEr=z%s() not allowed here) rr_QUOTESrJ _nodetest_mapgetrrr)rr"argsstringr!r#r#r$rs       zPathParser._node_typecCsP|jdksJ||}|jdkrtd|j|j|j|js&||S)Nrrz/Expected "]" to close predicate, but found "%s")rr_or_exprrrrrrexprr#r#r$r3s zPathParser._predicatecC6|}|jdkr|t||}|jdks |S)Nor) _and_exprrr OrOperatorrr#r#r$r?   zPathParser._or_exprcCr)Nand)_equality_exprrr AndOperatorrr#r#r$rFrzPathParser._and_exprcC@|}|jdvrt|j}||||}|jdvs |S)N)rr)_relational_exprr _operator_maprrropr#r#r$rM   zPathParser._equality_exprcCr)N)rrrr) _sub_exprrrrr r#r#r$rUr zPathParser._relational_exprcCsR|j}|dkr |S||}|jdkr#td|j|j|j||S)Nrrz4Expected ")" to close sub-expression, but found "%s")r _primary_exprrrrrr)rrrr#r#r$r ]s zPathParser._sub_exprcCs|j}t|dkr |d|df|jvr |t|ddS|ds,|ddkr6|tt|S|dkrF|}|t|S|j sT| drT| Sd}|dkr`t }|||S)Nr=rrErrrr)rrGrr StringLiteralisdigit NumberLiteralas_floatVariableReferencerrr_function_callr*r)rrr`r#r#r$r js$"  zPathParser._primary_exprcCs|j}|dkr g}n5|jdksJ||g}|jdkr1||||jdks!|jdksAtd|j|j|j|t|}|sVtd||j|j||S)Nrrrrz.r)r rrr r'r*r r(r#r0r$r)s z#QualifiedPrincipalTypeTest.__call__cC d|jS)Nz%s:*)rrr#r#r$rr<z#QualifiedPrincipalTypeTest.__repr__Nr+r#r#r#r$rs  rc@r-) ryzWNode test that matches any event with the given principal type and local name. r'r"cCr.r8)r'r")rr'r"r#r#r$r;r/zLocalNameTest.__init__cCsP|tur&|jtur|j|dvrt|j|d|jfgS|dj|jkSdS)Nr=r)r r'r*r"r rrr(r#r#r$r)s zLocalNameTest.__call__cC|jSr8r"rr#r#r$rzLocalNameTest.__repr__Nr+r#r#r#r$rys  ryc@0eZdZdZgdZddZddZddZd S) rz[Node test that matches any event with the given principal type and qualified name. r'rr"cC||_||_||_dSr8r7)rr'rr"r#r#r$r; zQualifiedNameTest.__init__cCs`td||j|jf}|tur.|jtur(||dvr(t||d|fgS|d|kSdS)Nz%s}%sr=r)r rrr"r r'r*r )rrVrWrArSrTqnamer#r#r$r)s  zQualifiedNameTest.__call__cCd|j|jfS)Nz%s:%s)rr"rr#r#r$rzQualifiedNameTest.__repr__Nr+r#r#r#r$r  rc@$eZdZdZgZddZddZdS)rzz*Node test that matches any comment events.cC|tuSr8)rr(r#r#r$r)zCommentNodeTest.__call__cCr2)Nz comment()r#rr#r#r$rr*zCommentNodeTest.__repr__Nr&r'r(r)r,r)rr#r#r#r$rz  rzc@r>)rz Node test that matches any node.cCs|turdS|||fSr3r r(r#r#r$r)s zNodeTest.__call__cCr2)Nznode()r#rr#r#r$r r*zNodeTest.__repr__NrAr#r#r#r$rs  rc@s0eZdZdZdgZd ddZddZdd ZdS) ProcessingInstructionNodeTestz8Node test that matches any processing instruction event.targetNcCr7r8rE)rrEr#r#r$r;r<z&ProcessingInstructionNodeTest.__init__cCs|tuo|j p|d|jkSNr)rrEr(r#r#r$r)sz&ProcessingInstructionNodeTest.__call__cCs d}|jr d|jd}d|S)Nrrzprocessing-instruction(%s)rF)rargr#r#r$rsz&ProcessingInstructionNodeTest.__repr__r8r+r#r#r#r$rD s   rDc@r>)r{z&Node test that matches any text event.cCr?r8)rr(r#r#r$r)r@zTextNodeTest.__call__cCr2)Nztext()r#rr#r#r$rr*zTextNodeTest.__repr__NrAr#r#r#r$r{rBr{)commentnodezprocessing-instructionrc@eZdZdZdS)Functionz3Base class for function nodes in XPath expressions.Nr&r'r(r)r#r#r#r$rL'rLc@s2eZdZdZdgZeZddZddZddZ d S) BooleanFunctionzPThe `boolean` function, which converts its argument to a boolean value. rcCr7r8rrr#r#r$r;0r<zBooleanFunction.__init__cC||||||}t|Sr8)rr$rrVrWrArSrTrr#r#r$r)2zBooleanFunction.__call__cCr2)Nz boolean(%r)rPrr#r#r$r5r<zBooleanFunction.__repr__N) r&r'r(r)r,r# _return_typer;r)rr#r#r#r$rO*s rOc@r&) CeilingFunctionzeThe `ceiling` function, which returns the nearest lower integer number for the given number. rcCr7r8rrrr#r#r$r;=r<zCeilingFunction.__init__cC||||||}tt|Sr8)rrrrrVrWrArSrTrr#r#r$r)? zCeilingFunction.__call__cCr2)Nz ceiling(%r)rVrr#r#r$rBr<zCeilingFunction.__repr__Nr+r#r#r#r$rU8  rUc@r&) ConcatFunctionzoThe `concat` function, which concatenates (joins) the variable number of strings it gets as arguments. exprscGr7r8)r])rr]r#r#r$r;Jr<zConcatFunction.__init__cs>g}fdd|jDD] }|t|qd|S)Ncsg|] }|qSr#r#r@rrWrVrSrArTr#r$rCNsz+ConcatFunction.__call__..r)r]rJr"r)rrVrWrArSrTstringsitemr#r_r$r)Ls   zConcatFunction.__call__cCsdddd|jDS)Nz concat(%s)z, cSg|]}t|qSr#)reprr^r#r#r$rCSz+ConcatFunction.__repr__..)rr]rr#r#r$rRszConcatFunction.__repr__Nr+r#r#r#r$r\Es  r\c@r-) ContainsFunctionz\The `contains` function, which returns whether a string contains a given substring. string1string2cCr.r8rfrgrrfrgr#r#r$r;Zr/zContainsFunction.__init__cCs4||||||}||||||}t|t|vSr8)rfrgr"rrVrWrArSrTrfrgr#r#r$r)]zContainsFunction.__call__cCr;Nzcontains(%r, %r)rhrr#r#r$rar<zContainsFunction.__repr__Nr+r#r#r#r$reU  rec@sPeZdZdZddgZejejejej dZ dddZ dd Z d d Z d d ZdS)MatchesFunctionz]The `matches` function, which returns whether a string matches a regular expression. rfrg)rmrir]rcCs||_||_|||_dSr8)rfrg _map_flagsflags)rrfrgrqr#r#r$r;kszMatchesFunction.__init__cCs<t||||||}t||||||}t|||jSr8)r"rfrgrsearchrqrjr#r#r$r)oszMatchesFunction.__call__csttjfdd|DtjS)Ncsg|]}j|qSr#)flag_map)r@flagrr#r$rCurz.MatchesFunction._map_flags..)roperatoror_rU)rrqr#rr$rpsszMatchesFunction._map_flagscCr;rlrhrr#r#r$rvr<zMatchesFunction.__repr__N)r)r&r'r(r)r,rSMIX flag_mappingr;r)rprr#r#r#r$rnds  rnc@r>) FalseFunctionzEThe `false` function, which always returns the boolean `false` value.cCr2NFr#r(r#r#r$r)|r*zFalseFunction.__call__cCr2)Nzfalse()r#rr#r#r$r~r*zFalseFunction.__repr__NrAr#r#r#r$r}yrBr}c@r&) FloorFunctionzfThe `ceiling` function, which returns the nearest higher integer number for the given number. rcCr7r8rVrWr#r#r$r;r<zFloorFunction.__init__cCrXr8)rrrrYr#r#r$r)rZzFloorFunction.__call__cCr2)Nz floor(%r)rVrr#r#r$rr<zFloorFunction.__repr__Nr+r#r#r#r$rr[rc@r>)LocalNameFunctionzXThe `local-name` function, which returns the local name of the current element. cC|tur |djSdSrG)r rr(r#r#r$r) zLocalNameFunction.__call__cCr2)Nz local-name()r#rr#r#r$rr*zLocalNameFunction.__repr__NrAr#r#r#r$r  rc@r>) NameFunctionzVThe `name` function, which returns the qualified name of the current element. cCs|tur|dSdSrGrCr(r#r#r$r)szNameFunction.__call__cCr2)Nzname()r#rr#r#r$rr*zNameFunction.__repr__NrAr#r#r#r$rrrc@r>)NamespaceUriFunctionz^The `namespace-uri` function, which returns the namespace URI of the current element. cCrrG)r r1r(r#r#r$r)rzNamespaceUriFunction.__call__cCr2)Nznamespace-uri()r#rr#r#r$rr*zNamespaceUriFunction.__repr__NrAr#r#r#r$rrrc@r&) NotFunctionzUThe `not` function, which returns the negated boolean value of its argument. rcCr7r8rPrr#r#r$r;r<zNotFunction.__init__cCst|||||| Sr8)r$rr(r#r#r$r)szNotFunction.__call__cCr2)Nznot(%s)rPrr#r#r$rr<zNotFunction.__repr__Nr+r#r#r#r$rs  rc@s:eZdZdZdgZedjZddZ ddZ dd Z d S) NormalizeSpaceFunctionzThe `normalize-space` function, which removes leading and trailing whitespace in the given string, and replaces multiple adjacent whitespace characters inside the string with a single space. rz\s{2,}cCr7r8rPrr#r#r$r;r<zNormalizeSpaceFunction.__init__cCs&||||||}|dt|S)N )r _normalizer"striprrVrWrArSrTrr#r#r$r)szNormalizeSpaceFunction.__call__cCsdt|jS)Nznormalize-space(%s))rcrrr#r#r$rszNormalizeSpaceFunction.__repr__N) r&r'r(r)r,rrsubrr;r)rr#r#r#r$rs  rc@r&) NumberFunctionz=The `number` function that converts its argument to a number.rcCr7r8rPrr#r#r$r;r<zNumberFunction.__init__cCrQr8)rrrRr#r#r$r)rSzNumberFunction.__call__cCr2)Nz number(%r)rPrr#r#r$rr<zNumberFunction.__repr__Nr+r#r#r#r$rs  rc@r&) RoundFunctionz]The `round` function, which returns the nearest integer number for the given number. rcCr7r8rVrWr#r#r$r;r<zRoundFunction.__init__cCrXr8)rroundrrYr#r#r$r)rZzRoundFunction.__call__cCr2)Nz round(%r)rVrr#r#r$rr<zRoundFunction.__repr__Nr+r#r#r#r$rr[rc@r-) StartsWithFunctionzbThe `starts-with` function that returns whether one string starts with a given substring. rfrgcCr.r8rhrir#r#r$r;r/zStartsWithFunction.__init__cCs6||||||}||||||}t|t|Sr8)rfrgr"rrjr#r#r$r)szStartsWithFunction.__call__cCr;)Nzstarts-with(%r, %r)rhrr#r#r$rr<zStartsWithFunction.__repr__Nr+r#r#r#r$rrmrc@r&) StringLengthFunctionzRThe `string-length` function that returns the length of the given string. rcCr7r8rPrr#r#r$r;r<zStringLengthFunction.__init__cCrXr8)rrGr"rr#r#r$r)rZzStringLengthFunction.__call__cCr2)Nzstring-length(%r)rPrr#r#r$rr<zStringLengthFunction.__repr__Nr+r#r#r#r$rr[rc@s2eZdZdZgdZd ddZddZdd ZdS) SubstringFunctionzThe `substring` function that returns the part of a string that starts at the given offset, and optionally limited to the given length. rstartlengthNcCr8r8r)rrrrr#r#r$r;r9zSubstringFunction.__init__c Csd||||||}||||||}d}|jdur"||||||}|t|tt|t|SrG)rrrrrGr") rrVrWrArSrTrrrr#r#r$r)s   zSubstringFunction.__call__cCs.|jdurd|j|j|jfSd|j|jfS)Nzsubstring(%r, %r, %r)zsubstring(%r, %r))rrrrr#r#r$rs  zSubstringFunction.__repr__r8r+r#r#r#r$rs   rc@r-) SubstringAfterFunctionzrThe `substring-after` function that returns the part of a string that is found after the given substring. rfrgcCr.r8rhrir#r#r$r;r/zSubstringAfterFunction.__init__c CsVt||||||}t||||||}||}|dkr)||t|dSdSNrr)r"rfrgfindrG rrVrWrArSrTrfrgindexr#r#r$r)s  zSubstringAfterFunction.__call__cCr;Nzsubstring-after(%r, %r)rhrr#r#r$r$r<zSubstringAfterFunction.__repr__Nr+r#r#r#r$r  rc@r-) SubstringBeforeFunctionztThe `substring-before` function that returns the part of a string that is found before the given substring. rfrgcCr.r8rhrir#r#r$r;,r/z SubstringBeforeFunction.__init__c CsNt||||||}t||||||}||}|dkr%|d|SdSr)r"rfrgrrr#r#r$r)/s   z SubstringBeforeFunction.__call__cCr;rrhrr#r#r$r6r<z SubstringBeforeFunction.__repr__Nr+r#r#r#r$r'rrc@r6) TranslateFunctionznThe `translate` function that translates a set of characters in a string to target set of characters. r fromcharstocharscCr8r8r)rrrrr#r#r$r;>r9zTranslateFunction.__init__c Csnt||||||}t||||||}t||||||}ttdd|Ddd|D} || S)NcSrbr#ordr@cr#r#r$rCFrdz.TranslateFunction.__call__..cSrbr#rrr#r#r$rCGrd)r"rrrdictzip translate) rrVrWrArSrTrrrtabler#r#r$r)Bs  zTranslateFunction.__call__cCsd|j|j|jfS)Nztranslate(%r, %r, %r)rrr#r#r$rIs zTranslateFunction.__repr__Nr+r#r#r#r$r9r=rc@r>) TrueFunctionzCThe `true` function, which always returns the boolean `true` value.cCr2r3r#r(r#r#r$r)Pr*zTrueFunction.__call__cCr2)Nztrue()r#rr#r#r$rRr*zTrueFunction.__repr__NrAr#r#r#r$rMrBrbooleanceilingconcatcontainsmatchesfalserz local-namer"z namespace-uriznormalize-spacenotrrz starts-withz string-length substring)zsubstring-afterzsubstring-beforertruec@rK)Literalz&Abstract base class for literal nodes.NrMr#r#r#r$rdrNrc@r&) rzA string literal node.rcCr7r8r)rrr#r#r$r;jr<zStringLiteral.__init__cCr3r8rr(r#r#r$r)lr5zStringLiteral.__call__cCr2)Nz"%s"rrr#r#r$rnr<zStringLiteral.__repr__Nr+r#r#r#r$rg  rc@r&) rzA number literal node.rcCr7r8rVrWr#r#r$r;tr<zNumberLiteral.__init__cCr3r8rVr(r#r#r$r)vr5zNumberLiteral.__call__cC t|jSr8)strrrr#r#r$rxr<zNumberLiteral.__repr__Nr+r#r#r#r$rqrrc@r&) rzA variable reference node.r"cCr7r8r4)rr"r#r#r$r;~r<zVariableReference.__init__cCs ||jSr8)rr"r(r#r#r$r)r%zVariableReference.__call__cCrr8)rr"rr#r#r$rr<zVariableReference.__repr__Nr+r#r#r#r$r{rrc@r-) rzThe boolean operator `and`.lvalrvalcCr.r8rrrrrr#r#r$r;r/zAndOperator.__init__cCs8t||||||}|sdS||||||}t|Sr~r$rrrrVrWrArSrTrrr#r#r$r) zAndOperator.__call__cCr;)Nz %s and %srrr#r#r$rr<zAndOperator.__repr__Nr+r#r#r#r$r  rc@r-) EqualsOperatorzThe equality operator `=`.rrcCr.r8rrr#r#r$r;r/zEqualsOperator.__init__cCs4t||||||}t||||||}||kSr8rrrrr#r#r$r)zEqualsOperator.__call__cCr;)Nz%s=%srrr#r#r$rr<zEqualsOperator.__repr__Nr+r#r#r#r$r  rc@r-) NotEqualsOperatorzThe equality operator `!=`.rrcCr.r8rrr#r#r$r;r/zNotEqualsOperator.__init__cCs4t||||||}t||||||}||kSr8rrr#r#r$r)rzNotEqualsOperator.__call__cCr;)Nz%s!=%srrr#r#r$rr<zNotEqualsOperator.__repr__Nr+r#r#r#r$rrrc@r-) rzThe boolean operator `or`.rrcCr.r8rrr#r#r$r;r/zOrOperator.__init__cCs8t||||||}|rdS||||||}t|Sr3rrr#r#r$r)rzOrOperator.__call__cCr;)Nz%s or %srrr#r#r$rr<zOrOperator.__repr__Nr+r#r#r#r$rrrc@r-) GreaterThanOperatorz+The relational operator `>` (greater than).rrcCr.r8rrr#r#r$r;r/zGreaterThanOperator.__init__cCs4||||||}||||||}t|t|kSr8rrrrr#r#r$r)rkzGreaterThanOperator.__call__cCr;)Nz%s>%srrr#r#r$rr<zGreaterThanOperator.__repr__Nr+r#r#r#r$rrrc@r-) GreaterThanOrEqualOperatorz5The relational operator `>=` (greater than or equal).rrcCr.r8rrr#r#r$r;r/z#GreaterThanOrEqualOperator.__init__cCs4||||||}||||||}t|t|kSr8rrr#r#r$r)rkz#GreaterThanOrEqualOperator.__call__cCr;)Nz%s>=%srrr#r#r$rr<z#GreaterThanOrEqualOperator.__repr__Nr+r#r#r#r$rrrc@r-) LessThanOperatorz(The relational operator `<` (less than).rrcCr.r8rrr#r#r$r;r/zLessThanOperator.__init__cCs4||||||}||||||}t|t|kSr8rrr#r#r$r)rkzLessThanOperator.__call__cCr;)Nz%s<%srrr#r#r$rr<zLessThanOperator.__repr__Nr+r#r#r#r$rrrc@r-) LessThanOrEqualOperatorz2The relational operator `<=` (less than or equal).rrcCr.r8rrr#r#r$r;r/z LessThanOrEqualOperator.__init__cCs4||||||}||||||}t|t|kSr8rrr#r#r$r)rkz LessThanOrEqualOperator.__call__cCr;)Nz%s<=%srrr#r#r$rr<z LessThanOrEqualOperator.__repr__Nr+r#r#r#r$rrr)rrrrrrr#)ar) collectionsr functoolsrmathrrrur itertoolsrr  genshi.compatr genshi.corerr r r r r rrrrrrr__all__ __docformat__objectrr*r+r,r-r.r1rxrrrrrrrrr"r$rrryrrzrrDr{rrLrOrUr\rernr}rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrqrrr#r#r#r$s    ,PF