本文整理汇总了Python中tty.setcbreak函数的典型用法代码示例。如果您正苦于以下问题:Python setcbreak函数的具体用法?Python setcbreak怎么用?Python setcbreak使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setcbreak函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __enter__
def __enter__(self):
self._attr = termios.tcgetattr(sys.stdin)
tty.setcbreak(sys.stdin.fileno())
new = termios.tcgetattr(sys.stdin)
new[0] &= ~termios.ICRNL
termios.tcsetattr(sys.stdin.fileno(), termios.TCSADRAIN, new)
return self
开发者ID:alonbl,项目名称:network-course,代码行数:7,代码来源:gutil.py
示例2: handle
def handle(self):
print "\n[!!] [email protected]# -> shell from %s" % self.client_address[0]
print "[**] This shell is powered by insane amounts of illegal substances"
s = self.request
import termios, tty, select, os
old_settings = termios.tcgetattr(0)
try:
tty.setcbreak(0)
c = True
os.write(s.fileno(), "id\nuname -a\n")
while c:
for i in select.select([0, s.fileno()], [], [], 0)[0]:
c = os.read(i, 1024)
if c:
if i == 0:
os.write(1, c)
os.write(s.fileno() if i == 0 else 1, c)
except KeyboardInterrupt: pass
finally: termios.tcsetattr(0, termios.TCSADRAIN, old_settings)
return
开发者ID:309972460,项目名称:software,代码行数:27,代码来源:Nagios-history.cgi-Exec-Code.py
示例3: getOneKey
def getOneKey():
try:
tty.setcbreak(sys.stdin.fileno())
ch = sys.stdin.read(1)
return ord(ch)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
开发者ID:Insaida,项目名称:attendance,代码行数:7,代码来源:attendance.py
示例4: posix_shell
def posix_shell(chan):
import select
oldtty = termios.tcgetattr(sys.stdin)
try:
tty.setraw(sys.stdin.fileno())
tty.setcbreak(sys.stdin.fileno())
chan.settimeout(0.0)
while True:
r, w, e = select.select([chan, sys.stdin], [], [])
if chan in r:
try:
x = u(chan.recv(1024))
if len(x) == 0:
sys.stdout.write('\r\n*** EOF\r\n')
break
sys.stdout.write(x)
sys.stdout.flush()
except socket.timeout:
pass
if sys.stdin in r:
x = sys.stdin.read(1)
if len(x) == 0:
break
chan.send(x)
finally:
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty)
开发者ID:huyuedong,项目名称:s14,代码行数:29,代码来源:interactive.py
示例5: __init__
def __init__(self, key='q', timeout=0):
"""Initialize. Specify key and timeout. Put terminal into cbreak mode."""
#
# To do:
# --> enable key combinations (e.g., CTRL+q)
# --> enable special keys (e.g., ESC)"""
#
# get key
if len(key) != 1:
raise ValueError('invalid key')
self.key = key
### how to use the ESC key?
# enable this class
self.disabled = False
# initialize the "aborted" flag
self.aborted = False
# initialize other attributes
try:
self.oldattr = termios.tcgetattr(sys.stdin)
except:
self.disabled = True # disable, probably does not work with nohup
return
self.buff = '' # collect all other pressed keys, in case needed
self.timeout = timeout
self.count = 0 # count the total number of checks made
# enter cbreak mode
tty.setcbreak(sys.stdin.fileno())
开发者ID:proggy,项目名称:progress,代码行数:33,代码来源:__init__.py
示例6: print_ansi
def print_ansi(self):
"""Controls the printing of the ANSI art."""
self._output.write(self.prepare_screen())
tty.setcbreak(sys.stdin.fileno())
while True:
character = self._source_ansi.read(1)
if not character:
break
# DOS EOF, after it comes SAUCE metadata.
if character == '\x1a':
break
self._output.write(self.process(character, self._source_ansi))
position = self.position_reporter.get_position_report()
# this is bugged after processing newlines.
if position['col'] != self.screen.cursor['col']:
message = ("wrong pos ({}, {}), processed to {}, actual row: {} "
"col: {}")
row = self.screen.cursor['row']
col = self.screen.cursor['col']
offset = self._source_ansi.tell()
rrow = position['row']
rcol = position['col']
self.logger.warn(message.format(row, col, offset, rrow, rcol))
self._output.write(self.close_screen())
开发者ID:ajsalminen,项目名称:ansaconv,代码行数:26,代码来源:ansi_art_converter.py
示例7: handle
def handle(self):
global do_brute
print "\n[!] connectback shell from %s" % self.client_address[0]
do_brute = False
s = self.request
import termios, tty, select, os
old_settings = termios.tcgetattr(0)
try:
tty.setcbreak(0)
c = True
while c:
for i in select.select([0, s.fileno()], [], [], 0)[0]:
c = os.read(i, 1024)
if c:
if i == 0:
os.write(1, c)
os.write(s.fileno() if i == 0 else 1, c)
except KeyboardInterrupt: pass
finally: termios.tcsetattr(0, termios.TCSADRAIN, old_settings)
return
开发者ID:0x24bin,项目名称:exploit-database,代码行数:25,代码来源:37834.py
示例8: posix_shell
def posix_shell(chan,ip,username,group): #unix交互
import select
oldtty = termios.tcgetattr(sys.stdin)
try:
tty.setraw(sys.stdin.fileno())
tty.setcbreak(sys.stdin.fileno())
chan.settimeout(0.0)
while True:
r, w, e = select.select([chan, sys.stdin], [], [])
if chan in r:
try:
x = chan.recv(1024)
if len(x) == 0:
print '\r\n*** EOF\r\n',
break
sys.stdout.write(x)
sys.stdout.flush()
except socket.timeout:
pass
logger(ip,username,group,x)
if sys.stdin in r:
x = sys.stdin.read(1) #写入日志
if len(x) == 0:
break
chan.send(x)
finally:
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty)
开发者ID:99649952,项目名称:practice,代码行数:31,代码来源:interactive.py
示例9: term
def term(ssh_channel):
oldtty = termios.tcgetattr(sys.stdin)
try:
tty.setraw(sys.stdin.fileno())
tty.setcbreak(sys.stdin.fileno())
ssh_channel.settimeout(0.0)
while True:
r, w, e = select.select([ssh_channel, sys.stdin], [], [])
if ssh_channel in r:
try:
x = u(ssh_channel.recv(1024))
if len(x) == 0:
sys.stdout.write('\r\n - Exit SSH Shell -\r\n')
break
sys.stdout.write(x)
sys.stdout.flush()
except socket.timeout:
pass
if sys.stdin in r:
x = sys.stdin.read(1)
if len(x) == 0:
break
ssh_channel.send(x)
finally:
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty)
开发者ID:rpurizaca,项目名称:python-programming,代码行数:27,代码来源:fortigate.py
示例10: unbuffered_input
def unbuffered_input(self):
'''Context manager for setting the terminal to use unbuffered input.
Normally, your terminal will collect together a user's input
keystrokes and deliver them to you in one neat parcel when they hit
the return/enter key. In a real-time interactive application we instead
want to receive each keystroke as it happens.
This context manager achieves that by setting 'cbreak' mode on the
the output tty stream. cbreak is a mode inbetween 'cooked mode', where
all the user's input is preprocessed, and 'raw mode' where none of it
is. Basically, in cbreak mode input like :kbd:`Control-c` will still
interrupt (i.e. 'break') the process, hence the name. Wikipedia is your
friend on this one!
:meth:`Root.run` uses this context manager for you to make your
application work in the correct way.
'''
if self.is_a_tty:
orig_tty_attrs = termios.tcgetattr(self.stream)
tty.setcbreak(self.stream)
try:
yield
finally:
termios.tcsetattr(
self.stream, termios.TCSADRAIN, orig_tty_attrs)
else:
yield
开发者ID:ch3pjw,项目名称:junction,代码行数:28,代码来源:terminal.py
示例11: run
def run ( self ):
self._done.clear()
if ( platform.system() == 'Windows'):
while not self._done.isSet():
# We use kbhit() to see if anything has been entered yet.
# This is important, because if we don't then we will block
# on getch() and be unable to tell when _done.isSet().
if msvcrt.kbhit():
self.pushChar(msvcrt.getch())
else:
''' we're not on Windows, so we try the Unix-like approach '''
fd = sys.stdin.fileno( )
old_settings = termios.tcgetattr(sys.stdin)
try:
tty.setcbreak(fd)
while not self._done.isSet():
# We use _isData() to see if anything has been entered yet.
# This is important, because if we don't then we will block
# on stdin.read() and be unable to tell when _done.isSet().
if _isData():
self.pushChar(sys.stdin.read(1))
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
开发者ID:chadjoan,项目名称:Phasic-Encabulator,代码行数:28,代码来源:TermInput.py
示例12: ssh_interactive
def ssh_interactive(chan):
"""Stolen from paramiko.demos.interactive."""
import select
import socket
import termios
import tty
oldtty = termios.tcgetattr(sys.stdin)
try:
tty.setraw(sys.stdin.fileno())
tty.setcbreak(sys.stdin.fileno())
chan.settimeout(0.0)
while True:
r, w, e = select.select([chan, sys.stdin], [], [])
if chan in r:
try:
x = chan.recv(1024).decode('utf-8')
if len(x) == 0:
sys.stdout.write('\r\n*** EOF\r\n')
break
sys.stdout.write(x)
sys.stdout.flush()
except socket.timeout:
pass
if sys.stdin in r:
x = sys.stdin.read(1)
if len(x) == 0:
break
chan.send(x)
finally:
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty)
开发者ID:YggDrazil,项目名称:DolphinPlugIn_SADM,代码行数:33,代码来源:install.py
示例13: __init__
def __init__(self):
height, width = self.get_terminal_size()
self.screen = aalib.AsciiScreen(height=height, width=width)
# init tty attributes
self._tty_settings = termios.tcgetattr(sys.stdin)
tty.setcbreak(sys.stdin.fileno())
开发者ID:Joycc,项目名称:polascii,代码行数:7,代码来源:console.py
示例14: gameLoop
def gameLoop(self):
"""This is the main game loop."""
self.reload()
self.steps = 0
self.firaNo = 0
pygame.mixer.init()
pygame.mixer.music.load("music/route2.mp3")
pygame.mixer.music.play()
while True:
self.__play.getLevelProperties()
if self.__play.retLives() <= 0:
break
tty.setcbreak(sys.stdin)
key = ord(sys.stdin.read(1))
if key == 113 or key == 81:
break
if key == 32 and not self.__play.inAir():
self.gameJumpLoop()
else:
self.updateEverything(key)
self.__win = self.__play.victory()
if self.__win:
os.system("clear")
self.reload(self.__play.retScore(), 2)
if pygame.mixer.music.get_busy() != True:
pygame.mixer.music.play()
print "GAME OVER"
开发者ID:anirudhdahiya9,项目名称:Open-data-projecy,代码行数:27,代码来源:DKMain.py
示例15: interactive_shell
def interactive_shell(self, chan):
sys.stdout.flush()
try:
signal.signal(signal.SIGHUP, self._session.kill_session)
oldtty = termios.tcgetattr(sys.stdin)
tty.setraw(sys.stdin.fileno())
tty.setcbreak(sys.stdin.fileno())
chan.settimeout(0.0)
while True:
r, w, e = select.select([chan, sys.stdin], [], [])
if chan in r:
try:
x = chan.recv(1024)
if len(x) == 0:
break
sys.stdout.write(x)
sys.stdout.flush()
except socket.timeout:
break
if sys.stdin in r:
x = os.read(sys.stdin.fileno(), 1)
if len(x) == 0:
break
chan.send(x)
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty)
except Exception as e:
logger.error(e.message)
raise e
开发者ID:bewie,项目名称:BlackHole,代码行数:28,代码来源:client.py
示例16: __enter__
def __enter__(self):
self.original_stty = termios.tcgetattr(self.in_stream)
tty.setcbreak(self.in_stream, termios.TCSANOW)
if self.sigint_event:
self.orig_sigint_handler = signal.getsignal(signal.SIGINT)
signal.signal(signal.SIGINT, self.sigint_handler)
return self
开发者ID:vzhz,项目名称:cache-cards,代码行数:7,代码来源:input.py
示例17: __enter__
def __enter__ (self):
try:
self.__settings = termios.tcgetattr (sys.stdin)
tty.setcbreak (sys.stdin.fileno())
except termios.error:
self.__settings = None
return Console (self)
开发者ID:mertcetin,项目名称:motop,代码行数:7,代码来源:motop.py
示例18: run
def run(self, cb):
# This method starts the non-blocking terminal.
#
# A callback must be passed in to handle user key input. It will be called
# for every key press.
#
# This implementation does not handle multi-byte characters, such as
# arrow keys. A previous version of this code did handle this case, but
# decided that it got kind of messy.
signal.signal(signal.SIGINT, signalHandler)
old_settings = termios.tcgetattr(sys.stdin)
fd = sys.stdin.fileno()
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
try:
tty.setcbreak(sys.stdin.fileno())
while True:
time.sleep(self.delay)
if self.hasData():
cb()
finally:
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
开发者ID:richard-to,项目名称:betelbot,代码行数:26,代码来源:util.py
示例19: _wait_for_interval
def _wait_for_interval(self):
"""Wait for the time interval to expire
This method issues a timing loop to wait for the specified interval to
expire or quit if the user presses 'q' or 'Q'. The method passes all
other keyboard requests to the _do_command() method for processing.
If the interval expires, the method returns None.
If the user presses a key, the method returns the numeric key number.
Returns - None or int (see above)
"""
# If on *nix systems, set the terminal IO sys to not echo
if os.name == "posix":
import tty, termios
old_settings = termios.tcgetattr(sys.stdin)
tty.setcbreak(sys.stdin.fileno())
key = None
done = False
# loop for interval in seconds while detecting keypress
while not done:
done = self.alarm <= time.time()
if kbhit() and not done:
key = getch()
done = True
# Reset terminal IO sys to older state
if os.name == "posix":
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
return key
开发者ID:dannykopping,项目名称:deploi,代码行数:32,代码来源:failover_console.py
示例20: posix_shell
def posix_shell(chan,logfile):
import select
oldtty = termios.tcgetattr(sys.stdin)
f=open(logfile,'w')
try:
mode = tty.tcgetattr(sys.stdin.fileno())
tty.setraw(sys.stdin.fileno())
tty.setcbreak(sys.stdin.fileno())
chan.settimeout(0.0)
while True:
r, w, e = select.select([chan, sys.stdin], [], [])
if chan in r:
try:
x = chan.recv(1024)
if len(x) == 0:
sys.stdout.write('\r\n*** EOF\r\n')
break
sys.stdout.write(x)
sys.stdout.flush()
f.write(x)
f.flush()
except socket.timeout:
pass
if sys.stdin in r:
#x = sys.stdin.read(1)
x=os.read(sys.stdin.fileno(),1000)
if len(x) == 0:
break
chan.send(x)
finally:
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty)
f.close()
开发者ID:yuzh,项目名称:mylogin,代码行数:35,代码来源:mylogin.py
注:本文中的tty.setcbreak函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论