From 30f71fe48202f3ee2e17420c6890eaee432a983c Mon Sep 17 00:00:00 2001 From: MinRK Date: Wed, 20 Aug 2014 10:23:17 -0700 Subject: [PATCH] support unicode input on Python 2 py2 unicode == py3 str, and should be treated the same. --- simplepam.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/simplepam.py b/simplepam.py index 7a649e3..8d3f236 100644 --- a/simplepam.py +++ b/simplepam.py @@ -20,6 +20,9 @@ from ctypes.util import find_library import sys +if sys.version_info >= (3,): + unicode = str + libpam = CDLL(find_library("pam")) libc = CDLL(find_library("c")) @@ -124,13 +127,12 @@ def authenticate(username, password, service='login', encoding='utf-8', Defaults to 'True'. """ - if sys.version_info >= (3,): - if isinstance(username, str): - username = username.encode(encoding) - if isinstance(password, str): - password = password.encode(encoding) - if isinstance(service, str): - service = service.encode(encoding) + if isinstance(username, unicode): + username = username.encode(encoding) + if isinstance(password, unicode): + password = password.encode(encoding) + if isinstance(service, unicode): + service = service.encode(encoding) @conv_func def my_conv(n_messages, messages, p_response, app_data):