[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Python3 type issue for tail()
commit 80df42fe0bb0e2386cb0b09601b6a122af44c4e3
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Thu Jun 11 09:52:45 2015 -0700
Python3 type issue for tail()
Last change was a step in the right direction for tail() to be python3
compatible, but neglected to normalize the strings a couple spots.
---
stem/util/system.py | 6 +++---
test/unit/util/system.py | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/stem/util/system.py b/stem/util/system.py
index 4c5349b..eb7b9ad 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -777,13 +777,13 @@ def tail(target, lines = None):
target.seek(0, 2) # go to the end of the file
block_end_byte = target.tell()
block_number = -1
- content = ''
+ content = b''
while (lines is None or lines > 0) and block_end_byte > 0:
if (block_end_byte - BLOCK_SIZE > 0):
# read the last block we haven't yet read
target.seek(block_number * BLOCK_SIZE, 2)
- content, completed_lines = (target.read(BLOCK_SIZE) + content).split('\n', 1)
+ content, completed_lines = (target.read(BLOCK_SIZE) + content).split(b'\n', 1)
else:
# reached the start of the file, just read what's left
target.seek(0, 0)
@@ -794,7 +794,7 @@ def tail(target, lines = None):
if lines is not None:
lines -= 1
- yield line
+ yield stem.util.str_tools._to_unicode(line)
block_end_byte -= BLOCK_SIZE
block_number -= 1
diff --git a/test/unit/util/system.py b/test/unit/util/system.py
index dd1e30f..242a7fb 100644
--- a/test/unit/util/system.py
+++ b/test/unit/util/system.py
@@ -382,7 +382,7 @@ class TestSystem(unittest.TestCase):
# by file handle
- with open(path) as riddle_file:
+ with open(path, 'rb') as riddle_file:
self.assertEqual([' both the wicked and sweet.'], list(system.tail(riddle_file, 1)))
self.assertEqual([], list(system.tail(path, 0)))
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits