当前位置: 首页>>代码示例>>Python>>正文


Python rlcompleter.Completer方法代码示例

本文整理汇总了Python中rlcompleter.Completer方法的典型用法代码示例。如果您正苦于以下问题:Python rlcompleter.Completer方法的具体用法?Python rlcompleter.Completer怎么用?Python rlcompleter.Completer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rlcompleter的用法示例。


在下文中一共展示了rlcompleter.Completer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_console

# 需要导入模块: import rlcompleter [as 别名]
# 或者: from rlcompleter import Completer [as 别名]
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() 
开发者ID:Deepwalker,项目名称:pundler,代码行数:20,代码来源:pundle.py

示例2: complete

# 需要导入模块: import rlcompleter [as 别名]
# 或者: from rlcompleter import Completer [as 别名]
def complete(self, text, state):
        if state == 0:
            self.completions = []
            append = self.completions.append
            for path in glob.glob(text + '*'):
                if os.path.isdir(path):
                    if not path.endswith(os.sep):
                        path += os.sep
                else:
                    path += ' '
                append(path)

            pycompleter = rlcompleter.Completer(namespace=self.local).complete
            for i in count():
                completion = pycompleter(text, i)
                if completion is None:
                    break
                else:
                    append(completion)

        try:
            return self.completions[state]
        except IndexError:
            return None 
开发者ID:terrycojones,项目名称:daudin,代码行数:26,代码来源:readline.py

示例3: test_main

