def keypress(self, key, editor): if key == "r": if editor.walker.get_current_value() is not None: signals.status_prompt_path.send( self, prompt = "Read file", callback = editor.read_file ) elif key == "R": if editor.walker.get_current_value() is not None: signals.status_prompt_path.send( editor, prompt = "Read unescaped file", callback = editor.read_file, args = (True,) ) elif key == "e": o = editor.walker.get_current_value() if o is not None: n = editor.master.spawn_editor(o.encode("string-escape")) n = strutils.clean_hanging_newline(n) editor.walker.set_current_value(n, False) editor.walker._modified() elif key in ["enter"]: editor.walker.start_edit() else: return key
def keypress(self, key, editor): if key == "r": if editor.walker.get_current_value() is not None: signals.status_prompt_path.send( self, prompt="Read file", callback=read_file, args=(editor.walker.set_current_value, True) ) elif key == "R": if editor.walker.get_current_value() is not None: signals.status_prompt_path.send( self, prompt="Read unescaped file", callback=read_file, args=(editor.walker.set_current_value, False) ) elif key == "e": o = editor.walker.get_current_value() if o is not None: n = editor.master.spawn_editor(o) n = strutils.clean_hanging_newline(n) editor.walker.set_current_value(n) elif key in ["enter"]: editor.walker.start_edit() else: return key
def test_clean_hanging_newline(): s = "foo\n" assert strutils.clean_hanging_newline(s) == "foo" assert strutils.clean_hanging_newline("foo") == "foo"
def keypress(self, key, editor): if key == "r": if editor.walker.get_current_value() is not None: signals.status_prompt_path.send( self, prompt = "Read file", args=(editor.walker.set_current_value, True), callback = read_file ) elif key == "R": if editor.walker.get_current_value() is not None: signals.status_prompt_path.send( self, prompt = "Read unescaped file", callback = read_file, args=(editor.walker.set_current_value, False) ) elif key == "e": o = editor.walker.get_current_value() if o is not None: n = editor.master.spawn_editor(o.encode("string-escape")) n = strutils.clean_hanging_newline(n) editor.walker.set_current_value(n) elif key == "D": # base64 decode o = editor.walker.get_current_value() if o is not None: try: if ' ' in o: parts = o.split(' ', 1) if len(parts) == 2: b64decoded_val = parts[0] + ' ' + base64.b64decode(parts[1]) else: b64decoded_val = base64.b64decode(o) except: b64decoded_val = o editor.walker.set_current_value(b64decoded_val) editor.walker._modified() elif key == "E": # base64 encode o = editor.walker.get_current_value() if o is not None: try: if ' ' in o: parts = o.split(' ', 1) if len(parts) == 2: b64encoded_val = parts[0] + ' ' + base64.b64encode(parts[1]) else: b64encoded_val = base64.b64encode(o) except: b64encoded_val = o editor.walker.set_current_value(b64encoded_val) editor.walker._modified() elif key == "p": # increase a number by 1 o = editor.walker.get_current_value() try: idx = self.get_number_start_idx(o) part1 = o[0:idx] part2 = o[idx:] part2 = str(int(part2) + 1) n = part1 + part2 except: n = o editor.walker.set_current_value(n) editor.walker._modified() elif key == "m": # increase a number by 1 o = editor.walker.get_current_value() try: idx = self.get_number_start_idx(o) part1 = o[0:idx] part2 = o[idx:] part2 = str(int(part2) - 1) n = part1 + part2 except: n = o editor.walker.set_current_value(n) editor.walker._modified() elif key == "n": o = editor.walker.get_current_value() n = "*****@*****.**" editor.walker.set_current_value(n) editor.walker._modified() elif key == "u": o = editor.walker.get_current_value() try: n = urllib.unquote_plus(o) except: n = o editor.walker.set_current_value(n) editor.walker._modified() elif key in ["enter"]: editor.walker.start_edit() else: return key