本文整理汇总了Python中sys.__stdin__方法的典型用法代码示例。如果您正苦于以下问题:Python sys.__stdin__方法的具体用法?Python sys.__stdin__怎么用?Python sys.__stdin__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sys
的用法示例。
在下文中一共展示了sys.__stdin__方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: win_getpass
# 需要导入模块: import sys [as 别名]
# 或者: from sys import __stdin__ [as 别名]
def win_getpass(prompt='Password: ', stream=None):
"""Prompt for password with echo off, using Windows getch()."""
if sys.stdin is not sys.__stdin__:
return fallback_getpass(prompt, stream)
import msvcrt
for c in prompt:
msvcrt.putch(c)
pw = ""
while 1:
c = msvcrt.getch()
if c == '\r' or c == '\n':
break
if c == '\003':
raise KeyboardInterrupt
if c == '\b':
pw = pw[:-1]
else:
pw = pw + c
msvcrt.putch('\r')
msvcrt.putch('\n')
return pw
示例2: _do_backtick
# 需要导入模块: import sys [as 别名]
# 或者: from sys import __stdin__ [as 别名]
def _do_backtick(self, c, fsm):
if fsm.arg:
self.arg_list.append(fsm.arg)
fsm.arg = ''
io = StringIO()
sys.stdout.flush()
sys.stdout = sys.stdin = io
try:
subcmd = self._cmd.subshell(io)
subparser = CommandParser(subcmd, self._logfile)
try:
subparser.feed(self.arg_list.pop()+"\n")
except:
ex, val, tb = sys.exc_info()
print >>sys.stderr, " *** %s (%s)" % (ex, val)
finally:
sys.stdout = sys.__stdout__
sys.stdin = sys.__stdin__
fsm.arg += io.getvalue().strip()
# get a cli built from sys.argv
示例3: _do_backtick
# 需要导入模块: import sys [as 别名]
# 或者: from sys import __stdin__ [as 别名]
def _do_backtick(self, c, fsm):
if fsm.arg:
self.arg_list.append(fsm.arg)
fsm.arg = ''
io = BytesIO()
sys.stdout.flush()
sys.stdout = sys.stdin = io
try:
subcmd = self._cmd.subshell(io)
subparser = CommandParser(subcmd, self._logfile)
try:
subparser.feed(self.arg_list.pop()+"\n")
except:
ex, val, tb = sys.exc_info()
print(" *** %s (%s)" % (ex, val), file=sys.stderr)
finally:
sys.stdout = sys.__stdout__
sys.stdin = sys.__stdin__
fsm.arg += io.getvalue().strip()
# get a cli built from sys.argv
示例4: win_getpass
# 需要导入模块: import sys [as 别名]
# 或者: from sys import __stdin__ [as 别名]
def win_getpass(prompt='Password: ', stream=None):
"""Prompt for password with echo off, using Windows getch()."""
if sys.stdin is not sys.__stdin__:
return fallback_getpass(prompt, stream)
for c in prompt:
msvcrt.putwch(c)
pw = ""
while 1:
c = msvcrt.getwch()
if c == '\r' or c == '\n':
break
if c == '\003':
raise KeyboardInterrupt
if c == '\b':
pw = pw[:-1]
else:
pw = pw + c
msvcrt.putwch('\r')
msvcrt.putwch('\n')
return pw
示例5: win_getpass
# 需要导入模块: import sys [as 别名]
# 或者: from sys import __stdin__ [as 别名]
def win_getpass(prompt='Password: ', stream=None):
"""Prompt for password with echo off, using Windows getch()."""
if sys.stdin is not sys.__stdin__:
return fallback_getpass(prompt, stream)
import msvcrt
for c in prompt:
msvcrt.putwch(c)
pw = ""
while 1:
c = msvcrt.getwch()
if c == '\r' or c == '\n':
break
if c == '\003':
raise KeyboardInterrupt
if c == '\b':
pw = pw[:-1]
else:
pw = pw + c
msvcrt.putwch('\r')
msvcrt.putwch('\n')
return pw
示例6: launch
# 需要导入模块: import sys [as 别名]
# 或者: from sys import __stdin__ [as 别名]
def launch(args: List[str]) -> None:
config_dir, kitten = args[:2]
kitten = resolved_kitten(kitten)
del args[:2]
args = [kitten] + args
os.environ['KITTY_CONFIG_DIRECTORY'] = config_dir
from kittens.tui.operations import clear_screen, reset_mode
set_debug(kitten)
m = import_kitten_main_module(config_dir, kitten)
try:
result = m['start'](args)
finally:
sys.stdin = sys.__stdin__
print(reset_mode('ALTERNATE_SCREEN') + clear_screen(), end='')
if result is not None:
import json
data = json.dumps(result)
print('OK:', len(data), data)
sys.stderr.flush()
sys.stdout.flush()
示例7: onecmd
# 需要导入模块: import sys [as 别名]
# 或者: from sys import __stdin__ [as 别名]
def onecmd(self,line):
cmd,arg,line = self.parseline(line)
if not line: return self.emptyline()
if line == 'EOF':
sys.stdin = sys.__stdin__
self._script = self._loaded = 0
return 0
if cmd is None: return self.default(line)
# cmd.Cmd().lastcmd
self.lastcmd = line
if cmd == '': return self.default(line)
else:
try:
# find functions with getattr
function = getattr(self, "do_" + cmd)
except AttributeError as e:
return self.default(line)
return function(arg)
示例8: main
# 需要导入模块: import sys [as 别名]
# 或者: from sys import __stdin__ [as 别名]
def main(debug = False):
try:
sys.stderr.write("\n")
sys.stderr.flush()
except IOError:
class dummyStream:
''' dummyStream behaves like a stream but does nothing. '''
def __init__(self): pass
def write(self,data): pass
def read(self,data): pass
def flush(self): pass
def close(self): pass
# and now redirect all default streams to this dummyStream:
sys.stdout = dummyStream()
sys.stderr = open("errors.txt", "w", 0)
sys.stdin = dummyStream()
sys.__stdout__ = dummyStream()
sys.__stderr__ = dummyStream()
sys.__stdin__ = dummyStream()
menu.mainMenu.Menu()
示例9: Main
# 需要导入模块: import sys [as 别名]
# 或者: from sys import __stdin__ [as 别名]
def Main():
try:
sys.stderr.write("\n")
sys.stderr.flush()
except IOError:
class dummyStream:
''' dummyStream behaves like a stream but does nothing. '''
def __init__(self): pass
def write(self,data): pass
def read(self,data): pass
def flush(self): pass
def close(self): pass
# and now redirect all default streams to this dummyStream:
sys.stdout = dummyStream()
sys.stderr = open("errors.txt", "w", 0)
sys.stdin = dummyStream()
sys.__stdout__ = dummyStream()
sys.__stderr__ = dummyStream()
sys.__stdin__ = dummyStream()
builder.builderWindow.MainFrame()
示例10: win_getpass
# 需要导入模块: import sys [as 别名]
# 或者: from sys import __stdin__ [as 别名]
def win_getpass(prompt='Password: ', stream=None):
"""Prompt for password with echo off, using Windows getch()."""
if sys.stdin is not sys.__stdin__:
return default_getpass(prompt, stream)
import msvcrt
for c in prompt:
msvcrt.putch(c)
pw = ""
while 1:
c = msvcrt.getch()
if c == '\r' or c == '\n':
break
if c == '\003':
raise KeyboardInterrupt
if c == '\b':
pw = pw[:-1]
else:
pw = pw + c
msvcrt.putch('\r')
msvcrt.putch('\n')
return pw
示例11: onecmd
# 需要导入模块: import sys [as 别名]
# 或者: from sys import __stdin__ [as 别名]
def onecmd(self, line):
cmd, arg, line = self.parseline(line)
if not line:
return self.emptyline()
if line == 'EOF':
# reset stdin for raw_input
sys.stdin = sys.__stdin__
Framework._script = 0
Framework._load = 0
return 0
if cmd is None:
return self.default(line)
self.lastcmd = line
if cmd == '':
return self.default(line)
else:
try:
func = getattr(self, 'do_' + cmd)
except AttributeError:
return self.default(line)
return func(arg)
# make help menu more attractive
示例12: _save_file
# 需要导入模块: import sys [as 别名]
# 或者: from sys import __stdin__ [as 别名]
def _save_file(pickler, obj, open_):
obj.flush()
if obj.closed:
position = None
else:
if obj in (sys.__stdout__, sys.__stderr__, sys.__stdin__):
position = -1
else:
position = obj.tell()
if is_dill(pickler) and pickler._fmode == FILE_FMODE:
f = open_(obj.name, "r")
fdata = f.read()
f.close()
else:
fdata = ""
if is_dill(pickler):
strictio = pickler._strictio
fmode = pickler._fmode
else:
strictio = False
fmode = 0 # HANDLE_FMODE
pickler.save_reduce(_create_filehandle, (obj.name, obj.mode, position,
obj.closed, open_, strictio,
fmode, fdata), obj=obj)
return
示例13: fix_windows_stdout_stderr
# 需要导入模块: import sys [as 别名]
# 或者: from sys import __stdin__ [as 别名]
def fix_windows_stdout_stderr():
"""
Processes can't write to stdout/stderr on frozen windows apps because they do not exist here
if process tries it anyway we get a nasty dialog window popping up, so we redirect the streams to a dummy
see https://github.com/jopohl/urh/issues/370
"""
if hasattr(sys, "frozen") and sys.platform == "win32":
try:
sys.stdout.write("\n")
sys.stdout.flush()
except:
class DummyStream(object):
def __init__(self): pass
def write(self, data): pass
def read(self, data): pass
def flush(self): pass
def close(self): pass
sys.stdout, sys.stderr, sys.stdin = DummyStream(), DummyStream(), DummyStream()
sys.__stdout__, sys.__stderr__, sys.__stdin__ = DummyStream(), DummyStream(), DummyStream()