[tor-commits] [stem/master] Proc connections skipped due to incorrect file mode

atagar at torproject.org atagar at torproject.org
Tue Jan 26 17:37:18 UTC 2016


commit e04f453314f015ef994f798d1418670f62003386
Author: Damian Johnson <atagar at torproject.org>
Date:   Tue Jan 26 09:36:52 2016 -0800

    Proc connections skipped due to incorrect file mode
    
    toralf reports that proc connection resolution no longer works and think I see
    the issue. Under python3 we read the contents as unicode but our checks all
    expect bytes, causing us to skip all the lines.
---
 stem/util/proc.py      |    4 ++--
 test/unit/util/proc.py |    4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/stem/util/proc.py b/stem/util/proc.py
index 2b16ccb..7fdd70f 100644
--- a/stem/util/proc.py
+++ b/stem/util/proc.py
@@ -393,7 +393,7 @@ def connections(pid):
       continue
 
     try:
-      with open(proc_file_path) as proc_file:
+      with open(proc_file_path, 'rb') as proc_file:
         proc_file.readline()  # skip the first line
 
         for line in proc_file:
@@ -458,7 +458,7 @@ def _decode_proc_address_encoding(addr, is_ipv6):
         grouping = ip[8 * i:8 * (i + 1)]
         inverted += [grouping[2 * i:2 * (i + 1)] for i in range(4)][::-1]
 
-      ip = ''.join(inverted)
+      ip = b''.join(inverted)
 
     ip = socket.inet_ntop(socket.AF_INET6, base64.b16decode(ip))
 
diff --git a/test/unit/util/proc.py b/test/unit/util/proc.py
index f852820..ee52d21 100644
--- a/test/unit/util/proc.py
+++ b/test/unit/util/proc.py
@@ -220,7 +220,7 @@ class TestProc(unittest.TestCase):
       '/proc/net/udp6': False
     }[param]
 
-    open_mock.side_effect = lambda param: {
+    open_mock.side_effect = lambda param, mode: {
       '/proc/net/tcp': io.BytesIO(tcp),
       '/proc/net/udp': io.BytesIO(udp)
     }[param]
@@ -262,7 +262,7 @@ class TestProc(unittest.TestCase):
       '/proc/net/udp6': False
     }[param]
 
-    open_mock.side_effect = lambda param: {
+    open_mock.side_effect = lambda param, mode: {
       '/proc/net/tcp6': io.BytesIO(TCP6_CONTENT),
     }[param]
 



More information about the tor-commits mailing list