/
opt
/
alt
/
python37
/
lib64
/
python3.7
/
idlelib
/
/opt/alt/python37/lib64/python3.7/idlelib
mkdir
upload
Name
Size
Mode
Actions
Icons/
-
0755
rm
idle_test/
-
0755
rm
__pycache__/
-
0755
rm
autocomplete.py
8954
0644
edit
dl
rm
autocomplete_w.py
20109
0644
edit
dl
rm
autoexpand.py
3216
0644
edit
dl
rm
browser.py
8314
0644
edit
dl
rm
calltip.py
6318
0644
edit
dl
rm
calltip_w.py
7158
0644
edit
dl
rm
ChangeLog
56360
0644
edit
dl
rm
codecontext.py
11326
0644
edit
dl
rm
colorizer.py
12992
0644
edit
dl
rm
config-extensions.def
2266
0644
edit
dl
rm
config-highlight.def
2864
0644
edit
dl
rm
config-keys.def
10910
0644
edit
dl
rm
config-main.def
3168
0644
edit
dl
rm
config.py
38173
0644
edit
dl
rm
configdialog.py
104524
0644
edit
dl
rm
config_key.py
14465
0644
edit
dl
rm
CREDITS.txt
1866
0644
edit
dl
rm
debugger.py
19104
0644
edit
dl
rm
debugger_r.py
12140
0644
edit
dl
rm
debugobj.py
4055
0644
edit
dl
rm
debugobj_r.py
1082
0644
edit
dl
rm
delegator.py
1043
0644
edit
dl
rm
dynoption.py
2017
0644
edit
dl
rm
editor.py
65614
0644
edit
dl
rm
extend.txt
3642
0644
edit
dl
rm
filelist.py
3896
0644
edit
dl
rm
format.py
15777
0644
edit
dl
rm
grep.py
7479
0644
edit
dl
rm
help.html
62214
0644
edit
dl
rm
help.py
11734
0644
edit
dl
rm
help_about.py
8981
0644
edit
dl
rm
history.py
4043
0644
edit
dl
rm
HISTORY.txt
10312
0644
edit
dl
rm
hyperparser.py
12883
0644
edit
dl
rm
idle.py
454
0644
edit
dl
rm
idle.pyw
570
0644
edit
dl
rm
iomenu.py
20632
0644
edit
dl
rm
macosx.py
9662
0644
edit
dl
rm
mainmenu.py
3918
0644
edit
dl
rm
multicall.py
18648
0644
edit
dl
rm
NEWS.txt
48791
0644
edit
dl
rm
NEWS2x.txt
27172
0644
edit
dl
rm
outwin.py
5788
0644
edit
dl
rm
parenmatch.py
7204
0644
edit
dl
rm
pathbrowser.py
3193
0644
edit
dl
rm
percolator.py
3130
0644
edit
dl
rm
pyparse.py
19947
0644
edit
dl
rm
pyshell.py
57247
0755
edit
dl
rm
query.py
14898
0644
edit
dl
rm
README.txt
9599
0644
edit
dl
rm
redirector.py
6875
0644
edit
dl
rm
replace.py
9889
0644
edit
dl
rm
rpc.py
21137
0644
edit
dl
rm
run.py
20293
0644
edit
dl
rm
runscript.py
8781
0644
edit
dl
rm
scrolledlist.py
4465
0644
edit
dl
rm
search.py
5566
0644
edit
dl
rm
searchbase.py
7537
0644
edit
dl
rm
searchengine.py
7472
0644
edit
dl
rm
sidebar.py
13585
0644
edit
dl
rm
squeezer.py
12840
0644
edit
dl
rm
stackviewer.py
4454
0644
edit
dl
rm
statusbar.py
1441
0644
edit
dl
rm
textview.py
6813
0644
edit
dl
rm
TODO.txt
8478
0644
edit
dl
rm
tooltip.py
6565
0644
edit
dl
rm
tree.py
16357
0644
edit
dl
rm
undo.py
11046
0644
edit
dl
rm
window.py
2616
0644
edit
dl
rm
zoomheight.py
4203
0644
edit
dl
rm
zzdummy.py
961
0644
edit
dl
rm
__init__.py
396
0644
edit
dl
rm
__main__.py
159
0644
edit
dl
rm
Edit:
/opt/alt/python37/lib64/python3.7/idlelib/searchengine.py
(7472B)
'''Define SearchEngine for search dialogs.''' import re from tkinter import StringVar, BooleanVar, TclError import tkinter.messagebox as tkMessageBox def get(root): '''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. ''' if not hasattr(root, "_searchengine"): root._searchengine = SearchEngine(root) # This creates a cycle that persists until root is deleted. return root._searchengine class SearchEngine: """Handles searching a text widget for Find, Replace, and Grep.""" def __init__(self, root): '''Initialize Variables that save search state. The dialogs bind these to the UI elements present in the dialogs. ''' self.root = root # need for report_error() self.patvar = StringVar(root, '') # search pattern self.revar = BooleanVar(root, False) # regular expression? self.casevar = BooleanVar(root, False) # match case? self.wordvar = BooleanVar(root, False) # match whole word? self.wrapvar = BooleanVar(root, True) # wrap around buffer? self.backvar = BooleanVar(root, False) # search backwards? # Access methods def getpat(self): return self.patvar.get() def setpat(self, pat): self.patvar.set(pat) def isre(self): return self.revar.get() def iscase(self): return self.casevar.get() def isword(self): return self.wordvar.get() def iswrap(self): return self.wrapvar.get() def isback(self): return self.backvar.get() # Higher level access methods def setcookedpat(self, pat): "Set pattern after escaping if re." # called only in search.py: 66 if self.isre(): pat = re.escape(pat) self.setpat(pat) def getcookedpat(self): pat = self.getpat() if not self.isre(): # if True, see setcookedpat pat = re.escape(pat) if self.isword(): pat = r"\b%s\b" % pat return pat def getprog(self): "Return compiled cooked search pattern." pat = self.getpat() if not pat: self.report_error(pat, "Empty regular expression") return None pat = self.getcookedpat() flags = 0 if not self.iscase(): flags = flags | re.IGNORECASE try: prog = re.compile(pat, flags) except re.error as what: args = what.args msg = args[0] col = args[1] if len(args) >= 2 else -1 self.report_error(pat, msg, col) return None return prog def report_error(self, pat, msg, col=-1): # Derived class could override this with something fancier msg = "Error: " + str(msg) if pat: msg = msg + "\nPattern: " + str(pat) if col >= 0: msg = msg + "\nOffset: " + str(col) tkMessageBox.showerror("Regular expression error", msg, master=self.root) def search_text(self, text, prog=None, ok=0): '''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. ''' if not prog: prog = self.getprog() if not prog: return None # Compilation failed -- stop wrap = self.wrapvar.get() first, last = get_selection(text) if self.isback(): if ok: start = last else: start = first line, col = get_line_col(start) res = self.search_backward(text, prog, line, col, wrap, ok) else: if ok: start = first else: start = last line, col = get_line_col(start) res = self.search_forward(text, prog, line, col, wrap, ok) return res def search_forward(self, text, prog, line, col, wrap, ok=0): wrapped = 0 startline = line chars = text.get("%d.0" % line, "%d.0" % (line+1)) while chars: m = prog.search(chars[:-1], col) if m: if ok or m.end() > col: return line, m line = line + 1 if wrapped and line > startline: break col = 0 ok = 1 chars = text.get("%d.0" % line, "%d.0" % (line+1)) if not chars and wrap: wrapped = 1 wrap = 0 line = 1 chars = text.get("1.0", "2.0") return None def search_backward(self, text, prog, line, col, wrap, ok=0): wrapped = 0 startline = line chars = text.get("%d.0" % line, "%d.0" % (line+1)) while 1: m = search_reverse(prog, chars[:-1], col) if m: if ok or m.start() < col: return line, m line = line - 1 if wrapped and line < startline: break ok = 1 if line <= 0: if not wrap: break wrapped = 1 wrap = 0 pos = text.index("end-1c") line, col = map(int, pos.split(".")) chars = text.get("%d.0" % line, "%d.0" % (line+1)) col = len(chars) - 1 return None def search_reverse(prog, chars, col): '''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(). ''' m = prog.search(chars) if not m: return None found = None i, j = m.span() # m.start(), m.end() == match slice indexes while i < col and j <= col: found = m if i == j: j = j+1 m = prog.search(chars, j) if not m: break i, j = m.span() return found def get_selection(text): '''Return tuple of 'line.col' indexes from selection or insert mark. ''' try: first = text.index("sel.first") last = text.index("sel.last") except TclError: first = last = None if not first: first = text.index("insert") if not last: last = first return first, last def get_line_col(index): '''Return (line, col) tuple of ints from 'line.col' string.''' line, col = map(int, index.split(".")) # Fails on invalid index return line, col if __name__ == "__main__": from unittest import main main('idlelib.idle_test.test_searchengine', verbosity=2)
Save
cmd:
run