本文整理匯總了Python中readline.get_completer方法的典型用法代碼示例。如果您正苦於以下問題:Python readline.get_completer方法的具體用法?Python readline.get_completer怎麽用?Python readline.get_completer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類readline
的用法示例。
在下文中一共展示了readline.get_completer方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import get_completer [as 別名]
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)
示例2: do_python
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import get_completer [as 別名]
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
示例3: _cmdloop
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import get_completer [as 別名]
def _cmdloop(self, intro=None):
"""Repeatedly issue a prompt, accept input, parse an initial prefix
off the received input, and dispatch to action methods, passing them
the remainder of the line as argument.
"""
# An almost perfect copy from Cmd; however, the pseudo_raw_input portion
# has been split out so that it can be called separately
self.preloop()
if self.use_rawinput and self.completekey:
try:
import readline
self.old_completer = readline.get_completer()
readline.set_completer(self.complete)
readline.parse_and_bind(self.completekey+": complete")
except ImportError:
pass
try:
if intro is not None:
self.intro = intro
if self.intro:
self.stdout.write(str(self.intro)+"\n")
stop = None
while not stop:
if self.cmdqueue:
line = self.cmdqueue.pop(0)
else:
line = self.pseudo_raw_input(self.prompt)
if (self.echo) and (isinstance(self.stdin, file)):
self.stdout.write(line + '\n')
stop = self.onecmd_plus_hooks(line)
self.postloop()
finally:
if self.use_rawinput and self.completekey:
try:
import readline
readline.set_completer(self.old_completer)
except ImportError:
pass
return stop
示例4: loop
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import get_completer [as 別名]
def loop(self):
previous_completer = readline.get_completer()
readline.parse_and_bind("tab: complete")
readline.set_completer(self.walk)
prompt = self.prompt + self.prompt_delim
if not ishell._current_prompt:
previous_prompt = prompt
else:
previous_prompt = ishell._current_prompt
ishell._current_prompt = prompt
if self.welcome_message:
sys.stdout.write(self.welcome_message + "\n\r")
while 1:
try:
sys.stdout.write("\r")
if self._exit:
break
sys.stdout.write("\033[K")
input_ = input(prompt + " ")
if not input_.strip():
self.print_childs_help()
elif input_ in ('quit', 'exit'):
break
else:
self.walk_and_run(input_)
except (KeyboardInterrupt, EOFError):
print("exit")
break
except Exception:
print(traceback.format_exc())
sys.exit(1)
ishell._current_prompt = previous_prompt
readline.set_completer(previous_completer)
示例5: _cmdloop
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import get_completer [as 別名]
def _cmdloop(self, intro=None):
"""Repeatedly issue a prompt, accept input, parse an initial prefix
off the received input, and dispatch to action methods, passing them
the remainder of the line as argument.
"""
# An almost perfect copy from Cmd; however, the pseudo_raw_input portion
# has been split out so that it can be called separately
self.preloop()
if self.use_rawinput and self.completekey:
try:
import readline
self.old_completer = readline.get_completer()
readline.set_completer(self.complete)
readline.parse_and_bind(self.completekey+": complete")
except ImportError:
pass
try:
if intro is not None:
self.intro = intro
if self.intro:
self.stdout.write(str(self.intro)+"\n")
stop = None
while not stop:
if self.cmdqueue:
line = self.cmdqueue.pop(0)
else:
line = self.pseudo_raw_input(self.prompt)
if (self.echo) and (isinstance(self.stdin, file)):
self.stdout.write(line + '\n')
stop = self.onecmd_plus_hooks(line)
self.postloop()
finally:
if self.use_rawinput and self.completekey:
try:
import readline
readline.set_completer(self.old_completer)
except ImportError:
pass
return stop
示例6: set_readline
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import get_completer [as 別名]
def set_readline(self):
if not objectmodel.we_are_translated():
self.old_completer = readline.get_completer()
self.old_delims = readline.get_completer_delims()
readline.set_completer(completer)
readline.set_completer_delims("\t ")
示例7: cmdloop
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import get_completer [as 別名]
def cmdloop(self, intro=None):
"""Repeatedly issue a prompt, accept input, parse an initial prefix
off the received input, and dispatch to action methods, passing them
the remainder of the line as argument.
"""
self.preloop()
if self.use_rawinput and self.completekey:
try:
import readline
self.old_completer = readline.get_completer()
readline.set_completer(self.complete)
readline.parse_and_bind(self.completekey+": complete")
except ImportError:
pass
try:
if intro is not None:
self.intro = intro
if self.intro:
self.stdout.write(str(self.intro)+"\n")
stop = None
while not stop:
if self.cmdqueue:
line = self.cmdqueue.pop(0)
else:
if self.use_rawinput:
try:
line = raw_input(self.prompt)
except EOFError:
line = 'EOF'
else:
self.stdout.write(self.prompt)
self.stdout.flush()
line = self.stdin.readline()
if not len(line):
line = 'EOF'
else:
line = line.rstrip('\r\n')
line = self.precmd(line)
stop = self.onecmd(line)
stop = self.postcmd(stop, line)
self.postloop()
finally:
if self.use_rawinput and self.completekey:
try:
import readline
readline.set_completer(self.old_completer)
except ImportError:
pass
示例8: isolate_io_context
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import get_completer [as 別名]
def isolate_io_context(function):
"""A decorator for separating I/O context.
This decorator isolates I/O context of target
function or method.
I/O Context is a mix of terminal related elements,
such as current stdout and readline completer
attributes.
This decorator is useful if you run something
that reconfigures the readline completer, or
needs to use the default stdout file descriptor
instead of the phpsploit's stdout wrapper.
"""
def wrapper(*args, **kwargs):
try:
import readline
handle_readline = True
except ImportError:
handle_readline = False
if handle_readline:
# backup & reset readline completer
old_readline_completer = readline.get_completer()
readline.set_completer((lambda x: x))
# backup & reset readline history
old_readline_history = []
hist_sz = readline.get_current_history_length()
for i in range(1, hist_sz + 1):
line = readline.get_history_item(i)
old_readline_history.append(line)
readline.clear_history()
# backup & reset stdout
old_stdout = sys.stdout
sys.stdout = sys.__stdout__
try:
retval = function(*args, **kwargs)
finally:
if handle_readline:
# restore old readline completer
readline.set_completer(old_readline_completer)
# restore old readline history
readline.clear_history()
for line in old_readline_history:
readline.add_history(line)
# restore old stdout
sys.stdout = old_stdout
return retval
return wrapper
示例9: isolate_readline_context
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import get_completer [as 別名]
def isolate_readline_context(function):
"""A decorator for separating readline context.
This decorator isolates readline context of target
function or method.
Use when phpsploit's readline context should be
reset temporarly is the context of triggering
function or method.
Unlike `isolate_io_context`, this decorator keeps
original stdout wrapper.
"""
def wrapper(*args, **kwargs):
try:
import readline
handle_readline = True
except ImportError:
handle_readline = False
if handle_readline:
# backup & reset readline completer
old_readline_completer = readline.get_completer()
readline.set_completer((lambda x: x))
# backup & reset readline history
old_readline_history = []
hist_sz = readline.get_current_history_length()
for i in range(1, hist_sz + 1):
line = readline.get_history_item(i)
old_readline_history.append(line)
readline.clear_history()
try:
retval = function(*args, **kwargs)
finally:
if handle_readline:
# restore old readline completer
readline.set_completer(old_readline_completer)
# restore old readline history
readline.clear_history()
for line in old_readline_history:
readline.add_history(line)
return retval
return wrapper
示例10: cmdloop
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import get_completer [as 別名]
def cmdloop(self, intro=None):
"""Repeatedly issue a prompt, accept input, parse an initial prefix
off the received input, and dispatch to action methods, passing them
the remainder of the line as argument.
"""
# try to load readline (if available)
if self.completekey:
try:
import readline
self.old_completer = readline.get_completer()
readline.set_completer(self.complete)
readline.parse_and_bind(self.completekey+": complete")
except ImportError:
pass
# print intro message (if any)
if intro:
self.intro = intro
if self.intro:
self.stdout.write(str(self.intro) + "\n")
# start command loop
try:
self.preloop() # pre command hook method
while True:
try:
line = self.raw_input(self.prompt)
except EOFError:
self.stdout.write("\n")
line = "exit"
except BaseException as err:
# nothing to interpret on exception
self.onexception(err)
continue
try:
self.interpret(line, interactive=True)
# system exit is the correct way to leave loop
except SystemExit as err:
return err.code
# restore readline completer (if used)
finally:
if self.completekey:
try:
import readline
readline.set_completer(self.old_completer)
except ImportError:
pass
self.postloop() # post command hook method
示例11: imgur
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import get_completer [as 別名]
def imgur(jarvis, s):
"""
Uploads an image to imgur
"""
# Autocomplete filename
jarvis.say("What's the image name?: ")
readline.set_completer_delims(' \t\n;')
readline.parse_and_bind("tab: complete")
r = readline.get_completer()
readline.set_completer(complete)
file = jarvis.input('')
# Get the absolute path
file = os.path.abspath(file)
file = os.path.expanduser(file)
if os.path.isfile(file):
try:
url = "https://api.imgur.com/3/image"
headers = {"Authorization": "Client-ID 145b6ea95cf11b4"}
# Send POST
resp = requests.post(
url,
headers=headers,
data={
'image': base64.b64encode(open(file, 'rb').read()),
'type': 'base64'
}
)
objresp = json.loads(resp.text)
# Treat response
if objresp.get('success', False):
jarvis.say('Here is your image: '
+ str(objresp['data']['link']))
else:
jarvis.say('Error: ' + str(objresp['data']['error']))
except Exception as e:
# Print exception as string
jarvis.say("Error {0}".format(str(e.args[0])).encode("utf-8"))
else:
jarvis.say("No such file")
readline.set_completer(r)
示例12: cmdloop
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import get_completer [as 別名]
def cmdloop(self, intro=None):
"""Repeatedly issue a prompt, accept input, parse an initial prefix
off the received input, and dispatch to action methods, passing them
the remainder of the line as argument.
"""
self.preloop()
if self.use_rawinput and self.completekey:
try:
import readline
self.old_completer = readline.get_completer()
readline.set_completer(self.complete)
readline.parse_and_bind(self.completekey+": complete")
except ImportError:
pass
try:
if intro is not None:
self.intro = intro
if self.intro:
self.stdout.write(str(self.intro)+"\n")
stop = None
while not stop:
if self.cmdqueue:
line = self.cmdqueue.pop(0)
else:
self.preinput()
if self.use_rawinput:
try:
line = input(self.prompt)
except EOFError:
line = 'EOF'
else:
self.stdout.write(self.prompt)
self.stdout.flush()
line = self.stdin.readline()
if not len(line):
line = 'EOF'
else:
line = line[:-1] # chop \n
line = self.postinput(line)
line = self.precmd(line)
stop = self.onecmd(line)
stop = self.postcmd(stop, line)
self.postloop()
finally:
if self.use_rawinput and self.completekey:
try:
import readline
readline.set_completer(self.old_completer)
except ImportError:
pass
示例13: cmdloop
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import get_completer [as 別名]
def cmdloop(self, intro=None):
"""Repeatedly issue a prompt, accept input, parse an initial prefix
off the received input, and dispatch to action methods, passing them
the remainder of the line as argument.
"""
self.preloop()
if self.use_rawinput and self.completekey:
try:
import readline
self.old_completer = readline.get_completer()
readline.set_completer(self.complete)
readline.parse_and_bind(self.completekey+": complete")
except ImportError:
pass
try:
if intro is not None:
self.intro = intro
if self.intro:
self.stdout.write(str(self.intro)+"\n")
stop = None
while not stop:
if self.cmdqueue:
line = self.cmdqueue.pop(0)
else:
if self.use_rawinput:
try:
line = input(self.prompt)
except EOFError:
line = 'EOF'
else:
self.stdout.write(self.prompt)
self.stdout.flush()
line = self.stdin.readline()
if not len(line):
line = 'EOF'
else:
line = line.rstrip('\r\n')
line = self.precmd(line)
stop = self.onecmd(line)
stop = self.postcmd(stop, line)
self.postloop()
finally:
if self.use_rawinput and self.completekey:
try:
import readline
readline.set_completer(self.old_completer)
except ImportError:
pass
示例14: cmdloop
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import get_completer [as 別名]
def cmdloop(self, intro=None):
"""Repeatedly issue a prompt, accept input, parse an initial prefix
off the received input, and dispatch to action methods, passing them
the remainder of the line as argument.
"""
# Custom change: added hadling for ctrl+c
self.preloop()
if self.use_rawinput and self.completekey:
try:
import readline
self.old_completer = readline.get_completer()
readline.set_completer(self.complete)
readline.parse_and_bind(self.completekey+": complete")
except ImportError:
pass
try:
if intro is not None:
self.intro = intro
if self.intro:
self.stdout.write(str(self.intro)+"\n")
stop = None
while not stop:
try:
if self.cmdqueue:
line = self.cmdqueue.pop(0)
else:
if self.use_rawinput:
try:
line = raw_input(self.prompt)
except EOFError:
line = 'EOF'
else:
self.stdout.write(self.prompt)
self.stdout.flush()
line = self.stdin.readline()
if not len(line):
line = 'EOF'
else:
line = line.rstrip('\r\n')
line = self.precmd(line)
stop = self.onecmd(line)
stop = self.postcmd(stop, line)
except KeyboardInterrupt:
print("^C")
self.postloop()
finally:
if self.use_rawinput and self.completekey:
try:
import readline
readline.set_completer(self.old_completer)
except ImportError:
pass
示例15: run_interactive_gtp_session
# 需要導入模塊: import readline [as 別名]
# 或者: from readline import get_completer [as 別名]
def run_interactive_gtp_session(engine):
"""Run a GTP engine session on stdin and stdout, using readline.
engine -- Gtp_engine_protocol object
This enables readline tab-expansion, and command history in
~/.gomill-gtp-history (if readline is available).
Returns either when EOF is seen on stdin, or when the engine signals end of
session.
If stdin isn't a terminal, this is equivalent to run_gtp_session.
If a write fails with 'broken pipe', this raises ControllerDisconnected.
Note that this will propagate KeyboardInterrupt if the user presses ^C;
normally you'll want to handle this to avoid an ugly traceback.
"""
# readline doesn't do anything if stdin isn't a tty, but it's simplest to
# just not import it in that case.
try:
use_readline = os.isatty(sys.stdin.fileno())
if use_readline:
import readline
except Exception:
use_readline = False
if not use_readline:
run_gtp_session(engine, sys.stdin, sys.stdout)
return
def write(s):
sys.stdout.write(s)
sys.stdout.flush()
history_pathname = os.path.expanduser("~/.gomill-gtp-history")
readline.parse_and_bind("tab: complete")
old_completer = readline.get_completer()
old_delims = readline.get_completer_delims()
readline.set_completer(make_readline_completer(engine))
readline.set_completer_delims("")
try:
readline.read_history_file(history_pathname)
except EnvironmentError:
pass
_run_gtp_session(engine, raw_input, write)
try:
readline.write_history_file(history_pathname)
except EnvironmentError:
pass
readline.set_completer(old_completer)
readline.set_completer_delims(old_delims)