ó {fc@s©dZddlZddlmZmZmZddlZd„Zddd„ƒYZd„Z d„Z d „Z e d kr¥ddl Z e jd d d deƒ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((s,/usr/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((s,/usr/lib64/python2.7/idlelib/SearchEngine.pyt__init__s cCs |jjƒS(N(R R(R((s,/usr/lib64/python2.7/idlelib/SearchEngine.pytgetpat#scCs|jj|ƒdS(N(R tset(Rtpat((s,/usr/lib64/python2.7/idlelib/SearchEngine.pytsetpat&scCs |jjƒS(N(R R(R((s,/usr/lib64/python2.7/idlelib/SearchEngine.pytisre)scCs |jjƒS(N(R R(R((s,/usr/lib64/python2.7/idlelib/SearchEngine.pytiscase,scCs |jjƒS(N(R R(R((s,/usr/lib64/python2.7/idlelib/SearchEngine.pytisword/scCs |jjƒS(N(RR(R((s,/usr/lib64/python2.7/idlelib/SearchEngine.pytiswrap2scCs |jjƒS(N(RR(R((s,/usr/lib64/python2.7/idlelib/SearchEngine.pytisback5scCs/|jƒrtj|ƒ}n|j|ƒdS(s!Set pattern after escaping if re.N(RtretescapeR(RR((s,/usr/lib64/python2.7/idlelib/SearchEngine.pyt setcookedpat:s cCsG|jƒ}|jƒs*tj|ƒ}n|jƒrCd|}n|S(Ns\b%s\b(RRRRR(RR((s,/usr/lib64/python2.7/idlelib/SearchEngine.pyt getcookedpatAs     cCsÐ|jƒ}|s&|j|dƒdS|jƒ}d}|jƒsT|tjB}nytj||ƒ}Wn_tjk rË}|j }|d}t |ƒdkr®|dnd}|j|||ƒdSX|S(s&Return compiled cooked search pattern.sEmpty regular expressioniiiiÿÿÿÿN( Rt report_errortNoneRRRt IGNORECASEtcompileterrortargstlen(RRtflagstprogtwhatR%tmsgtcol((s,/usr/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(tstrt tkMessageBoxt showerrorR(RRR*R+((s,/usr/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 parameter is 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((s,/usr/lib64/python2.7/idlelib/SearchEngine.pyt search_textgs$   ! 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!( RR5R(R;R+R7R6twrappedt startlinetcharstm((s,/usr/lib64/python2.7/idlelib/SearchEngine.pyR4s(    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-WdS(Nis%d.0iiÿÿÿÿsend-1ct.( Rtsearch_reverseR:tindextmaptinttsplitR&R!( RR5R(R;R+R7R6R@RARBRCtpos((s,/usr/lib64/python2.7/idlelib/SearchEngine.pyR3¥s,   !N(t__name__t __module__t__doc__RRRRRRRRRRR,R R!R=R4R3(((s,/usr/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 \n. Col: stop index for the search; the limit for match.end(). iN(R>R!tspan(R(RBR+RCtfoundtitj((s,/usr/lib64/python2.7/idlelib/SearchEngine.pyRE½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(RFRR!(R5R8R9((s,/usr/lib64/python2.7/idlelib/SearchEngine.pyR1Ôs  cCs(tt|jdƒƒ\}}||fS(s8Return (line, col) tuple of ints from 'line.col' string.RD(RGRHRI(RFR;R+((s,/usr/lib64/python2.7/idlelib/SearchEngine.pyR2âst__main__s#idlelib.idle_test.test_searchenginet verbosityitexit((RMRtTkinterRRRR/RRRER1R2RKtunittesttmainR (((s,/usr/lib64/python2.7/idlelib/SearchEngine.pyts   ¬