# 需要导入模块: import rlcompleter [as 别名]
# 或者: from rlcompleter import Completer [as 别名]
def test_main():
    support.run_unittest(TestRlcompleter)

    def test_duplicate_globals(self):
        namespace = {
            'False': None,  # Keyword vs builtin vs namespace
            'assert': None,  # Keyword vs namespace
            'try': lambda: None,  # Keyword vs callable
            'memoryview': None,  # Callable builtin vs non-callable
            'Ellipsis': lambda: None,  # Non-callable builtin vs callable
        }
        completer = rlcompleter.Completer(namespace)
        self.assertEqual(completer.complete('False', 0), 'False')
        self.assertIsNone(completer.complete('False', 1))  # No duplicates
        self.assertEqual(completer.complete('assert', 0), 'assert')
        self.assertIsNone(completer.complete('assert', 1))
        self.assertEqual(completer.complete('try', 0), 'try')
        self.assertIsNone(completer.complete('try', 1))
        # No opening bracket "(" because we overrode the built-in class
        self.assertEqual(completer.complete('memoryview', 0), 'memoryview')
        self.assertIsNone(completer.complete('memoryview', 1))
        self.assertEqual(completer.complete('Ellipsis', 0), 'Ellipsis(')
        self.assertIsNone(completer.complete('Ellipsis', 1)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:test_rlcompleter.py

示例4: complete_names

# 需要导入模块: import rlcompleter [as 别名]
# 或者: from rlcompleter import Completer [as 别名]
def complete_names(word, namespace):
    """Complete variable names or attributes

    :param word: word to be completed
    :type word: str
    :param namespace: namespace
    :type namespace: dict
    :returns: completion matches
    :rtype: list of str

    >>> complete_names('fo', {'foo': 'bar'})
    ['foo', 'for', 'format(']
    """
    # start completer
    completer = rlcompleter.Completer(namespace)
    # find matches with std library (don't try to implement this yourself)
    completer.complete(word, 0)
    return sorted(set(completer.matches)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:20,代码来源:complete_namespace.py

示例5: test_duplicate_globals

# 需要导入模块: import rlcompleter [as 别名]
# 或者: from rlcompleter import Completer [as 别名]
def test_duplicate_globals(self):
        namespace = {
            'False': None,  # Keyword vs builtin vs namespace
            'assert': None,  # Keyword vs namespace
            'try': lambda: None,  # Keyword vs callable
            'memoryview': None,  # Callable builtin vs non-callable
            'Ellipsis': lambda: None,  # Non-callable builtin vs callable
        }
        completer = rlcompleter.Completer(namespace)
        self.assertEqual(completer.complete('False', 0), 'False')
        self.assertIsNone(completer.complete('False', 1))  # No duplicates
        self.assertEqual(completer.complete('assert', 0), 'assert')
        self.assertIsNone(completer.complete('assert', 1))
        self.assertEqual(completer.complete('try', 0), 'try')
        self.assertIsNone(completer.complete('try', 1))
        # No opening bracket "(" because we overrode the built-in class
        self.assertEqual(completer.complete('memoryview', 0), 'memoryview')
        self.assertIsNone(completer.complete('memoryview', 1))
        self.assertEqual(completer.complete('Ellipsis', 0), 'Ellipsis(')
        self.assertIsNone(completer.complete('Ellipsis', 1)) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:22,代码来源:test_rlcompleter.py

示例6: enable_autocomplete_and_history

# 需要导入模块: import rlcompleter [as 别名]
# 或者: from rlcompleter import Completer [as 别名]
def enable_autocomplete_and_history(adir,env):
    try:
        import rlcompleter
        import atexit
        import readline
    except ImportError:
        pass
    else:
        readline.parse_and_bind("bind ^I rl_complete"
                                if sys.platform == 'darwin'
                                else "tab: complete")
        history_file = os.path.join(adir,'.pythonhistory')
        try:
            readline.read_history_file(history_file)
        except IOError:
            open(history_file, 'a').close()
        atexit.register(readline.write_history_file, history_file)
        readline.set_completer(rlcompleter.Completer(env).complete) 
开发者ID:uwdata,项目名称:termite-visualizations,代码行数:20,代码来源:shell.py

示例7: start

# 需要导入模块: import rlcompleter [as 别名]
# 或者: from rlcompleter import Completer [as 别名]
def start(self) -> None:
        try:
            import readline
        except ImportError:
            pass
        else:
            # We don't have to wrap the following import in a 'try', because
            # we already know 'readline' was imported successfully.
            import rlcompleter

            readline.set_completer(rlcompleter.Completer(self.context).complete)
            readline.parse_and_bind("tab:complete")

        if self.prompt:
            sys.ps1 = self.prompt
        if self.output:
            warnings.warn("Custom output templates not supported by PythonShell.")
        code.interact(self.banner, local=self.context)
        return None 
开发者ID:sloria,项目名称:konch,代码行数:21,代码来源:konch.py

示例8: run_client

# 需要导入模块: import rlcompleter [as 别名]
# 或者: from rlcompleter import Completer [as 别名]
def run_client(host="localhost", port=9901):
    import code
    import readline
    import rlcompleter
    url = "http://{host}:{port}/jsonrpc".format(host=host, port=port)
    cli = TeleniumHttpClient(url=url, timeout=5)

    print("Connecting to {}".format(url))
    while not cli.ping():
        sleep(.1)
    print("Connected!")

    vars = globals()
    vars.update(locals())
    readline.set_completer(rlcompleter.Completer(vars).complete)
    readline.parse_and_bind("tab: complete")
    shell = code.InteractiveConsole(vars)
    shell.interact() 
开发者ID:tito,项目名称:telenium,代码行数:20,代码来源:client.py

示例9: setupReadline

# 需要导入模块: import rlcompleter [as 别名]
# 或者: from rlcompleter import Completer [as 别名]
def setupReadline(local):
    """Initialize the readline library and command history.

    @return: A C{bool} to indicate whether standard input is a terminal
        (and therefore interactive).
    """
    readline.parse_and_bind('tab: complete')
    readline.set_completer_delims(' \t\n')
    readline.set_completer(Completer(local).complete)

    # Readline code from https://docs.python.org/3.7/library/readline.html
    histfile = os.path.join(os.path.expanduser('~'), '.daudin_history')

    try:
        readline.read_history_file(histfile)
        historyLen = readline.get_current_history_length()
    except FileNotFoundError:
        open(histfile, 'wb').close()
        historyLen = 0

    try:
        readline.append_history_file
    except AttributeError:
        # We won't be able to save readline history. This can happen on
        # Python 3.5 at least - not sure why.
        pass
    else:
        import atexit

        def saveHistory(prevHistoryLen, histfile):
            newHistoryLen = readline.get_current_history_length()
            readline.set_history_length(1000)
            readline.append_history_file(newHistoryLen - prevHistoryLen,
                                         histfile)

        atexit.register(saveHistory, historyLen, histfile)

    return True 
开发者ID:terrycojones,项目名称:daudin,代码行数:40,代码来源:readline.py

示例10: handle

# 需要导入模块: import rlcompleter [as 别名]
# 或者: from rlcompleter import Completer [as 别名]
def handle(self, **options):
        try:
            if options['plain']:
                # Don't bother loading IPython, because the user wants plain Python.
                raise ImportError

            self.run_shell(shell=options['interface'])
        except ImportError:
            import code
            # Set up a dictionary to serve as the environment for the shell, so
            # that tab completion works on objects that are imported at runtime.
            # See ticket 5082.
            imported_objects = {}
            try:  # Try activating rlcompleter, because it's handy.
                import readline
            except ImportError:
                pass
            else:
                # We don't have to wrap the following import in a 'try', because
                # we already know 'readline' was imported successfully.
                import rlcompleter
                readline.set_completer(rlcompleter.Completer(imported_objects).complete)
                readline.parse_and_bind("tab:complete")

            # We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system
            # conventions and get $PYTHONSTARTUP first then .pythonrc.py.
            if not options['no_startup']:
                for pythonrc in (os.environ.get("PYTHONSTARTUP"), '~/.pythonrc.py'):
                    if not pythonrc:
                        continue
                    pythonrc = os.path.expanduser(pythonrc)
                    if not os.path.isfile(pythonrc):
                        continue
                    try:
                        with open(pythonrc) as handle:
                            exec(compile(handle.read(), pythonrc, 'exec'), imported_objects)
                    except NameError:
                        pass
            code.interact(local=imported_objects) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:41,代码来源:shell.py

示例11: __exec_py

# 需要导入模块: import rlcompleter [as 别名]
# 或者: from rlcompleter import Completer [as 别名]
def __exec_py(self, args):
        ns = {"api": self.api, "args": args[1:], "analyzer": self.analyzer}
        ns.update(EXPORTED_SYMBOLS)
        if len(args) > 1:
            if args[1].startswith("!"):
                args[1] = "%s/%s" % (PLASMA_SCRIPTS_DIR, args[1][1:])
            exec(open(args[1]).read(), ns)
        else:
            readline.set_completer(rlcompleter.Completer(ns).complete)
            code.interact(local=ns)
            readline.set_completer(self.comp.complete) 
开发者ID:plasma-disassembler,项目名称:plasma,代码行数:13,代码来源:console.py

示例12: setUp

# 需要导入模块: import rlcompleter [as 别名]
# 或者: from rlcompleter import Completer [as 别名]
def setUp(self):
        self.stdcompleter = rlcompleter.Completer()
        self.completer = rlcompleter.Completer(dict(spam=int,
                                                    egg=str,
                                                    CompleteMe=CompleteMe))

        # forces stdcompleter to bind builtins namespace
        self.stdcompleter.complete('', 0) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_rlcompleter.py

示例13: test_namespace

# 需要导入模块: import rlcompleter [as 别名]
# 或者: from rlcompleter import Completer [as 别名]
def test_namespace(self):
        class A(dict):
            pass
        class B(list):
            pass

        self.assertTrue(self.stdcompleter.use_main_ns)
        self.assertFalse(self.completer.use_main_ns)
        self.assertFalse(rlcompleter.Completer(A()).use_main_ns)
        self.assertRaises(TypeError, rlcompleter.Completer, B((1,))) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_rlcompleter.py

示例14: test_excessive_getattr

# 需要导入模块: import rlcompleter [as 别名]
# 或者: from rlcompleter import Completer [as 别名]
def test_excessive_getattr(self):
        # Ensure getattr() is invoked no more than once per attribute
        class Foo:
            calls = 0
            @property
            def bar(self):
                self.calls += 1
                return None
        f = Foo()
        completer = rlcompleter.Completer(dict(f=f))
        self.assertEqual(completer.complete('f.b', 0), 'f.bar')
        self.assertEqual(f.calls, 1) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:14,代码来源:test_rlcompleter.py

示例15: global_matches

# 需要导入模块: import rlcompleter [as 别名]
# 或者: from rlcompleter import Completer [as 别名]
def global_matches( self, text ):
         matches = rlcompleter.Completer.global_matches( self, text )
         if not matches: matches = []
         matches += self.file_matches( text )
         return matches 
开发者ID:dnanexus,项目名称:parliament2,代码行数:7,代码来源:ROOT.py


注:本文中的rlcompleter.Completer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。