Skip to content

Commit 2bc8085

Browse files
committed
chore: use django's import_string
1 parent 22813a7 commit 2bc8085

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

captcha/conf/settings.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22

33
from django.conf import settings
4+
from django.utils.module_loading import import_string
45

56

67
CAPTCHA_FONT_PATH = getattr(
@@ -58,11 +59,8 @@
5859
def _callable_from_string(string_or_callable):
5960
if callable(string_or_callable):
6061
return string_or_callable
61-
else:
62-
return getattr(
63-
__import__(".".join(string_or_callable.split(".")[:-1]), {}, {}, [""]),
64-
string_or_callable.split(".")[-1],
65-
)
62+
elif isinstance(string_or_callable, str):
63+
return import_string(string_or_callable)
6664

6765

6866
def get_challenge(generator=None):
@@ -81,7 +79,7 @@ def filter_functions():
8179
return []
8280

8381

84-
def get_letter_color(index, char):
82+
def get_letter_color(index, challenge):
8583
if CAPTCHA_LETTER_COLOR_FUNCT:
86-
return _callable_from_string(CAPTCHA_LETTER_COLOR_FUNCT)(index, char)
84+
return _callable_from_string(CAPTCHA_LETTER_COLOR_FUNCT)(index, challenge)
8785
return CAPTCHA_FOREGROUND_COLOR

0 commit comments

Comments
 (0)