From 34a736b7521def321b2104d541e634134c5d1c62 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sun, 7 Oct 2012 21:16:01 +0200 Subject: [PATCH] Used pkgutil to get list of backend modules Refs #18827. --- django/db/utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/django/db/utils.py b/django/db/utils.py index 146de7b9f4..5fa78fe350 100644 --- a/django/db/utils.py +++ b/django/db/utils.py @@ -1,4 +1,5 @@ import os +import pkgutil from threading import local from django.conf import settings @@ -28,9 +29,9 @@ def load_backend(backend_name): # listing all possible (built-in) database backends. backend_dir = os.path.join(os.path.dirname(__file__), 'backends') try: - builtin_backends = [f for f in os.listdir(backend_dir) - if os.path.isdir(os.path.join(backend_dir, f)) - and not (f.startswith('.') or f in ('__pycache__', 'dummy'))] + builtin_backends = [ + name for _, name, ispkg in pkgutil.iter_modules([backend_dir]) + if ispkg and name != 'dummy'] except EnvironmentError: builtin_backends = [] if backend_name not in ['django.db.backends.%s' % b for b in