Python readline.__doc__() Examples

The following are 18 code examples of readline.__doc__(). 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: autocomplete.py    From vault with MIT License 7 votes vote down vote up
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 #2
Source File: smartconsole.py    From iOSSecAudit with GNU General Public License v3.0 6 votes vote down vote up
def init_history(self, histfile):
    
        #readline.parse_and_bind("bind ^I rl_complete")
        
        # Register our completer function
        readline.set_completer(SimpleCompleter(G.cmmands.keys()).complete)
        
        
        #readline.set_completer(TabCompleter().complete)
        ### Add autocompletion
        if 'libedit' in readline.__doc__:
            readline.parse_and_bind("bind -e")
            readline.parse_and_bind("bind '\t' rl_complete")
        else:
            readline.parse_and_bind("tab: complete")
        
        # Use the tab key for completion
        #readline.parse_and_bind('tab: complete')
        if hasattr(readline, "read_history_file"):
            try:
                readline.read_history_file(histfile)
            except:
                pass
            
            atexit.register(self.save_history, histfile) 
Example #3
Source File: _rlcompleter.py    From magic-wormhole with MIT License 6 votes vote down vote up
def _input_code_with_completion(prompt, input_helper, reactor):
    # reminder: this all occurs in a separate thread. All calls to input_helper
    # must go through blockingCallFromThread()
    c = CodeInputter(input_helper, reactor)
    if readline is not None:
        if readline.__doc__ and "libedit" in readline.__doc__:
            readline.parse_and_bind("bind ^I rl_complete")
        else:
            readline.parse_and_bind("tab: complete")
        readline.set_completer(c.completer)
        readline.set_completer_delims("")
        debug("==== readline-based completion is prepared")
    else:
        debug("==== unable to import readline, disabling completion")
    code = input(prompt)
    # Code is str(bytes) on py2, and str(unicode) on py3. We want unicode.
    if isinstance(code, bytes):
        code = code.decode("utf-8")
    c.finish(code)
    return c.used_completion 
Example #4
Source File: main.py    From rshell with MIT License 6 votes vote down vote up
def do_help(self, line):
        """help [COMMAND]

           List available commands with no arguments, or detailed help when
           a command is provided.
        """
        # We provide a help function so that we can trim the leading spaces
        # from the docstrings. The builtin help function doesn't do that.
        if not line:
            cmd.Cmd.do_help(self, line)
            self.print(EXIT_STR)
            return
        parser = self.create_argparser(line)
        if parser:
            parser.print_help()
            return
        try:
            doc = getattr(self, 'do_' + line).__doc__
            if doc:
                self.print("%s" % trim(doc))
                return
        except AttributeError:
            pass
        self.print(str(self.nohelp % (line,))) 
Example #5
Source File: main.py    From rshell with MIT License 6 votes vote down vote up
def create_argparser(self, command):
        try:
            argparse_args = getattr(self, "argparse_" + command)
        except AttributeError:
            return None
        doc_lines = getattr(self, "do_" + command).__doc__.expandtabs().splitlines()
        if '' in doc_lines:
            blank_idx = doc_lines.index('')
            usage = doc_lines[:blank_idx]
            description = doc_lines[blank_idx+1:]
        else:
            usage = doc_lines
            description = []
        parser = argparse.ArgumentParser(
            prog=command,
            usage='\n'.join(usage),
            description='\n'.join(description)
        )
        for args, kwargs in argparse_args:
            parser.add_argument(*args, **kwargs)
        return parser 
Example #6
Source File: utils.py    From QRLJacking with GNU General Public License v3.0 6 votes vote down vote up
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 #7
Source File: interactive.py    From rainbowstream with MIT License 5 votes vote down vote up
def init_interactive_shell(d):
    """
    Init the rainbow shell
    """
    readline.set_completer(RainbowCompleter(d).complete)
    readline.parse_and_bind('set skip-completed-text on')
    if 'libedit' in readline.__doc__:
        readline.parse_and_bind("bind ^I rl_complete")
    else:
        readline.parse_and_bind("tab: complete") 
Example #8
Source File: spinel-cli.py    From pyspinel with Apache License 2.0 5 votes vote down vote up
def do_help(self, line):
        if line:
            cmd, _arg, _unused = self.parseline(line)
            try:
                doc = getattr(self, 'do_' + cmd).__doc__
            except AttributeError:
                doc = None
            if doc:
                self.log("%s\n" % textwrap.dedent(doc))
            else:
                self.log("No help on %s\n" % (line))
        else:
            self.print_topics(
                "\nAvailable commands (type help <name> for more information):",
                SpinelCliCmd.command_names, 15, 80) 
