Skip to content

Commit bf79b4c

Browse files
committed
Support for smart_str in Django v4
The `smart_text()` util in Django is deprecated, and has been removed in Django v4, with `smart_str()` its replacement. This change attempts to import the new `smart_str()` util, falling back to `smart_text()` for earlier versions of Django.
1 parent 01e0f2d commit bf79b4c

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

django_elasticache/cluster_utils.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
utils for discovery cluster
33
"""
44
from distutils.version import StrictVersion
5-
from django.utils.encoding import smart_text
65
import re
76
from telnetlib import Telnet
87

8+
try:
9+
from django.utils.encoding import smart_str
10+
except ImportError:
11+
from django.utils.encoding import smart_text as smart_str
12+
913

1014
class WrongProtocolData(ValueError):
1115
"""
@@ -35,7 +39,7 @@ def get_cluster_info(host, port, ignore_cluster_errors=False):
3539
if len(version_list) not in [2, 3] or version_list[0] != b'VERSION':
3640
raise WrongProtocolData('version', res)
3741
version = version_list[1]
38-
if StrictVersion(smart_text(version)) >= StrictVersion('1.4.14'):
42+
if StrictVersion(smart_str(version)) >= StrictVersion('1.4.14'):
3943
cmd = b'config get cluster\n'
4044
else:
4145
cmd = b'get AmazonElastiCache:cluster\n'
@@ -50,8 +54,8 @@ def get_cluster_info(host, port, ignore_cluster_errors=False):
5054
return {
5155
'version': version,
5256
'nodes': [
53-
'{0}:{1}'.format(smart_text(host),
54-
smart_text(port))
57+
'{0}:{1}'.format(smart_str(host),
58+
smart_str(port))
5559
]
5660
}
5761

@@ -67,8 +71,8 @@ def get_cluster_info(host, port, ignore_cluster_errors=False):
6771
try:
6872
for node in ls[2].split(b' '):
6973
host, ip, port = node.split(b'|')
70-
nodes.append('{0}:{1}'.format(smart_text(ip or host),
71-
smart_text(port)))
74+
nodes.append('{0}:{1}'.format(smart_str(ip or host),
75+
smart_str(port)))
7276
except ValueError:
7377
raise WrongProtocolData(cmd, res)
7478
return {

0 commit comments

Comments
 (0)