Files
swift-mirror/test/Serialization/Inputs/binary_sub.py
Saleem Abdulrasool f77e794977 test: make binary_sub python 2, 3 compatible
In order to access `stdin`, `stdout` as binary, you must use the
`buffer` member in Python 3.  The replacement of the binary data
requires that pattern and the replacement be byte objects.  Convert the
pattern and replacement to UTF-8 encoded bytes.
2020-06-23 08:19:08 -07:00

14 lines
316 B
Python
Executable File

#!/usr/bin/env python
import sys
(_, old, new) = sys.argv
assert(len(old) == len(new))
if sys.version_info[0] < 3:
data = sys.stdin.read()
sys.stdout.write(data.replace(old, new))
else:
data = sys.stdin.buffer.read()
sys.stdout.buffer.write(data.replace(old.encode('utf-8'), new.encode('utf-8')))