Skip to content

Commit 4ecfd91

Browse files
committed
fix(python2): Fix reading from stdin
Reading from stdin was broken in python2. This was not noticed, because stdin is mocked in the tests. Apparently the same applies to writing. This commit fixes both. Closes #35
1 parent f865bef commit 4ecfd91

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

anonip.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,14 @@ def run(self, input_file=None):
142142
# Assign here instead of using a default parameter value
143143
# to allow "late binding".
144144
input_file = sys.stdin
145-
for line in input_file:
145+
line = input_file.readline()
146+
while line:
146147
line = line.rstrip()
147148

148149
logger.debug("Got line: %r", line)
149150

150151
yield self.process_line(line)
152+
line = input_file.readline()
151153

152154
def process_ip(self, ip):
153155
"""
@@ -403,7 +405,7 @@ def main():
403405
else:
404406
output_file = sys.stdout
405407
for line in anonip.run(input_file):
406-
print(line, file=output_file)
408+
print(unicode(line), file=output_file)
407409
# TODO: when dropping support for Python <= 3.3, move the
408410
# flush into the print()
409411
output_file.flush()

0 commit comments

Comments
 (0)