Skip to content

Commit

Permalink
Do not attempt to use sys.std{out,in}.buffer on Python 2
Browse files Browse the repository at this point in the history
  • Loading branch information
cdown committed Jun 3, 2017
1 parent fbeb8fe commit 0f0ba98
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions srt_tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
else:
_open = open

STDIN_BYTESTREAM = getattr(sys.stdin, 'buffer', sys.stdin)
STDOUT_BYTESTREAM = getattr(sys.stdout, 'buffer', sys.stdout)

DASH_STREAM_MAP = {
'input': sys.stdin.buffer,
'output': sys.stdout.buffer,
'input': STDIN_BYTESTREAM,
'output': STDOUT_BYTESTREAM,
}

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -52,15 +55,15 @@ def basic_parser(multi_input=False, no_output=False):
else:
parser.add_argument(
'--input', '-i', metavar='FILE',
default=sys.stdin.buffer,
default=STDIN_BYTESTREAM,
type=lambda arg: dash_to_stream(arg, 'input'),
help='the file to process (default: stdin)',
)

if not no_output:
parser.add_argument(
'--output', '-o', metavar='FILE',
default=sys.stdout.buffer,
default=STDOUT_BYTESTREAM,
type=lambda arg: dash_to_stream(arg, 'output'),
help='the file to write to (default: stdout)',
)
Expand Down

0 comments on commit 0f0ba98

Please sign in to comment.