本文整理汇总了Python中readline.get_completer_delims函数的典型用法代码示例。如果您正苦于以下问题:Python get_completer_delims函数的具体用法?Python get_completer_delims怎么用?Python get_completer_delims使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_completer_delims函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_context_manager_with_unmocked_readline
def test_context_manager_with_unmocked_readline(self):
from letsencrypt.display import completer
reload_module(completer)
original_completer = readline.get_completer()
original_delims = readline.get_completer_delims()
with completer.Completer():
pass
self.assertEqual(readline.get_completer(), original_completer)
self.assertEqual(readline.get_completer_delims(), original_delims)
开发者ID:Advertile,项目名称:letsencrypt,代码行数:12,代码来源:completer_test.py
示例2: startup
def startup():
# python startup file
import readline
import rlcompleter
import atexit
import os
# tab completion
readline.parse_and_bind('tab: complete')
readline.set_completer(completer)
# do not use - as delimiter
old_delims = readline.get_completer_delims() # <-
readline.set_completer_delims(old_delims.replace('-', '')) # <-
# history file
histfile = os.path.join(os.environ['HOME'], '.pythonhistory')
try:
readline.read_history_file(histfile)
except IOError:
pass
atexit.register(readline.write_history_file, histfile)
del os, histfile, readline, rlcompleter
import readline
开发者ID:Jzarecta,项目名称:sentinel,代码行数:25,代码来源:misc.py
示例3: run
def run(self):
""" Start logging shell. """
exit_commands = ['exit', 'Exit', 'EXIT', 'q', 'quit', 'Quit']
pathes = os.getenv('PATH').split(':')
pathes.append('./')
self._commands = []
for path in pathes:
out, err = self._execute('ls %(path)s' % {'path': path})
self._commands.extend(out.split('\n'))
self._commands.extend(exit_commands)
self._commands.sort()
readline.set_completer(self.complete)
original_delims = readline.get_completer_delims()
new_delims = original_delims.replace('.', '').replace('/', '')
readline.set_completer_delims(new_delims)
print 'Start logging to "%(file)s"' % {'file': self._file.name}
print 'exit logging by typing one of %(exit)s' % \
{'exit': exit_commands}
readline.parse_and_bind('tab: complete')
stdin = raw_input(self._prefix)
while (stdin not in exit_commands):
try:
self.execute(stdin)
stdin = raw_input(self._prefix)
except EOFError:
print 'The input file has finished reading.'
break
print 'End logging. Log file is "%(file)s"' % {'file': self._file.name}
开发者ID:FumihikoKouno,项目名称:Tools,代码行数:28,代码来源:myshell.py
示例4: initialize
def initialize(self, region='us-west-1', host='localhost', port=8000,
access_key=None, secret_key=None, config_dir=None):
""" Set up the repl for execution. """
# Tab-complete names with a '-' in them
import readline
delims = set(readline.get_completer_delims())
if '-' in delims:
delims.remove('-')
readline.set_completer_delims(''.join(delims))
self._conf_dir = (config_dir or
os.path.join(os.environ.get('HOME', '.'), '.config'))
self.session = botocore.session.get_session()
if access_key:
self.session.set_credentials(access_key, secret_key)
if region == 'local':
conn = DynamoDBConnection.connect_to_host(host, port,
session=self.session)
else:
conn = DynamoDBConnection.connect_to_region(region, self.session)
self.engine = FragmentEngine(conn)
conf = self.load_config()
display_name = conf.get('display')
if display_name is not None:
self.display = DISPLAYS[display_name]
else:
self.display = get_default_display()
self.formatter = SmartFormat(pagesize=conf.get('pagesize', 1000),
width=conf.get('width', 80))
for line in conf.get('autorun', []):
six.exec_(line, self.engine.scope)
开发者ID:cce,项目名称:dql,代码行数:32,代码来源:cli.py
示例5: __init__
def __init__(self, admin_cli):
# remove stdout stream encoding while in 'shell' mode, becuase this breaks readline
# (autocompletion and shell history). In 'shell' mode the stdout
# is encoded just for time necessary for command execution see precmd a postcmd
sys.stdout = stdout_origin
self.stdout_with_codec = encode_stream(sys.stdout, "utf-8")
self.completion_matches = None
Cmd.__init__(self)
self.admin_cli = admin_cli
self.completion = Completion(self.admin_cli)
try:
Config()
self.prompt = Config.parser.get('shell', 'prompt') + ' '
except (ConfigFileError, ConfigParser.Error):
self.prompt = 'katello> '
try:
# don't split on hyphens during tab completion (important for completing parameters)
newdelims = readline.get_completer_delims()
newdelims = re.sub('-', '', newdelims)
readline.set_completer_delims(newdelims)
if (Config.parser.get('shell', 'nohistory').lower() != 'true'):
self.__init_history()
except ConfigParser.Error:
pass
self.__init_commands()
开发者ID:bcrochet,项目名称:katello,代码行数:29,代码来源:shell.py
示例6: cmdloop
def cmdloop(self, intro=None):
self.old_completer = readline.get_completer()
self.old_completer_delims = readline.get_completer_delims()
readline.set_completer(self.complete)
readline.parse_and_bind(self.completekey+": complete")
readline.parse_and_bind("set bell-style none")
readline.parse_and_bind("set show-all-if-ambiguous")
readline.parse_and_bind("set completion-query-items -1")
# If press help key, add the character and accept the line
readline.parse_and_bind('"?": "\C-q?\C-j"')
# Register a function for execute before read user
# input. We can use it for insert text at command line
readline.set_pre_input_hook(self.pre_input_hook)
readline.set_completer_delims(' \t\n')
try:
stop = None
while not stop:
try:
line = raw_input(self.prompt)
except EOFError:
line = 'EOF'
stop = self.onecmd(line)
stop = self.postcmd(stop, line)
finally:
readline.set_completer(self.old_completer)
readline.set_completer_delims(self.old_completer_delims)
开发者ID:aleasoluciones,项目名称:boscli-oss-core,代码行数:29,代码来源:boscli.py
示例7: sftp_cmd
def sftp_cmd(*args):
sftp = Channel.get_instance().get_transport().open_sftp_client()
old_completer = readline.get_completer()
readline.set_completer(sftp_completer(sftp))
old_delim = readline.get_completer_delims()
readline.set_completer_delims(' /')
global rcwd
try:
try:
cmd = raw_input('SFTP> ')
except EOFError:
return
except KeyboardInterrupt:
return
while not cmd or not 'quit'.startswith(cmd):
args = [x for x in cmd.split(' ') if x]
if args and args[0] in all_cmd:
all_cmd[args[0]](sftp, args)
else:
print('invalid command')
try:
cmd = raw_input('SFTP> ')
except EOFError:
return
except KeyboardInterrupt:
return
finally:
readline.set_completer(old_completer)
readline.set_completer_delims(old_delim)
开发者ID:simpoir,项目名称:reach,代码行数:31,代码来源:sftp.py
示例8: exec_cmdloop
def exec_cmdloop(self, args, options):
try:
import readline
delims = readline.get_completer_delims()
delims = delims.replace(':', '') # "group:process" as one word
delims = delims.replace('*', '') # "group:*" as one word
delims = delims.replace('-', '') # names with "-" as one word
readline.set_completer_delims(delims)
if options.history_file:
try:
readline.read_history_file(options.history_file)
except IOError:
pass
def save():
try:
readline.write_history_file(options.history_file)
except IOError:
pass
import atexit
atexit.register(save)
except ImportError:
pass
try:
self.cmdqueue.append('status')
self.cmdloop()
except KeyboardInterrupt:
self.output('')
pass
开发者ID:maoshuyu,项目名称:supervisor,代码行数:31,代码来源:supervisorctl.py
示例9: rlinput
def rlinput(prompt, prefill='', oneline=False, ctxkey=''):
"""
Get user input with readline editing support.
"""
sentinel = ''
if prefill is None:
prefill = ''
def only_once(text):
""" generator for startup hook """
readline.insert_text(text)
yield
while True:
yield
savedhist = NamedTemporaryFile()
readline.write_history_file(savedhist.name)
ctxhistname = ".tl" + ctxkey + "history"
ctxhistfile = os.path.join(G.ProjectFolder, ctxhistname)
try:
readline.clear_history()
except AttributeError:
print "This readline doesn't support clear_history()"
raise
savedcompleter = readline.get_completer()
try:
ulines = uniqify(ctxhistfile)
readline.read_history_file(ctxhistfile)
readline.set_completer(HistoryCompleter(ulines).complete)
except IOError:
pass
readline.parse_and_bind('tab: complete')
saveddelims = readline.get_completer_delims()
readline.set_completer_delims('') ## No delims. Complete entire lines.
readline.set_completion_display_matches_hook(match_display_hook)
gen = only_once(prefill)
readline.set_startup_hook(gen.next)
try:
if oneline:
edited = raw_input(prompt)
else:
print prompt
edited = "\n".join(iter(raw_input, sentinel))
if edited.endswith(r'%%'):
## Invoke external editor
edited = external_edit(edited[0:-2])
return edited
finally:
## Restore readline state
readline.write_history_file(ctxhistfile)
readline.clear_history()
readline.read_history_file(savedhist.name)
savedhist.close()
readline.set_completer(savedcompleter)
readline.set_completer_delims(saveddelims)
readline.set_startup_hook()
开发者ID:Michael-F-Ellis,项目名称:TransLily,代码行数:60,代码来源:rl_interface.py
示例10: interact
def interact(PS1, PS2, BANNER, *arg, **kwarg):
def Completer(text, stat):
if text.startswith('.') or text.startswith('/'):
ret = path_matches(text)
elif '.' not in text:
ret = global_matches(text)
else:
ret = attr_matches(text)
try:
return ret[stat]
except IndexError:
return None
@utils.regExitCallback
def exit_interact():
""" Clean all when exit """
print "Goodbye..."
## Compatible for Mac OS since Mac OS ship libedit for readline
if "libedit" in readline.__doc__:
import rlcompleter
readline.parse_and_bind("bind ^I rl_complete")
else:
readline.parse_and_bind("tab: complete")
## Change PS
sys.ps1, sys.ps2 = PS1, PS2
delims = readline.get_completer_delims().replace('/','')
readline.set_completer_delims(delims)
readline.set_completer(Completer)
## Run Interpreter
code.interact(banner=BANNER, local=globals())
开发者ID:cmj0121,项目名称:PyCrack,代码行数:35,代码来源:jpython.py
示例11: launch_ui
def launch_ui(args):
# Setup tab completion
try:
import readline
except ImportError:
print('%s[!] Module \'readline\' not available. Tab complete disabled.%s' % (Colors.R, Colors.N))
else:
import rlcompleter
if 'libedit' in readline.__doc__:
readline.parse_and_bind('bind ^I rl_complete')
else:
readline.parse_and_bind('tab: complete')
readline.set_completer_delims(re.sub('[/-]', '', readline.get_completer_delims()))
# Instantiate the UI object
x = cli.CLI(cli.Mode.CONSOLE)
# check for and run version check
if args.check:
if not x.version_check(): return
# Check for and run script session
if args.script_file:
x.do_resource(args.script_file)
# Run the UI
try:
x.cmdloop()
except KeyboardInterrupt:
print('')
开发者ID:mwrlabs,项目名称:needle,代码行数:26,代码来源:needle.py
示例12: __init__
def __init__(self, verbose=False):
Cmd.__init__(self)
self.pp = pprint.PrettyPrinter(indent=4)
try:
self.conn = boto.connect_dynamodb()
except Exception as e:
self.conn = None
print e
print "Cannot connect to dynamodb - Check your credentials in ~/.boto or use the 'login' command"
# by default readline thinks - and other characters are word delimiters :(
if readline:
readline.set_completer_delims(re.sub('[-~]', '', readline.get_completer_delims()))
path = os.path.join(os.environ.get('HOME', ''), HISTORY_FILE)
self.history_file = os.path.abspath(path)
else:
self.history_file = None
self.tables = []
self.table = None
self.consistent = False
self.consumed = False
self.verbose = verbose
self.next_key = None
self.schema = {}
if verbose:
self._onchange_verbose(None, verbose)
开发者ID:raff,项目名称:dynash,代码行数:31,代码来源:dynash.py
示例13: main
def main(self, argv):
cmd_args = argv[1:]
if cmd_args:
cmd_line = u' '.join(cmd_args)
cmds = cmd_line.split(';')
for cmd in cmds:
ret = self.onecmd(cmd)
if ret:
return ret
elif self.DISABLE_REPL:
self._parser.print_help()
self._parser.exit()
else:
try:
import readline
except ImportError:
pass
else:
# Remove '-' from delims
readline.set_completer_delims(readline.get_completer_delims().replace('-', ''))
history_filepath = os.path.join(self.weboob.workdir, '%s_history' % self.APPNAME)
try:
readline.read_history_file(history_filepath)
except IOError:
pass
def savehist():
readline.write_history_file(history_filepath)
atexit.register(savehist)
self.intro += '\nLoaded backends: %s\n' % ', '.join(sorted(backend.name for backend in self.weboob.iter_backends()))
self._interactive = True
self.cmdloop()
开发者ID:blckshrk,项目名称:Weboob,代码行数:34,代码来源:repl.py
示例14: __init__
def __init__(self, complete_key='tab', prompt='> ', stdin=None, stdout=None):
'''
Instantiate a simple line-oriented interpreter framework.
The optional argument 'complete_key' is the readline name of a
completion key; it defaults to the Tab key ('tab'). If complete_key is
not None, command completion is done by the 'complete()' method. The
optional arguments stdin and stdout specify alternate input and output
file objects; if not specified, sys.stdin and sys.stdout are used.
'''
# key used to trigger autocomplete
self.complete_key = complete_key
self.stdin = stdin or sys.stdin
self.stdout = stdout or sys.stdout
# the prompt issued to the user to gather input
self.prompt = prompt
# delimiters for readline to use during completion
self.completer_delimiters = readline.get_completer_delims()
# the intro displayed before the first prompt is issued
self.intro = None
开发者ID:jasontbradshaw,项目名称:plinth,代码行数:25,代码来源:interpreter.py
示例15: improved_rlcompleter
def improved_rlcompleter(self):
"""Enhances the default rlcompleter
The function enhances the default rlcompleter by also doing
pathname completion and module name completion for import
statements. Additionally, it inserts a tab instead of attempting
completion if there is no preceding text.
"""
completer = rlcompleter.Completer(namespace=self.locals)
# - remove / from the delimiters to help identify possibility for path completion
readline.set_completer_delims(readline.get_completer_delims().replace('/', ''))
modlist = frozenset(name for _, name, _ in pkgutil.iter_modules())
def complete_wrapper(text, state):
line = readline.get_line_buffer().strip()
if line == '':
return None if state > 0 else self.tab
if state == 0:
if line.startswith('import') or line.startswith('from'):
completer.matches = [name for name in modlist if name.startswith(text)]
else:
match = completer.complete(text, state)
if match is None and '/' in text:
completer.matches = glob.glob(text+'*')
try:
match = completer.matches[state]
return '{}{}'.format(match, ' ' if keyword.iskeyword(match) else '')
except IndexError:
return None
return complete_wrapper
开发者ID:jeffbuttars,项目名称:env,代码行数:30,代码来源:pythonrc.py
示例16: __init__
def __init__(self, command_line):
self.status = {}
self.status['log_started'] = False
self.status['resource_found'] = False
self.status['command_line'] = command_line
self.status['file_found'] = False
self.global_config = {}
self.tools = []
self.assessments = []
self.job_queue = []
self.arguments = ddict_options = defaultdict(lambda : '')
self.instance = {}
self.instance['tool'] = []
self.instance['config'] = {}
self.load("tools")
self.load("assessments")
self.load("global_config")
# Remove / from completer delim so tab completion works
# with tool/nmap, for example
old_delims = readline.get_completer_delims()
readline.set_completer_delims(old_delims.replace('/', ''))
开发者ID:rubicondimitri,项目名称:autopwn,代码行数:26,代码来源:__init__.py
示例17: __init__
def __init__(self):
cmd.Cmd.__init__(self)
self.prompt = "BN> "
self.ic = None
default_delims = readline.get_completer_delims()
new_delims = ''.join((c not in '-/[]') and c or ''
for c in default_delims)
readline.set_completer_delims(new_delims)
开发者ID:edarc,项目名称:birdnest,代码行数:8,代码来源:cl.py
示例18: setup_readline
def setup_readline():
readline.set_history_length(100)
readline.parse_and_bind("tab: complete")
readline.set_completer(completer)
readline.set_completer_delims(\
readline.get_completer_delims().replace('-','').replace('/','').replace('=',''))
try: readline.read_history_file(vars.hist_file)
except: pass
开发者ID:brhellman,项目名称:pacemaker,代码行数:8,代码来源:completion.py
示例19: configure_readline
def configure_readline():
"""Configure the readline module"""
if rlmodule is not None: # pragma: no cover
delims = list(rlmodule.get_completer_delims())
for char in {'-', '"', "'", '!', '@', '?'}:
if char in delims:
delims.remove(char)
rlmodule.set_completer_delims(''.join(delims))
开发者ID:simone-campagna,项目名称:shells-kitchen,代码行数:8,代码来源:utils.py
示例20: main
def main():
readline.set_completer(compl1)
print(readline.get_completer_delims())
while True:
s = input("input str: ")
print(s)
print("buf: " + readline.get_line_buffer())
if s == "quit":
break
开发者ID:10sr,项目名称:junks,代码行数:9,代码来源:main.py
注:本文中的readline.get_completer_delims函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论