From: Rob Browning Date: Fri, 3 Jan 2020 21:23:54 +0000 (-0600) Subject: pwdgrp: pass strings to python for python 3 X-Git-Tag: 0.31~118 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=bup.git;a=commitdiff_plain;h=4436ea65fffddde86abdf1d59f9aa28662a37c64;ds=sidebyside pwdgrp: pass strings to python for python 3 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 Tested-by: Rob Browning --- diff --git a/lib/bup/pwdgrp.py b/lib/bup/pwdgrp.py index cb8ccf3..485b429 100644 --- a/lib/bup/pwdgrp.py +++ b/lib/bup/pwdgrp.py @@ -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 = {}