Skip to content

Commit f77e794

Browse files
committed
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.
1 parent 451fd09 commit f77e794

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

test/Serialization/Inputs/binary_sub.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@
55
(_, old, new) = sys.argv
66
assert(len(old) == len(new))
77

8-
data = sys.stdin.read()
9-
sys.stdout.write(data.replace(old, new))
8+
if sys.version_info[0] < 3:
9+
data = sys.stdin.read()
10+
sys.stdout.write(data.replace(old, new))
11+
else:
12+
data = sys.stdin.buffer.read()
13+
sys.stdout.buffer.write(data.replace(old.encode('utf-8'), new.encode('utf-8')))

0 commit comments

Comments
 (0)