Ticket #3349: 3349_r11897.diff

File 3349_r11897.diff, 9.8 KB (added by Andrew Badr, 15 years ago)
  • django/conf/__init__.py

     
    1111import time     # Needed for Windows
    1212
    1313from django.conf import global_settings
     14from django.core.exceptions import wrap_and_raise
    1415from django.utils.functional import LazyObject
    1516from django.utils import importlib
    1617
     
    7273        try:
    7374            mod = importlib.import_module(self.SETTINGS_MODULE)
    7475        except ImportError, e:
    75             raise ImportError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)
     76            wrap_and_raise(ImportError("Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)))
    7677
    7778        # Settings that should be converted into tuples if they're mistakenly entered
    7879        # as strings.
  • django/core/urlresolvers.py

     
    1111
    1212from django.http import Http404
    1313from django.conf import settings
    14 from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist
     14from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist, wrap_and_raise
    1515from django.utils.datastructures import MultiValueDict
    1616from django.utils.encoding import iri_to_uri, force_unicode, smart_str
    1717from django.utils.functional import memoize
     
    135135            self._callback = get_callable(self._callback_str)
    136136        except ImportError, e:
    137137            mod_name, _ = get_mod_func(self._callback_str)
    138             raise ViewDoesNotExist, "Could not import %s. Error was: %s" % (mod_name, str(e))
     138            wrap_and_raise(ViewDoesNotExist("Could not import %s. Error was: %s" % (mod_name, str(e))))
    139139        except AttributeError, e:
    140140            mod_name, func_name = get_mod_func(self._callback_str)
    141             raise ViewDoesNotExist, "Tried %s in module %s. Error was: %s" % (func_name, mod_name, str(e))
     141            wrap_and_raise(ViewDoesNotExist("Tried %s in module %s. Error was: %s" % (func_name, mod_name, str(e))))
    142142        return self._callback
    143143    callback = property(_get_callback)
    144144
  • django/core/handlers/base.py

     
    22
    33from django import http
    44from django.core import signals
     5from django.core.exceptions import wrap_and_raise
    56from django.utils.encoding import force_unicode
    67from django.utils.importlib import import_module
    78
     
    3435            try:
    3536                dot = middleware_path.rindex('.')
    3637            except ValueError:
    37                 raise exceptions.ImproperlyConfigured, '%s isn\'t a middleware module' % middleware_path
     38                wrap_and_raise(exceptions.ImproperlyConfigured('%s isn\'t a middleware module' % middleware_path))
    3839            mw_module, mw_classname = middleware_path[:dot], middleware_path[dot+1:]
    3940            try:
    4041                mod = import_module(mw_module)
  • django/core/exceptions.py

     
    3535class ValidationError(Exception):
    3636    """An error while validating data."""
    3737    pass
     38
     39def wrap_and_raise(new_exception):
     40    """
     41    Call from an except: block to raise a new exception, while keeping
     42    the traceback info from the source exception.
     43   
     44    new_exception is be the Exception (or subclass) instance to raise.
     45    """
     46    import sys
     47    exc_class, exc, tb = sys.exc_info()
     48
     49    if issubclass(exc_class, Exception):
     50        raise new_exception.__class__, new_exception, tb
     51    else:
     52        raise new_exception
     53
  • django/contrib/auth/__init__.py

     
    11import datetime
    22from warnings import warn
    3 from django.core.exceptions import ImproperlyConfigured
     3from django.core.exceptions import ImproperlyConfigured, wrap_and_raise
    44from django.utils.importlib import import_module
    55
    66SESSION_KEY = '_auth_user_id'
     
    1313    try:
    1414        mod = import_module(module)
    1515    except ImportError, e:
    16         raise ImproperlyConfigured, 'Error importing authentication backend %s: "%s"' % (module, e)
     16        wrap_and_raise(ImproperlyConfigured('Error importing authentication backend %s: "%s"' % (module, e)))
    1717    except ValueError, e:
    1818        raise ImproperlyConfigured, 'Error importing authentication backends. Is AUTHENTICATION_BACKENDS a correctly defined list or tuple?'
    1919    try:
  • django/template/__init__.py

     
    5252from inspect import getargspec
    5353
    5454from django.conf import settings
     55from django.core.exceptions import wrap_and_raise
    5556from django.template.context import Context, RequestContext, ContextPopException
    5657from django.utils.importlib import import_module
    5758from django.utils.itercompat import is_iterable
     
    970971        try:
    971972            mod = import_module(module_name)
    972973        except ImportError, e:
    973             raise InvalidTemplateLibrary("Could not load template library from %s, %s" % (module_name, e))
     974            wrap_and_raise(InvalidTemplateLibrary("Could not load template library from %s, %s" % (module_name, e)))
    974975        try:
    975976            lib = mod.register
    976977            libraries[module_name] = lib
  • django/template/loaders/app_directories.py

     
    77import sys
    88
    99from django.conf import settings
    10 from django.core.exceptions import ImproperlyConfigured
     10from django.core.exceptions import ImproperlyConfigured, wrap_and_raise
    1111from django.template import TemplateDoesNotExist
    1212from django.template.loader import BaseLoader
    1313from django.utils._os import safe_join
     
    2020    try:
    2121        mod = import_module(app)
    2222    except ImportError, e:
    23         raise ImproperlyConfigured, 'ImportError %s: %s' % (app, e.args[0])
     23        wrap_and_raise(ImproperlyConfigured('ImportError %s: %s' % (app, e.args[0])))
    2424    template_dir = os.path.join(os.path.dirname(mod.__file__), 'templates')
    2525    if os.path.isdir(template_dir):
    2626        app_template_dirs.append(template_dir.decode(fs_encoding))
  • django/template/defaulttags.py

     
    1313from django.template import get_library, Library, InvalidTemplateLibrary
    1414from django.template.smartif import IfParser, Literal
    1515from django.conf import settings
     16from django.core.exceptions import wrap_and_raise
    1617from django.utils.encoding import smart_str, smart_unicode
    1718from django.utils.itercompat import groupby
    1819from django.utils.safestring import mark_safe
     
    924925            lib = get_library("django.templatetags.%s" % taglib)
    925926            parser.add_library(lib)
    926927        except InvalidTemplateLibrary, e:
    927             raise TemplateSyntaxError("'%s' is not a valid tag library: %s" %
    928                                       (taglib, e))
     928            wrap_and_raise(TemplateSyntaxError("'%s' is not a valid tag library: %s" %
     929                                      (taglib, e)))
    929930    return LoadNode()
    930931load = register.tag(load)
    931932
  • django/template/context.py

     
    1 from django.core.exceptions import ImproperlyConfigured
     1from django.core.exceptions import ImproperlyConfigured, wrap_and_raise
    22from django.utils.importlib import import_module
    33
    44# Cache of actual callables.
     
    123123            try:
    124124                mod = import_module(module)
    125125            except ImportError, e:
    126                 raise ImproperlyConfigured('Error importing request processor module %s: "%s"' % (module, e))
     126                wrap_and_raise(ImproperlyConfigured('Error importing request processor module %s: "%s"' % (module, e)))
    127127            try:
    128128                func = getattr(mod, attr)
    129129            except AttributeError:
  • django/template/loader.py

     
    2020# Python eggs) sets is_usable to False if the "pkg_resources" module isn't
    2121# installed, because pkg_resources is necessary to read eggs.
    2222
    23 from django.core.exceptions import ImproperlyConfigured
     23from django.core.exceptions import ImproperlyConfigured, wrap_and_raise
    2424from django.template import Origin, Template, Context, TemplateDoesNotExist, add_to_builtins
    2525from django.utils.importlib import import_module
    2626from django.conf import settings
     
    8181        try:
    8282            mod = import_module(module)
    8383        except ImportError:
    84             raise ImproperlyConfigured('Error importing template source loader %s: "%s"' % (loader, e))
     84            wrap_and_raise(ImproperlyConfigured('Error importing template source loader %s: "%s"' % (loader, e)))
    8585        try:
    8686            TemplateLoader = getattr(mod, attr)
    8787        except AttributeError, e:
Back to Top