Python2 no likey

pull/11/head
Zach Riggle 11 years ago
parent 18aa627d31
commit 9ea31293e6

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

Loading…
Cancel
Save