[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Python's pwd module is unavailable on Windows



commit 646bd2b9856e9b7a43e863ca5880ddd9ba846df3
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Fri Aug 5 09:27:03 2016 -0700

    Python's pwd module is unavailable on Windows
    
    Our process module isn't intended to work on Windows, but turns out one of our
    imports raises an unexpected ImportError there breaking others...
    
      https://trac.torproject.org/projects/tor/ticket/19823
---
 stem/util/proc.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/stem/util/proc.py b/stem/util/proc.py
index 2897242..0a310bf 100644
--- a/stem/util/proc.py
+++ b/stem/util/proc.py
@@ -50,7 +50,6 @@ future, use them at your own risk.**
 import base64
 import os
 import platform
-import pwd
 import socket
 import sys
 import time
@@ -62,6 +61,13 @@ import stem.util.str_tools
 from stem.util import log
 
 try:
+  # unavailable on windows (#19823)
+  import pwd
+  IS_PWD_AVAILABLE = True
+except ImportError:
+  IS_PWD_AVAILABLE = False
+
+try:
   # added in python 3.2
   from functools import lru_cache
 except ImportError:
@@ -359,6 +365,9 @@ def connections(pid = None, user = None):
     parameter = 'all connections'
 
   try:
+    if not IS_PWD_AVAILABLE:
+      raise IOError("This requires python's pwd module, which is unavailable on Windows.")
+
     inodes = _inodes_for_sockets(pid) if pid else []
     process_uid = pwd.getpwnam(user).pw_uid if user else None
 

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits