pwdgrp: pass strings to python for python 3
authorRob Browning <rlb@defaultvalue.org>
Fri, 3 Jan 2020 21:23:54 +0000 (15:23 -0600)
committerRob Browning <rlb@defaultvalue.org>
Sun, 2 Feb 2020 19:30:12 +0000 (13:30 -0600)
Python 3's getpwnam and getgrnam functions only accept unicode
strings, so decode the bytes we have as iso-8859-1, which is what they
should be, given bup-python's LC_CTYPE override.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/pwdgrp.py

index cb8ccf3653a6363d437c646ad9a750035730dc80..485b4292db8e5fc17567f29057b630c74b3f31e1 100644 (file)
@@ -37,7 +37,9 @@ def getpwuid(uid):
     return _passwd_from_py(pwd.getpwuid(uid))
 
 def getpwnam(name):
-    return _passwd_from_py(pwd.getpwnam(name))
+    assert isinstance(name, bytes)
+    return _passwd_from_py(pwd.getpwnam(name.decode('iso-8859-1') if py_maj > 2
+                                        else name))
 
 
 class Group:
@@ -63,7 +65,9 @@ def getgrgid(uid):
     return _group_from_py(grp.getgrgid(uid))
 
 def getgrnam(name):
-    return _group_from_py(grp.getgrnam(name))
+    assert isinstance(name, bytes)
+    return _group_from_py(grp.getgrnam(name.decode('iso-8859-1') if py_maj > 2
+                                       else name))
 
 
 _uid_to_pwd_cache = {}