Skip to content

Commit 0087f02

Browse files
committed
bin: use binary stdio; fixes msoulier#113
again possible to upload from stdin, download to stdout
1 parent 6b1ade7 commit 0087f02

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

partftpy/TftpContexts.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def __init__(
350350
if hasattr(input, "read"):
351351
self.fileobj = input
352352
elif input == "-":
353-
self.fileobj = sys.stdin.buffer
353+
self.fileobj = sys.stdin if PY2 else sys.stdin.buffer
354354
else:
355355
self.fileobj = open(input, "rb")
356356

@@ -438,7 +438,7 @@ def __init__(
438438
self.filelike_fileobj = True
439439
# If the output filename is -, then use stdout
440440
elif output == "-":
441-
self.fileobj = sys.stdout
441+
self.fileobj = sys.stdout if PY2 else sys.stdout.buffer
442442
self.filelike_fileobj = True
443443
else:
444444
self.fileobj = open(output, "wb")

partftpy/TftpShared.py

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# vim: ts=4 sw=4 et ai:
33
from __future__ import print_function, unicode_literals
44

5+
import sys
6+
57
"""This module holds all objects shared by all other modules in partftpy."""
68

79

@@ -22,6 +24,15 @@
2224
# be skipped to simulate lost packets.
2325

2426

27+
PY2 = sys.version_info < (3,)
28+
29+
30+
try:
31+
from typing import TYPE_CHECKING
32+
except:
33+
TYPE_CHECKING = False
34+
35+
2536
def tftpassert(condition, msg):
2637
"""This function is a simple utility that will check the condition
2738
passed for a false state. If it finds one, it throws a TftpException

0 commit comments

Comments
 (0)