Skip to content

Commit

Permalink
bin: use binary stdio; fixes msoulier#113
Browse files Browse the repository at this point in the history
again possible to upload from stdin, download to stdout
  • Loading branch information
9001 committed Jun 16, 2024
1 parent 6b1ade7 commit 0087f02
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions partftpy/TftpContexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def __init__(
if hasattr(input, "read"):
self.fileobj = input
elif input == "-":
self.fileobj = sys.stdin.buffer
self.fileobj = sys.stdin if PY2 else sys.stdin.buffer
else:
self.fileobj = open(input, "rb")

Expand Down Expand Up @@ -438,7 +438,7 @@ def __init__(
self.filelike_fileobj = True
# If the output filename is -, then use stdout
elif output == "-":
self.fileobj = sys.stdout
self.fileobj = sys.stdout if PY2 else sys.stdout.buffer
self.filelike_fileobj = True
else:
self.fileobj = open(output, "wb")
Expand Down
11 changes: 11 additions & 0 deletions partftpy/TftpShared.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# vim: ts=4 sw=4 et ai:
from __future__ import print_function, unicode_literals

import sys

"""This module holds all objects shared by all other modules in partftpy."""


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


PY2 = sys.version_info < (3,)


try:
from typing import TYPE_CHECKING
except:
TYPE_CHECKING = False


def tftpassert(condition, msg):
"""This function is a simple utility that will check the condition
passed for a false state. If it finds one, it throws a TftpException
Expand Down

0 comments on commit 0087f02

Please sign in to comment.