Ticket #8238: load-backend-pep-302.diff

File load-backend-pep-302.diff, 1.2 KB (added by bhuztez, 13 years ago)

taken from pep-302.5.diff for #596

  • django/db/utils.py

    diff --git a/django/db/utils.py b/django/db/utils.py
    index 3f5b86e..5c4740f 100644
    a b  
    11import os
    22from threading import local
     3import pkgutil
    34
    45from django.conf import settings
    56from django.core.exceptions import ImproperlyConfigured
    def load_backend(backend_name):  
    2526    except ImportError, e_user:
    2627        # The database backend wasn't found. Display a helpful error message
    2728        # listing all possible (built-in) database backends.
    28         backend_dir = os.path.join(os.path.dirname(__file__), 'backends')
    29         try:
    30             available_backends = [f for f in os.listdir(backend_dir)
    31                     if os.path.isdir(os.path.join(backend_dir, f))
    32                     and not f.startswith('.')]
    33         except EnvironmentError:
    34             available_backends = []
     29        backend_path = import_module('django.db.backends').__path__
     30        available_backends = [ name for loader, name, ispkg
     31                in pkgutil.iter_modules(backend_path)
     32                if ispkg ]
    3533        full_notation = backend_name.startswith('django.db.backends.')
    3634        if full_notation:
    3735            backend_name = backend_name[19:] # See #15621.
Back to Top