core: fix tab-complete in shell

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-11-22 20:30:00 +01:00
parent ab3d47c437
commit 5262d89505
1 changed files with 17 additions and 1 deletions

View File

@ -1,6 +1,8 @@
"""authentik shell command""" """authentik shell command"""
import code import code
import platform import platform
import sys
import traceback
from django.apps import apps from django.apps import apps
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -88,7 +90,21 @@ class Command(BaseCommand):
# pylint: disable=exec-used # pylint: disable=exec-used
exec(options["command"], namespace) # nosec # noqa exec(options["command"], namespace) # nosec # noqa
return return
try:
hook = sys.__interactivehook__
except AttributeError:
# Match the behavior of the cpython shell where a missing
# sys.__interactivehook__ is ignored.
pass
else:
try:
hook()
except Exception:
# Match the behavior of the cpython shell where an error in
# sys.__interactivehook__ prints a warning and the exception
# and continues.
print("Failed calling sys.__interactivehook__")
traceback.print_exc()
# Try to enable tab-complete # Try to enable tab-complete
try: try:
import readline import readline