Django

Code

Ticket #5743: 5743.diff

File 5743.diff, 4.6 kB (added by ionut_bizau, 7 months ago)

patch

  • django/conf/__init__.py

    old new  
    1010import time     # Needed for Windows 
    1111from django.conf import global_settings 
    1212 
     13class ConfigurationError(ImportError, EnvironmentError): 
     14    pass 
     15 
    1316ENVIRONMENT_VARIABLE = "DJANGO_SETTINGS_MODULE" 
    1417 
    1518class LazySettings(object): 
     
    5255            if not settings_module: # If it's set but is an empty string. 
    5356                raise KeyError 
    5457        except KeyError: 
    55             raise EnvironmentError, "Environment variable %s is undefined." % ENVIRONMENT_VARIABLE 
     58            raise ConfigurationError, "Environment variable %s is undefined." % ENVIRONMENT_VARIABLE 
    5659 
    5760        self._target = Settings(settings_module) 
    5861 
     
    6366        argument must support attribute access (__getattr__)). 
    6467        """ 
    6568        if self._target != None: 
    66             raise EnvironmentError, 'Settings already configured.' 
     69            raise ConfigurationError, 'Settings already configured.' 
    6770        holder = UserSettingsHolder(default_settings) 
    6871        for name, value in options.items(): 
    6972            setattr(holder, name, value) 
     
    8184 
    8285        try: 
    8386            mod = __import__(self.SETTINGS_MODULE, {}, {}, ['']) 
    84         except ImportError, e: 
    85             raise EnvironmentError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e) 
     87        except ConfigurationError, e: 
     88            raise ImportError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e) 
    8689 
    8790        # Settings that should be converted into tuples if they're mistakenly entered 
    8891        # as strings. 
  • django/core/management/__init__.py

    old new  
    44from imp import find_module 
    55 
    66import django 
     7from django.conf import ConfigurationError 
    78from django.core.management.base import BaseCommand, CommandError, handle_default_options 
    89 
    910# For backwards compatibility: get_version() used to be in this module. 
     
    8485        try: 
    8586            from django.conf import settings 
    8687            apps = settings.INSTALLED_APPS 
    87         except (AttributeError, EnvironmentError): 
     88        except (AttributeError, ConfigurationError): 
    8889            apps = [] 
    8990 
    9091        for app_name in apps: 
     
    99100        try: 
    100101            from django.conf import settings 
    101102            project_directory = setup_environ(__import__(settings.SETTINGS_MODULE)) 
    102         except (AttributeError, EnvironmentError, ImportError): 
     103        except (AttributeError, ConfigurationError, ImportError): 
    103104            project_directory = None 
    104105 
    105106        if project_directory: 
  • django/newforms/fields.py

    old new  
    1616except NameError: 
    1717    from sets import Set as set 
    1818 
     19from django.conf import ConfigurationError 
    1920from django.utils.translation import ugettext_lazy as _ 
    2021from django.utils.encoding import StrAndUnicode, smart_unicode, smart_str 
    2122 
     
    415416try: 
    416417    from django.conf import settings 
    417418    URL_VALIDATOR_USER_AGENT = settings.URL_VALIDATOR_USER_AGENT 
    418 except (ImportError, EnvironmentError): 
     419except (ImportError, ConfigurationError): 
    419420    # It's OK if Django settings aren't configured. 
    420421    URL_VALIDATOR_USER_AGENT = 'Django (http://www.djangoproject.com/)' 
    421422 
  • docs/settings.txt

    old new  
    11291129settings. 
    11301130 
    11311131If you don't set ``DJANGO_SETTINGS_MODULE`` and don't call ``configure()``, 
    1132 Django will raise an ``EnvironmentError`` exception the first time a setting 
    1133 is accessed. 
     1132Django will raise an ``django.conf.ConfigurationError`` exception the first 
     1133time a setting is accessed. 
    11341134 
    11351135If you set ``DJANGO_SETTINGS_MODULE``, access settings values somehow, *then* 
    1136 call ``configure()``, Django will raise an ``EnvironmentError`` saying settings 
    1137 have already been configured. 
     1136call ``configure()``, Django will raise an ``django.conf.ConfigurationError`` 
     1137saying settings have already been configured. 
    11381138 
    11391139Also, it's an error to call ``configure()`` more than once, or to call 
    11401140``configure()`` after any setting has been accessed.