MCPcopy Index your code
hub / github.com/python/cpython / fetch

Method fetch

Lib/idlelib/history.py:41–88  ·  view source on GitHub ↗

Fetch statement and replace current line in text widget. Set prefix and pointer as needed for successive fetches. Reset them to None, None when returning to the start line. Sound bell when return to start line or cannot leave a line because cyclic is False.

(self, reverse)

Source from the content-addressed store, hash-verified

39 return "break"
40
41 def fetch(self, reverse):
42 '''Fetch statement and replace current line in text widget.
43
44 Set prefix and pointer as needed for successive fetches.
45 Reset them to None, None when returning to the start line.
46 Sound bell when return to start line or cannot leave a line
47 because cyclic is False.
48 '''
49 nhist = len(self.history)
50 pointer = self.pointer
51 prefix = self.prefix
52 if pointer is not None and prefix is not None:
53 if self.text.compare("insert", "!=", "end-1c") or \
54 self.text.get("iomark", "end-1c") != self.history[pointer]:
55 pointer = prefix = None
56 self.text.mark_set("insert", "end-1c") # != after cursor move
57 if pointer is None or prefix is None:
58 prefix = self.text.get("iomark", "end-1c")
59 if reverse:
60 pointer = nhist # will be decremented
61 else:
62 if self.cyclic:
63 pointer = -1 # will be incremented
64 else: # abort history_next
65 self.text.bell()
66 return
67 nprefix = len(prefix)
68 while True:
69 pointer += -1 if reverse else 1
70 if pointer < 0 or pointer >= nhist:
71 self.text.bell()
72 if not self.cyclic and pointer < 0: # abort history_prev
73 return
74 else:
75 if self.text.get("iomark", "end-1c") != prefix:
76 self.text.delete("iomark", "end-1c")
77 self.text.insert("iomark", prefix, "stdin")
78 pointer = prefix = None
79 break
80 item = self.history[pointer]
81 if item[:nprefix] == prefix and len(item) > nprefix:
82 self.text.delete("iomark", "end-1c")
83 self.text.insert("iomark", item, "stdin")
84 break
85 self.text.see("insert")
86 self.text.tag_remove("sel", "1.0", "end")
87 self.pointer = pointer
88 self.prefix = prefix
89
90 def store(self, source):
91 "Store Shell input statement into history list."

Callers 5

history_nextMethod · 0.95
history_prevMethod · 0.95
fetch_testMethod · 0.45
test_fetch_editMethod · 0.45

Calls 8

compareMethod · 0.45
getMethod · 0.45
mark_setMethod · 0.45
bellMethod · 0.45
deleteMethod · 0.45
insertMethod · 0.45
seeMethod · 0.45
tag_removeMethod · 0.45

Tested by 3

fetch_testMethod · 0.36
test_fetch_editMethod · 0.36