Example #9
Source File: shell.py    From kitty with GNU General Public License v3.0 5 votes vote down vote up
def init_readline(readline: Any) -> None:
    try:
        readline.read_init_file()
    except OSError:
        if not is_macos:
            raise
    if 'libedit' in readline.__doc__:
        readline.parse_and_bind("bind ^I rl_complete")
    else:
        readline.parse_and_bind('tab: complete') 
Example #10
Source File: SniffAir.py    From SniffAir with MIT License 5 votes vote down vote up
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 #11
Source File: cli.py    From cli with MIT License 5 votes vote down vote up
def do_help(self, arg):
        methods = inspect.getmembers(CodeShell, predicate=inspect.ismethod)
        for key, method in methods:
            if key.startswith('do_'):
                name = key.split('_')[1]
                doc = method.__doc__
                if (not arg or arg == name) and doc:
                    print name, '\t', doc
        print """
A tag can refer to a topic (e.g. array) or a company (e.g. amazon).
A keyword can be anything (including a tag).
Commands and options can be completed by <TAB>.""" 
Example #12
Source File: cli.py    From cli with MIT License 5 votes vote down vote up
def __init__(self):
        import readline
        if 'libedit' in readline.__doc__:
            readline.parse_and_bind('bind ^I rl_complete')
        else:
            readline.parse_and_bind('tab: complete')

        cmd.Cmd.__init__(self)
        Magic.__init__(self)
        if not os.path.exists(self.ws):
            os.makedirs(self.ws) 
Example #13
Source File: consoles.py    From vulscan with MIT License 5 votes vote down vote up
def help_set(self):
        print
        print('  Usage :  set <key> <value>')
        print('  Desp  :  {}'.format(getattr(self, 'do_set').__doc__))
        print('  Demo  :  set threads 1')
        print 
Example #14
Source File: consoles.py    From vulscan with MIT License 5 votes vote down vote up
def help_pocadd(self):
        print
        print('  Usage :  pocadd /path/to/pocfile or /path/to/poc_dir')
        print('  Desp  :  {}'.format(getattr(self, 'do_pocadd').__doc__))
        print('  Demo  :  pocadd modules')
        print 
Example #15
Source File: consoles.py    From vulscan with MIT License 5 votes vote down vote up
def help_back(self):
        print
        print('  Usage : back')
        print('  Desp  : {}'.format(getattr(self, 'do_back').__doc__))
        print('  Demo  : back')
        print 
Example #16
Source File: consoles.py    From vulscan with MIT License 5 votes vote down vote up
def print_topics(self, header, cmds, cmdlen, maxcol):
        """make help menu more readable"""
        if cmds:
            self.stdout.write(header)
            self.stdout.write("\n")
            if self.ruler:
                self.stdout.write(self.ruler * len(header))
                self.stdout.write("\n")

            for cmd in cmds:
                help_msg = getattr(self, "do_{}".format(cmd)).__doc__
                self.stdout.write("{:<16}".format(cmd))
                self.stdout.write(help_msg)
                self.stdout.write("\n")
            self.stdout.write("\n") 
Example #17
Source File: consoles.py    From vulscan with MIT License 5 votes vote down vote up
def __init__(self):
        Cmd.__init__(self)
        self.do_help.__func__.__doc__ = "Show help menu" 
Example #18
Source File: spinel-cli.py    From pyspinel with Apache License 2.0 4 votes vote down vote up
def __init__(self, stream, nodeid, *_a, **kw):
        if self.VIRTUAL_TIME:
            self._init_virtual_time()
        self.nodeid = nodeid
        self.tun_if = None

        self.wpan_api = WpanApi(stream, nodeid)
        self.wpan_api.queue_register(SPINEL.HEADER_DEFAULT)
        self.wpan_api.callback_register(SPINEL.PROP_STREAM_NET,
                                        self.wpan_callback)

        Cmd.__init__(self)
        Cmd.identchars = string.ascii_letters + string.digits + '-'

        if sys.stdin.isatty():
            self.prompt = MASTER_PROMPT + " > "
        else:
            self.use_rawinput = 0
            self.prompt = ""

        SpinelCliCmd.command_names.sort()

        self.history_filename = os.path.expanduser("~/.spinel-cli-history")

        try:
            import readline
            try:
                readline.read_history_file(self.history_filename)
            except IOError:
                pass
        except ImportError:
            print("Module readline unavailable")
        else:
            import rlcompleter
            if 'libedit' in readline.__doc__:
                readline.parse_and_bind('bind ^I rl_complete')
            else:
                readline.parse_and_bind('tab: complete')

        if hasattr(stream, 'pipe'):
            self.wpan_api.queue_wait_for_prop(SPINEL.PROP_LAST_STATUS,
                                              SPINEL.HEADER_ASYNC)
        self.prop_set_value(SPINEL.PROP_IPv6_ICMP_PING_OFFLOAD, 1)
        self.prop_set_value(SPINEL.PROP_THREAD_RLOC16_DEBUG_PASSTHRU, 1)