Python2 no likey

This commit is contained in:
Zach Riggle 2015-05-09 18:05:24 -04:00
parent 18aa627d31
commit 9ea31293e6
1 changed files with 6 additions and 12 deletions

View File

@ -13,24 +13,18 @@ import gdb
import pwndbg.compat
def get(fd, mode):
if pwndbg.compat.python3:
file = io.open(fd, mode=mode, buffering=0, closefd=False)
return io.TextIOWrapper(file, write_through=True)
else:
return os.fdopen(fd, mode, 0)
stdin = get(0, 'rb')
stdout = get(1, 'wb')
stderr = get(2, 'wb')
file = io.open(fd, mode=mode, buffering=0, closefd=False)
return io.TextIOWrapper(file, write_through=True)
class Stdio(object):
queue = []
def __enter__(self, *a, **kw):
self.queue.append((sys.stdin, sys.stdout, sys.stderr))
sys.stdin = get(0, 'rb')
sys.stdout = get(1, 'wb')
sys.stderr = get(2, 'wb')
if pwndbg.compat.python3:
sys.stdin = get(0, 'rb')
sys.stdout = get(1, 'wb')
sys.stderr = get(2, 'wb')
def __exit__(self, *a, **kw):
sys.stdin, sys.stdout, sys.stderr = self.queue.pop()