From 047d68b36c9bd6a5ddd978b3eddbb245ca537bfb Mon Sep 17 00:00:00 2001 From: Sebastian Nickels Date: Wed, 8 Dec 2021 13:48:45 +0100 Subject: [PATCH] Update for Django 4 --- django_python3_ldap/utils.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/django_python3_ldap/utils.py b/django_python3_ldap/utils.py index cb67f35..44f5053 100644 --- a/django_python3_ldap/utils.py +++ b/django_python3_ldap/utils.py @@ -6,7 +6,11 @@ import binascii import itertools -from django.utils.encoding import force_text +try: + from django.utils.encoding import force_str +except ImportError: + from django.utils.encoding import force_text as force_str + from django.utils.module_loading import import_string from django_python3_ldap.conf import settings @@ -27,8 +31,8 @@ def clean_ldap_name(name): """ return re.sub( r'[^a-zA-Z0-9 _\-.@:*]', - lambda c: "\\" + force_text(binascii.hexlify(c.group(0).encode("latin-1", errors="ignore"))).upper(), - force_text(name), + lambda c: "\\" + force_str(binascii.hexlify(c.group(0).encode("latin-1", errors="ignore"))).upper(), + force_str(name), )