Plan 9 from Bell Labs’s /usr/web/sources/contrib/stallion/root/sys/lib/python2.7/idlelib/SearchEngine.pyo

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�`^c@s�dZddlZddlmZmZmZddlZd�Zddd��YZd�Z	d�Z
d	�Zed
kr�ddl
Z
e
jdd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*/sys/lib/python2.7/idlelib/SearchEngine.pytgetsRcBs�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�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*/sys/lib/python2.7/idlelib/SearchEngine.pyt__init__s	cCs
|jj�S(N(R	R(R((s*/sys/lib/python2.7/idlelib/SearchEngine.pytgetpat#scCs|jj|�dS(N(R	tset(Rtpat((s*/sys/lib/python2.7/idlelib/SearchEngine.pytsetpat&scCs
|jj�S(N(RR(R((s*/sys/lib/python2.7/idlelib/SearchEngine.pytisre)scCs
|jj�S(N(RR(R((s*/sys/lib/python2.7/idlelib/SearchEngine.pytiscase,scCs
|jj�S(N(R
R(R((s*/sys/lib/python2.7/idlelib/SearchEngine.pytisword/scCs
|jj�S(N(RR(R((s*/sys/lib/python2.7/idlelib/SearchEngine.pytiswrap2scCs
|jj�S(N(RR(R((s*/sys/lib/python2.7/idlelib/SearchEngine.pytisback5scCs/|j�rtj|�}n|j|�dS(s!Set pattern after escaping if re.N(RtretescapeR(RR((s*/sys/lib/python2.7/idlelib/SearchEngine.pytsetcookedpat:scCsG|j�}|j�s*tj|�}n|j�rCd|}n|S(Ns\b%s\b(RRRRR(RR((s*/sys/lib/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�tdnd}|j|||�dSX|S(s&Return compiled cooked search pattern.sEmpty regular expressioniiii�N(Rtreport_errortNoneRRRt
IGNORECASEtcompileterrortargstlentarg(RRtflagstprogtwhatR%tmsgtcol((s*/sys/lib/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*/sys/lib/python2.7/idlelib/SearchEngine.pyR ]s	icCs�|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((s*/sys/lib/python2.7/idlelib/SearchEngine.pytsearch_textgs$	!	cCs�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!(RR6R)R<R,R8R7twrappedt	startlinetcharstm((s*/sys/lib/python2.7/idlelib/SearchEngine.pyR5�s(	


cCsd}|}|jd|d|d�}	x�||	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_reverseR;tindextmaptinttsplitR&R!(RR6R)R<R,R8R7RARBRCRDtpos((s*/sys/lib/python2.7/idlelib/SearchEngine.pyR4�s,

!N(t__name__t
__module__t__doc__RRRRRRRRRRR-R R!R>R5R4(((s*/sys/lib/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)RCR,RDtfoundtitj((s*/sys/lib/python2.7/idlelib/SearchEngine.pyRF�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(RGRR!(R6R9R:((s*/sys/lib/python2.7/idlelib/SearchEngine.pyR2�s
	cCs(tt|jd��\}}||fS(s8Return (line, col) tuple of ints from 'line.col' string.RE(RHRIRJ(RGR<R,((s*/sys/lib/python2.7/idlelib/SearchEngine.pyR3�st__main__s#idlelib.idle_test.test_searchenginet	verbosityitexit((RNRtTkinterRRRR0RRRFR2R3RLtunittesttmainR
(((s*/sys/lib/python2.7/idlelib/SearchEngine.pyt<module>s	�		

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.