MCPcopy Index your code
hub / github.com/RustPython/RustPython / push

Method push

Lib/_pyrepl/unix_eventqueue.py:116–152  ·  view source on GitHub ↗

Processes a character by updating the buffer and handling special key mappings.

(self, char: int | bytes)

Source from the content-addressed store, hash-verified

114 self.events.append(event)
115
116 def push(self, char: int | bytes) -> None:
117 """
118 Processes a character by updating the buffer and handling special key mappings.
119 """
120 ord_char = char if isinstance(char, int) else ord(char)
121 char = bytes(bytearray((ord_char,)))
122 self.buf.append(ord_char)
123 if char in self.keymap:
124 if self.keymap is self.compiled_keymap:
125 #sanity check, buffer is empty when a special key comes
126 assert len(self.buf) == 1
127 k = self.keymap[char]
128 trace('found map {k!r}', k=k)
129 if isinstance(k, dict):
130 self.keymap = k
131 else:
132 self.insert(Event('key', k, self.flush_buf()))
133 self.keymap = self.compiled_keymap
134
135 elif self.buf and self.buf[0] == 27: # escape
136 # escape sequence not recognized by our keymap: propagate it
137 # outside so that i can be recognized as an M-... key (see also
138 # the docstring in keymap.py
139 trace('unrecognized escape sequence, propagating...')
140 self.keymap = self.compiled_keymap
141 self.insert(Event('key', '\033', bytearray(b'\033')))
142 for _c in self.flush_buf()[1:]:
143 self.push(_c)
144
145 else:
146 try:
147 decoded = bytes(self.buf).decode(self.encoding)
148 except UnicodeError:
149 return
150 else:
151 self.insert(Event('key', decoded, self.flush_buf()))
152 self.keymap = self.compiled_keymap

Callers

nothing calls this directly

Calls 9

insertMethod · 0.95
flush_bufMethod · 0.95
traceFunction · 0.90
isinstanceFunction · 0.85
ordFunction · 0.85
lenFunction · 0.85
EventClass · 0.70
appendMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected