Python readline.parse_and_bind() Examples
The following are 30
code examples of readline.parse_and_bind().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
readline
, or try the search function
.
Example #1
Source File: pundle.py From pundler with BSD 2-Clause "Simplified" License | 9 votes |
def run_console(glob): import readline import rlcompleter import atexit import code history_path = os.path.expanduser("~/.python_history") def save_history(history_path=history_path): readline.write_history_file(history_path) if os.path.exists(history_path): readline.read_history_file(history_path) atexit.register(save_history) readline.set_completer(rlcompleter.Completer(glob).complete) readline.parse_and_bind("tab: complete") code.InteractiveConsole(locals=glob).interact()
Example #2
Source File: autocomplete.py From vault with MIT License | 7 votes |
def get_input_autocomplete(message=''): """ Allow user to type input and provide auto-completion """ # Apple does not ship GNU readline with OS X. # It does ship BSD libedit which includes a readline compatibility interface. # Source: https://stackoverflow.com/questions/7116038/python-tab-completion-mac-osx-10-7-lion if 'libedit' in readline.__doc__: readline.parse_and_bind("bind ^I rl_complete") else: readline.parse_and_bind("tab: complete") readline.set_completer(autocomplete) try: return input(message).strip() except KeyboardInterrupt: return False except Exception: # Other Exception return False
Example #3
Source File: featherduster.py From featherduster with BSD 3-Clause "New" or "Revised" License | 6 votes |
def run(self, line): ishellCompleter = readline.get_completer() readline.set_completer_delims(' \t\n;') readline.parse_and_bind("tab: complete") readline.set_completer(completer.complete) sample_file = raw_input('Please enter the filename you want to open: ') try: sample_fh = open(sample_file,'r') feathermodules.samples.extend([sample.strip() for sample in sample_fh.readlines()]) sample_fh.close() feathermodules.samples = filter(lambda x: x != '' and x != None, feathermodules.samples) except: print 'Something went wrong. Sorry! Please try again.' finally: readline.set_completer(ishellCompleter)
Example #4
Source File: shell.py From imapfw with MIT License | 6 votes |
def configureCompletion(self) -> None: try: from jedi.utils import setup_readline setup_readline() except ImportError: # Fallback to the stdlib readline completer if it is installed. # Taken from http://docs.python.org/2/library/rlcompleter.html runtime.ui.info("jedi is not installed, falling back to readline" " for completion") try: import readline import rlcompleter readline.parse_and_bind("tab: complete") except ImportError: runtime.ui.info("readline is not installed either." " No tab completion is enabled.")
Example #5
Source File: BaseInterpreter.py From Industrial-Security-Auditing-Framework with GNU General Public License v3.0 | 6 votes |
def setup(self): """ Initialization of third-party libraries Setting interpreter history. Setting appropriate completer function. :return: """ if not os.path.exists(self.history_file): open(self.history_file, 'a+').close() readline.read_history_file(self.history_file) readline.set_history_length(self.history_length) atexit.register(readline.write_history_file, self.history_file) readline.parse_and_bind('set enable-keypad on') readline.set_completer(self.complete) readline.set_completer_delims(' \t\n;') readline.parse_and_bind("tab: complete")
Example #6
Source File: PupyCmd.py From NoobSec-Toolkit with GNU General Public License v2.0 | 6 votes |
def do_python(self,arg): """ start the local python interpreter (for debugging purposes) """ orig_exit=builtins.exit orig_quit=builtins.quit def disabled_exit(*args, **kwargs): self.display_warning("exit() disabled ! use ctrl+D to exit the python shell") builtins.exit=disabled_exit builtins.quit=disabled_exit oldcompleter=readline.get_completer() try: local_ns={"pupsrv":self.pupsrv} readline.set_completer(PythonCompleter(local_ns=local_ns).complete) readline.parse_and_bind('tab: complete') code.interact(local=local_ns) except Exception as e: self.display_error(str(e)) finally: readline.set_completer(oldcompleter) readline.parse_and_bind('tab: complete') builtins.exit=orig_exit builtins.quit=orig_quit
Example #7
Source File: featherduster.py From featherduster with BSD 3-Clause "New" or "Revised" License | 6 votes |
def run(self, line): ishellCompleter = readline.get_completer() readline.set_completer_delims(' \t\n;') readline.parse_and_bind("tab: complete") readline.set_completer(completer.complete) sample_file = raw_input('Please enter the filename you want to open: ') try: sample_fh = open(sample_file,'r') feathermodules.samples.append(sample_fh.read()) sample_fh.close() feathermodules.samples = filter(lambda x: x != '' and x != None, feathermodules.samples) except: print 'Something went wrong. Sorry! Please try again.' finally: readline.set_completer(ishellCompleter)
Example #8
Source File: utils.py From QRLJacking with GNU General Public License v3.0 | 6 votes |
def Input_completer(keywords): completer = MyCompleter(keywords) readline.set_completer(completer.complete) if "libedit" in readline.__doc__: readline.parse_and_bind("bind ^I rl_complete") else: readline.parse_and_bind('tab: complete') #readline.parse_and_bind('"\\e[A": complete') # Up arrow readline.parse_and_bind("set colored-completion-prefix on") readline.parse_and_bind("set show-all-if-unmodified on") readline.parse_and_bind("set horizontal-scroll-mode on") if os.path.exists(history_file): readline.read_history_file(history_file) readline.set_history_length(20) readline.set_completer_delims(' ') atexit.register(save_history)
Example #9
Source File: armory_interactive.py From armory with GNU General Public License v3.0 | 6 votes |
def show_menu(CommandClass, CompleterClass, name): command = CommandClass(name) completer = CompleterClass(command) readline.set_completer(completer.complete) readline.set_completer_delims(" ") readline.parse_and_bind("tab: complete") res = False while res is not True: valid_commands = command.cmd.keys() ret_cmd = six.input("%s> " % name).strip() cmd, options = (ret_cmd.split(" ")[0], " ".join(ret_cmd.split(" ")[1:])) if cmd == "debug": pdb.set_trace() elif cmd.lower() in valid_commands: res = command.run_cmd(cmd, options) else: print("Invalid command.") readline.set_completer(completer.complete)
Example #10
Source File: shell.py From koadic with Apache License 2.0 | 6 votes |
def get_command(self, prompt, auto_complete_fn=None, basefile_fn=None): try: if auto_complete_fn != None: import readline readline.set_completer_delims(' \t\n;/') readline.parse_and_bind("tab: complete") readline.set_completer(auto_complete_fn) # readline.set_completion_display_matches_hook(basefile_fn) except: pass # python3 changes raw input name if sys.version_info[0] == 3: raw_input = input else: raw_input = __builtins__['raw_input'] cmd = raw_input("%s" % prompt) return cmd.strip()
Example #11
Source File: Interface.py From smod-1 with GNU General Public License v2.0 | 6 votes |
def use(self,args,pointer = None): global POINTER if(len(args) < 2): return None POINTER = args[1] moduleName = args[1].split('/') comp = Completer() readline.set_completer_delims(' \t\n;') readline.parse_and_bind("tab: complete") readline.set_completer(comp.complete) while True: input = raw_input('SMOD ' + moduleName[0] + '(' + bcolors.OKBLUE + moduleName[-1] + bcolors.ENDC + ') >').strip().split() try: result = getattr(globals()['Command'](),input[0])(input,args[1]) except: return None if (POINTER == None): break
Example #12
Source File: PupyCmd.py From NoobSec-Toolkit with GNU General Public License v2.0 | 6 votes |
def do_python(self,arg): """ start the local python interpreter (for debugging purposes) """ orig_exit=builtins.exit orig_quit=builtins.quit def disabled_exit(*args, **kwargs): self.display_warning("exit() disabled ! use ctrl+D to exit the python shell") builtins.exit=disabled_exit builtins.quit=disabled_exit oldcompleter=readline.get_completer() try: local_ns={"pupsrv":self.pupsrv} readline.set_completer(PythonCompleter(local_ns=local_ns).complete) readline.parse_and_bind('tab: complete') code.interact(local=local_ns) except Exception as e: self.display_error(str(e)) finally: readline.set_completer(oldcompleter) readline.parse_and_bind('tab: complete') builtins.exit=orig_exit builtins.quit=orig_quit
Example #13
Source File: cli.py From clonedigger with GNU General Public License v3.0 | 6 votes |
def init_readline(complete_method, histfile=None): """init the readline library if available""" try: import readline readline.parse_and_bind("tab: complete") readline.set_completer(complete_method) string = readline.get_completer_delims().replace(':', '') readline.set_completer_delims(string) if histfile is not None: try: readline.read_history_file(histfile) except IOError: pass import atexit atexit.register(readline.write_history_file, histfile) except: print('readline si not available :-(')
Example #14
Source File: interactive.py From pycopia with Apache License 2.0 | 5 votes |
def parse_and_bind(self, *args): pass
Example #15
Source File: __main__.py From signac with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _main_import_interactive(project, origin, args): from .contrib.import_export import _prepare_import_into_project if args.move: raise ValueError("Cannot use '--move' in combination with '--sync-interactive'.") with project.temporary_project() as tmp_project: _print_err("Prepare data space for import...") with _prepare_import_into_project(origin, tmp_project, args.schema_path) as data_mapping: paths = dict() for src, copy_executor in tqdm( dict(data_mapping).items(), desc='Import to temporary project'): paths[src] = copy_executor() local_ns = dict( signac=importlib.import_module(__package__), project=project, pr=project, tmp_project=tmp_project) if READLINE: readline.set_completer(Completer(local_ns).complete) readline.parse_and_bind('tab: complete') code.interact( local=local_ns, banner=SHELL_BANNER_INTERACTIVE_IMPORT.format( python_version=sys.version, signac_version=__version__, project_id=project.get_id(), job_banner='', root_path=project.root_directory(), workspace_path=project.workspace(), size=len(project), origin=args.origin)) return paths
Example #16
Source File: shell.py From rssant with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _enable_completer(context=None): try: import readline except ImportError: return try: import rlcompleter except ImportError: return readline.set_completer(rlcompleter.Completer(context).complete) readline.parse_and_bind("tab:complete") # command history if os.path.exists(HISTORY_PATH): readline.read_history_file(HISTORY_PATH) atexit.register(_save_history)
Example #17
Source File: scaffold.py From daenerys with Apache License 2.0 | 5 votes |
def main(): url = sys.argv[1] context['url'] = url pkg = app.dispatch_url(url) context['pkg'] = pkg for item in pkg.to_dict().items(): print '{} = {}'.format(*item) def prepare_readline(): import os import readline import atexit readline.parse_and_bind('tab: complete') histfile = os.path.expanduser("~/.daenerys_history") try: readline.read_history_file(histfile) except IOError: pass def savehist(histfile): readline.write_history_file(histfile) atexit.register(savehist, histfile) del atexit try: from IPython.terminal.interactiveshell import TerminalInteractiveShell shell = TerminalInteractiveShell(user_ns=context) shell.mainloop() except ImportError: import code shell = code.InteractiveConsole(locals=context) shell.runcode(prepare_readline.__code__) shell.interact()
Example #18
Source File: interact.py From neleval with Apache License 2.0 | 5 votes |
def run_python(local): import code try: import readline except ImportError: pass else: import rlcompleter readline.set_completer(rlcompleter.Completer(local).complete) readline.parse_and_bind('tab:complete') code.interact(local=local)
Example #19
Source File: repl.py From sdb with Apache License 2.0 | 5 votes |
def __init__(self, target: drgn.Program, vocabulary: List[str], prompt: str = "sdb> ", closing: str = ""): self.prompt = prompt self.closing = closing self.vocabulary = vocabulary self.target = target self.histfile = "" readline.set_completer(REPL.__make_completer(vocabulary)) readline.parse_and_bind("tab: complete")
Example #20
Source File: completer.py From pythem with GNU General Public License v3.0 | 5 votes |
def __init__(self, path, console): tab = readline.parse_and_bind("tab: complete") if console == "pythem": historyPath = ".pythem_history".format(path) readline.read_history_file(historyPath) completer = readline.set_completer(self.pythem) # readline.write_history_file(historyPath) if console == "xploit": completer = readline.set_completer(self.xploit)
Example #21
Source File: riposte.py From riposte with MIT License | 5 votes |
def _setup_completer(self) -> None: readline.set_completer(self._complete) readline.set_completer_delims(" \t\n;") readline.parse_and_bind( "bind ^I rl_complete" if is_libedit() else "tab: complete" )
Example #22
Source File: Interface.py From smod-1 with GNU General Public License v2.0 | 5 votes |
def mainLoop(): comp = Completer() readline.set_completer_delims(' \t\n;') readline.parse_and_bind("tab: complete") readline.set_completer(comp.complete) while True: input = raw_input('SMOD >').strip().split() if(input[0] in Command.COMMANDS): result = getattr(globals()['Command'](),input[0])(input)
Example #23
Source File: console.py From click-odoo with GNU Lesser General Public License v3.0 | 5 votes |
def python(cls, local_vars): console = code.InteractiveConsole(locals=local_vars) import rlcompleter # noqa import readline readline.parse_and_bind("tab: complete") console.interact()
Example #24
Source File: comm.py From qdb with Apache License 2.0 | 5 votes |
def __init__(self): super(TerminalCommandManager, self).__init__() self._sticky = True self._redraw = True # Side effectful imports ;_; import rlcompleter # NOQA import readline self.readline = readline readline.parse_and_bind("tab: complete")
Example #25
Source File: plac_ext.py From plac with BSD 2-Clause "Simplified" License | 5 votes |
def __init__(self, completions, case_sensitive=True, histfile=None): self.completions = completions self.case_sensitive = case_sensitive self.histfile = histfile if not case_sensitive: self.completions = [c.upper() for c in completions] import readline self.rl = readline readline.parse_and_bind("tab: complete") readline.set_completer(self.complete)
Example #26
Source File: cli.py From pytgbot with GNU General Public License v3.0 | 5 votes |
def register_tab_completion(self): # Register our completer function readline.parse_and_bind('tab: complete') readline.set_completer(self.complete) # Use the tab key for completion # end def
Example #27
Source File: SniffAir.py From SniffAir with MIT License | 5 votes |
def choice(): global name global module try: if module == "": readline.set_completer(completer) readline.set_completer_delims('') if 'libedit' in readline.__doc__: readline.parse_and_bind("bind ^I rl_complete") else: readline.parse_and_bind("tab: complete") raw_choice = raw_input(" >> [" + name + "]# ") choice = raw_choice exec_menu(choice) else: readline.set_completer(completer) readline.set_completer_delims('') if 'libedit' in readline.__doc__: readline.parse_and_bind("bind ^I rl_complete") else: readline.parse_and_bind("tab: complete") raw_choice = raw_input(" >> [" + name + "][" + module + "]# ") choice = raw_choice exec_menu(choice) except EOFError: pass except KeyboardInterrupt: exec_menu('exit')
Example #28
Source File: featherduster.py From featherduster with BSD 3-Clause "New" or "Revised" License | 5 votes |
def run(self, line): def _formatOutput(res): if isinstance(res, str): return res else: try: return "\n".join(_formatOutput(r) for r in res) except TypeError: return str(res) ishellCompleter = readline.get_completer() readline.set_completer_delims(' \t\n;') readline.parse_and_bind("tab: complete") readline.set_completer(completer.complete) filePath = raw_input("Please specify a path to the output file: ").strip() readline.set_completer(ishellCompleter) if os.path.isfile(filePath): confirm = raw_input("File already exists and will be overwritten, confirm? [y/N] ") if confirm is "" or confirm[0] not in ("y", "Y"): print "Canceled." return with open(filePath, "w+") as handle: handle.write(_formatOutput(feathermodules.results))
Example #29
Source File: complete.py From weeman with GNU General Public License v3.0 | 5 votes |
def complete(array): completer = auto(array) readline.set_completer(completer.complete) readline.parse_and_bind('tab:complete')
Example #30
Source File: console.py From baidupan_shell with GNU General Public License v2.0 | 5 votes |
def __init__(self): # 绑定readline readline.parse_and_bind('tab: complete') readline.set_completer(_completer)