ó ,§Rc@sÅdZddlZddlmZmZmZddlZd„Zddd„ƒYZd„Z d„Z d „Z e d krÁdd l mZd ge_ddlZejd dddeƒndS(s'Define SearchEngine for search dialogs.iÿÿÿÿN(t StringVart BooleanVartTclErrorcCs(t|dƒs!t|ƒ|_n|jS(s¼Return the singleton SearchEngine instance for the process. The single SearchEngine saves settings between dialog instances. If there is not a SearchEngine already, make one. t _searchengine(thasattrt SearchEngineR(troot((s5/opt/freeware/lib64/python2.7/idlelib/SearchEngine.pytgetsRcBs¤eZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z d d „Zddd„Zdd„Zdd„ZRS(s<Handles searching a text widget for Find, Replace, and Grep.cCsy||_t|dƒ|_t|tƒ|_t|tƒ|_t|tƒ|_t|tƒ|_ t|tƒ|_ dS(s€Initialize Variables that save search state. The dialogs bind these to the UI elements present in the dialogs. tN( RRtpatvarRtFalsetrevartcasevartwordvartTruetwrapvartbackvar(tselfR((s5/opt/freeware/lib64/python2.7/idlelib/SearchEngine.pyt__init__s cCs |jjƒS(N(R R(R((s5/opt/freeware/lib64/python2.7/idlelib/SearchEngine.pytgetpat#scCs|jj|ƒdS(N(R tset(Rtpat((s5/opt/freeware/lib64/python2.7/idlelib/SearchEngine.pytsetpat&scCs |jjƒS(N(R R(R((s5/opt/freeware/lib64/python2.7/idlelib/SearchEngine.pytisre)scCs |jjƒS(N(R R(R((s5/opt/freeware/lib64/python2.7/idlelib/SearchEngine.pytiscase,scCs |jjƒS(N(R R(R((s5/opt/freeware/lib64/python2.7/idlelib/SearchEngine.pytisword/scCs |jjƒS(N(RR(R((s5/opt/freeware/lib64/python2.7/idlelib/SearchEngine.pytiswrap2scCs |jjƒS(N(RR(R((s5/opt/freeware/lib64/python2.7/idlelib/SearchEngine.pytisback5scCs/|jƒrtj|ƒ}n|j|ƒdS(s!Set pattern after escaping if re.N(RtretescapeR(RR((s5/opt/freeware/lib64/python2.7/idlelib/SearchEngine.pyt setcookedpat:s cCsG|jƒ}|jƒs*tj|ƒ}n|jƒrCd|}n|S(Ns\b%s\b(RRRRR(RR((s5/opt/freeware/lib64/python2.7/idlelib/SearchEngine.pyt getcookedpatAs     cCsÇ|jƒ}|s&|j|dƒdS|jƒ}d}|jƒsT|tjB}nytj||ƒ}WnVtjk rÂ}y|\}}Wnt |ƒ}d}nX|j|||ƒdSX|S(s&Return compiled cooked search pattern.sEmpty regular expressioniiÿÿÿÿN( Rt report_errortNoneRRRt IGNORECASEtcompileterrortstr(RRtflagstprogtwhattmsgtcol((s5/opt/freeware/lib64/python2.7/idlelib/SearchEngine.pytgetprogIs&     iÿÿÿÿcCsmdt|ƒ}|r-|dt|ƒ}n|dkrP|dt|ƒ}ntjd|d|jƒdS(NsError: s Pattern: is Offset: sRegular expression errortmaster(R%t tkMessageBoxt showerrorR(RRR)R*((s5/opt/freeware/lib64/python2.7/idlelib/SearchEngine.pyR _s  ic CsÝ|s|jƒ}|sdSn|jjƒ}t|ƒ\}}|jƒr”|r[|}n|}t|ƒ\}} |j|||| ||ƒ} nE|r£|}n|}t|ƒ\}} |j|||| ||ƒ} | S(sµReturn (lineno, matchobj) or None for forward/backward search. This function calls the right function with the right arguments. It directly return the result of that call. Text is a text widget. Prog is a precompiled pattern. The ok parameteris a bit complicated as it has two effects. If there is a selection, the search begin at either end, depending on the direction setting and ok, with ok meaning that the search starts with the selection. Otherwise, search begins at the insert mark. To aid progress, the search functions do not return an empty match at the starting position unless ok is True. N( R+R!RRt get_selectionRt get_line_coltsearch_backwardtsearch_forward( RttextR'toktwraptfirsttlasttstarttlineR*tres((s5/opt/freeware/lib64/python2.7/idlelib/SearchEngine.pyt search_textis$   ! c Csúd}|}|jd|d|dƒ} xÉ| rõ|j| d |ƒ} | rt|sg| jƒ|krt|| fSn|d}|r”||kr”Pnd}d}|jd|d|dƒ} | r-|r-d}d}d}|jddƒ} q-q-WdS(Nis%d.0iiÿÿÿÿs1.0s2.0(RtsearchtendR!( RR3R'R9R*R5R4twrappedt startlinetcharstm((s5/opt/freeware/lib64/python2.7/idlelib/SearchEngine.pyR2‘s(    c Csd}|}|jd|d|dƒ} xêt|| d |ƒ} | rn|sa| jƒ|krn|| fSn|d}|rŽ||krŽPnd}|dkræ|sªPnd}d}|jdƒ} tt| jdƒƒ\}}n|jd|d|dƒ} t| ƒd}q-dS(Nis%d.0iiÿÿÿÿsend-1ct.( Rtsearch_reverseR8tindextmaptinttsplittlenR!( RR3R'R9R*R5R4R>R?R@RAtpos((s5/opt/freeware/lib64/python2.7/idlelib/SearchEngine.pyR1§s,   !N(t__name__t __module__t__doc__RRRRRRRRRRR+R R!R;R2R1(((s5/opt/freeware/lib64/python2.7/idlelib/SearchEngine.pyRs             ( cCs¡|j|ƒ}|sdSd}|jƒ\}}xi||krœ||krœ|}||krk|d}n|j||ƒ}|s‡Pn|jƒ\}}q4W|S(s%Search backwards and return an re match object or None. This is done by searching forwards until there is no match. Prog: compiled re object with a search method returning a match. Chars: line of text, without . Col: stop index for the search; the limit for match.end(). iN(R<R!tspan(R'R@R*RAtfoundtitj((s5/opt/freeware/lib64/python2.7/idlelib/SearchEngine.pyRC¿s  cCsqy"|jdƒ}|jdƒ}Wntk r?d}}nX|sX|jdƒ}n|sg|}n||fS(sFReturn tuple of 'line.col' indexes from selection or insert mark. s sel.firstssel.lasttinsertN(RDRR!(R3R6R7((s5/opt/freeware/lib64/python2.7/idlelib/SearchEngine.pyR/Ös  cCs(tt|jdƒƒ\}}||fS(s8Return (line, col) tuple of ints from 'line.col' string.RB(RERFRG(RDR9R*((s5/opt/freeware/lib64/python2.7/idlelib/SearchEngine.pyR0äst__main__(tsupporttguis#idlelib.idle_test.test_searchenginet verbosityitexit((RLRtTkinterRRRR-RRRCR/R0RJttestRSt use_resourcestunittesttmainR (((s5/opt/freeware/lib64/python2.7/idlelib/SearchEngine.pyts   ®