z>c@sdZddlZddlZddlmZmZddlmZddlmZddlm Z m Z ddlm Z m Z ddlm Z dd lmZmZdd lmZdd lmZed Zd dGdYZddlZyejejgZWnejgZnXdZdZdZdZddZddZ ddZ!ddZ"dZ#dZ$dZ%dZ&dZ'ddZ(ddZ)ddZ*dZ+d Z,d!Z-d"Z.d#Z/d$Z0dd%Z1d&Z2d'Z3d(Z4d)Z5d*Z6ieed+f6eed,f6eed-f6eed.f6eed/f6e ed0f6e!ed1f6e"ed2f6e#ed3f6e$ed4f6e%ed5f6e&ed6f6e'ed7f6e(ed8f6e)ed9f6e*ed:f6e+ed;f6e,ed<f6e-ed=f6e.ed>f6e/ed?f6e0ed@f6e1edAf6e2edBf6e3edCf6e4edDf6e5edEf6e6edFf6Z7iejejejgfe(6Z8dS(Hs The implementation of all of the core functions for the XPath spec. WWW: http://4suite.org/XPATH e-mail: support@4suite.org Copyright (c) 2000-2001 Fourthought Inc, USA. All Rights Reserved. See http://4suite.org/COPYRIGHT for license and copyright information iN(tNodetEMPTY_NAMESPACE(tExpandedNameWrapper(t NamespaceNode(tNaNtInf(tUtilt Conversions(tNAMESPACE_NODE(tCompiletimeExceptiontRuntimeException(tboolean(tget_translatortxpathtTypescBs&eZdZdZdZdZdZRS(iiiii(t__name__t __module__t NumberTypet StringTypet BooleanTypet NodeSetTypet ObjectType(((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pyRs cCs|jS(sFunction: last()(tsize(tcontext((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pytLast-scCs|jS(sFunction: position()(tposition(R((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pytPosition2scCs@t|tgkr6ttjdtdnt|S(s$Function: count()tcountsexpected node set argument(ttypeR tWRONG_ARGUMENTSt_tlen(RtnodeSet((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pytCount7sc Csg}t|tgkr?tj|}tj|}n'x$|D]}|jtj|qFWg}x|D]z}|jjp|j}tj |j |}t |dkrt t j dtdqs|rs|j|dqsqsW|S(s!Function: id()itidsargument not uniquei(RRt StringValuetstringtsplittappendtnodet ownerDocumentRt ElementsByIdtdocumentElementRR RR( Rtobjecttid_listtsttntrtR"tdoctelements((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pytId>s  cCs|dkr|j}n}t|tgkrNttjdtdntj|}t|tgkst|dkrdS|d}t |}|dks|j dkrdS|j S(s*Function: local-name(?)s local-namesexpected node setitN( tNoneR'RR RRRt SortDocOrderRt ExpandedNamet localName(RR R'ten((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pyt LocalNameSs  *  cCs|dkr|j}n}t|tgkrNttjdtdntj|}t|tgkst|dkrdS|d}t |}|dks|j dkrdS|j S(s-Function: namespace-uri(?)s namespace-urisexpected node setiR3N( R4R'RR RRRR5RR6t namespaceURI(RR R'R8((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pyt NamespaceUrids  *  cCs|dkr|j}n}t|tgkrNttjdtdntj|}t|tgkst|dkrdS|d}t |}|dkrdS|j S(s$Function: name(?)tnamesexpected node setiR3N( R4R'RR RRRR5RR6tqName(RR R'R8((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pytNameus  *   cCs>t|tkr|S|dkr1|jg}ntj|S(s$Function: string(?)N(Rt g_stringTypesR4R'RR#(RR+((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pytStrings  cGsFt|dkr0ttjdtdnt|d|dS(s2Function: concat(, , ...)itconcatsat least 2 arguments expectedcSs|tj|S(N(RR#(tatbtc((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pytsR3(RR RRtreduce(Rtargs((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pytConcats cCsDtj|}tj|}|t| |kr=tjpCtjS(s2Function: starts-with(, )(RR#RR ttruetfalse(Rtoutertinner((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pyt StartsWithscCsxtj|}tj|}t|dkrL||krEtjpKtjStj||dkrmtjpstjSdS(s/Function: contains(, )iiN(RR#RR RIRJR$tfind(RRKRL((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pytContainss cCsHtj|}tj|}tj||}|dkr@dS|| S(s7Function: substring-before(, )iR3(RR#R$RN(RRKRLtindex((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pytSubstringBefores  cCsRtj|}tj|}tj||}|dkr@dS||t|S(s6Function: substring-after(, )iR3(RR#R$RNR(RRKRLRP((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pytSubstringAfters  cCstj|}tj|}|tkr.dStt|}|dkrV|dpYd}|dkrp||Stj|}|tkr||Stt|}||||!S(s;Function: substring(, , ?)R3iiN(RR#t NumberValueRtinttroundR4(RR-tstarttend((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pyt Substrings   cCs+|dkr|j}nttj|S(s+Function: string-length(?)N(R4R'RRR#(RR-((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pyt StringLengths  cCs=|dkr|j}ntj|}tjtj|S(s-Function: normalize-space(?)N(R4R'RR#R$tjoinR%(RR-((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pyt Normalizes  cCstj|}tj|}tj|}i}x0td||D]\}}||t| translate(, , )cSs ||jt||pdS(NR3(tgettord(RBRCtt((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pyREsR3N(RR#tmapR4R]RF(Rtsourcet fromCharsttoCharst translatet from_chartto_chartresult((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pyt Translates  cCs tj|S(s%Function: boolean()(Rt BooleanValue(RR+((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pyt_BooleanscCs tj| rtjptjS(s"Function: not()(RRhR RIRJ(RR+((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pytNotscCstjS(sFunction: true()(R RI(R((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pytTruescCstjS(sFunction: false()(R RJ(R((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pytFalsescCstjtj|}|j}x|rtd|jj}|rX|djp[d}|rtj |d}|dkr|| }ntj|}||krt j pt j S|jtjkr|jp|j}q$Wt j S(s"Function: lang()cSs|jdko|jS(Nsxml:lang(R<tvalue(tx((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pyRE sit-iN(R$tupperRR#R'tfiltert attributestvaluest nodeValueR4RNR RIRJtnodeTypeRtATTRIBUTE_NODEt ownerElementt parentNode(RtlangR't lang_attrRmRP((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pytLangs    (cCs(|dkr|jg}ntj|S(s$Function: number(?)N(R4R'RRS(RR+((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pytNumbers cCs%td|}td|dS(s"Function: sum()cSs tj|S(N(RRS(Rn((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pyRE!scSs||S(N((Rnty((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pyRE"si(R_RF(RR tnns((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pytSumscCsMtj|}t||kr%|S|dkr?t|dSt|SdS(s"Function: floor()iiN(RRSRT(Rtnumber((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pytFloor%s  cCsMtj|}t||kr%|S|dkr?t|dSt|SdS(s$Function: ceiling()iiN(RRSRT(RR((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pytCeiling2s  cCstj|}t|dS(s"Function: round()i(RRSRU(RR((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pytRound?scCsDt|dr@|jtjtjtjtgkr@tj|SdS(s#Get the expanded name of any objectRuN( thasattrRuRt ELEMENT_NODEtPROCESSING_INSTRUCTION_NODERvRRR4(R'((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pyR6Fs3 tlastRRR"s local-names namespace-uriR<R$RAs starts-withtcontainsssubstring-beforessubstring-aftert substrings string-lengthsnormalize-spaceRcR tnotRIRJRyRtsumtfloortceilingRUs expanded-name((9t__doc__R$t cStringIOtxml.domRRt xml.xpathRRRRRRRR R t xml.utilsR t xml.FtCoreR RRttypesRt UnicodeTypeR?RRR!R2R4R9R;R>R@RHRMRORQRRRXRYR[RgRiRjRkRlR{R|RRRRR6t CoreFunctionstArgs(((sI/opt/freeware/lib/python2.7/site-packages/_xmlplus/xpath/CoreFunctions.pyt s