本文整理汇总了Python中tty.setcbreak函数的典型用法代码示例。如果您正苦于以下问题:Python setcbreak函数的具体用法?Python setcbreak怎么用?Python setcbreak使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setcbreak函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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
示例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)
示例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)
示例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())
示例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())
示例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
示例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)
示例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)
示例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
示例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)
示例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)
示例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())
示例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"
示例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