1
0
Fork 0
mirror of https://github.com/kakwa/ldapcherry synced 2025-07-04 20:37:48 +02:00

better handling of the str/byte mess for python3

* add dedicated methods for python 3 in handling of bytearrays/strings
* using them to compare attributes checks in AD backend
This commit is contained in:
kakwa 2019-02-08 20:33:58 +01:00
parent 12c511b537
commit 18fdeb483e
2 changed files with 26 additions and 13 deletions

View file

@ -312,22 +312,35 @@ class Backend(ldapcherry.backend.Backend):
else:
dn_entry = r[0]
return dn_entry
# python-ldap talks in bytes,
# as the rest of ldapcherry talks in unicode utf-8:
# * everything passed to python-ldap must be converted to bytes
# * everything coming from python-ldap must be converted to unicode
if sys.version < '3':
def _str(self, s):
"""unicode -> bytes conversion"""
if s is None:
return None
return s.encode('utf-8')
def _uni(self, s):
"""bytes -> unicode conversion"""
if s is None:
return None
return s.decode('utf-8', 'ignore')
else:
def _str(self, s):
"""unicode -> bytes conversion"""
return s
def _str(self, s):
"""unicode -> bytes conversion"""
if s is None:
return None
return s.encode('utf-8')
def _uni(self, s):
"""bytes -> unicode conversion"""
if s is None:
return None
return s.decode('utf-8', 'ignore')
def _uni(self, s):
"""bytes -> unicode conversion"""
if s is None:
return None
if type(s) is not str:
return s.decode('utf-8', 'ignore')
else:
return s
def auth(self, username, password):
"""Authentication of a user"""