From ae9eecff76b13a031bda56e55ed19f8e7c899eef Mon Sep 17 00:00:00 2001
From: Alexandre Ferland <alf@pixmob.com>
Date: Tue, 26 Sep 2017 16:51:37 -0400
Subject: [PATCH] return strings instead of bytes for py3

---
 docs/conf.py                 | 4 ++--
 docs/index.rst               | 3 +++
 flask_simpleldap/__init__.py | 9 +++++----
 setup.py                     | 2 +-
 4 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/docs/conf.py b/docs/conf.py
index 1f3c49a..744c5cb 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -64,9 +64,9 @@ copyright = u'2017, Alexandre Ferland'
 # built documents.
 #
 # The short X.Y version.
-version = '1.1.2'
+version = '1.2.0'
 # The full version, including alpha/beta/rc tags.
-release = '1.1.2'
+release = '1.2.0'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
diff --git a/docs/index.rst b/docs/index.rst
index dcc2e90..7f4dbae 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -116,6 +116,9 @@ History
 
 Changes:
 
+- 1.2.0 September 26, 2017
+  - Changed get_group_members() and get_user_groups() returning strings instead of bytes in PY3.
+
 - 1.1.2 July 17, 2017
   - Merge GitHub PR `#30 <https://github.com/admiralobvious/flask-simpleldap/pull/30>`_,
     Fix for python3
diff --git a/flask_simpleldap/__init__.py b/flask_simpleldap/__init__.py
index e7885c0..82ae17f 100644
--- a/flask_simpleldap/__init__.py
+++ b/flask_simpleldap/__init__.py
@@ -150,10 +150,7 @@ class LDAP(object):
             return
         try:
             conn = self.initialize
-            if sys.version_info[0] > 2:
-                conn.simple_bind_s(user_dn, password)
-            else:
-                conn.simple_bind_s(user_dn.decode('utf-8'), password)
+            conn.simple_bind_s(user_dn.decode('utf-8'), password)
             return True
         except ldap.LDAPError:
             return
@@ -248,6 +245,8 @@ class LDAP(object):
                             current_app.config['LDAP_USER_GROUPS_FIELD']]
                         result = [re.findall(b'(?:cn=|CN=)(.*?),', group)[0]
                                   for group in groups]
+                        if sys.version_info[0] > 2:
+                            result = [r.decode('utf-8') for r in result]
                         return result
         except ldap.LDAPError as e:
             raise LDAPException(self.error(e.args))
@@ -272,6 +271,8 @@ class LDAP(object):
                         records[0][1]:
                     members = records[0][1][
                         current_app.config['LDAP_GROUP_MEMBERS_FIELD']]
+                    if sys.version_info[0] > 2:
+                        members = [m.decode('utf-8') for m in members]
                     return members
         except ldap.LDAPError as e:
             raise LDAPException(self.error(e.args))
diff --git a/setup.py b/setup.py
index 137a98e..baed24c 100644
--- a/setup.py
+++ b/setup.py
@@ -9,7 +9,7 @@ from setuptools import setup
 
 setup(
     name='Flask-SimpleLDAP',
-    version='1.1.2',
+    version='1.2.0',
     url='https://github.com/admiralobvious/flask-simpleldap',
     license='MIT',
     author='Alexandre Ferland',
-- 
GitLab