diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py index c697abfaa7022..050d4776d0621 100644 --- a/django/contrib/admin/views/main.py +++ b/django/contrib/admin/views/main.py @@ -174,7 +174,7 @@ def get_filters(self, request): lookup_needs_distinct(self.lookup_opts, key)) return filter_specs, bool(filter_specs), lookup_params, use_distinct except FieldDoesNotExist as e: - raise IncorrectLookupParameters, IncorrectLookupParameters(e), sys.exc_info()[2] + six.reraise(IncorrectLookupParameters, IncorrectLookupParameters(e), sys.exc_info()[2]) def get_query_string(self, new_params=None, remove=None): if new_params is None: new_params = {} diff --git a/django/contrib/gis/db/backends/oracle/introspection.py b/django/contrib/gis/db/backends/oracle/introspection.py index 0e27ece7a5fec..d6c8f452df6e5 100644 --- a/django/contrib/gis/db/backends/oracle/introspection.py +++ b/django/contrib/gis/db/backends/oracle/introspection.py @@ -1,6 +1,7 @@ import cx_Oracle -from django.db.backends.oracle.introspection import DatabaseIntrospection import sys +from django.db.backends.oracle.introspection import DatabaseIntrospection +from django.utils import six class OracleIntrospection(DatabaseIntrospection): # Associating any OBJECTVAR instances with GeometryField. Of course, @@ -22,7 +23,7 @@ def get_geometry_type(self, table_name, geo_col): 'Could not find entry in USER_SDO_GEOM_METADATA ' 'corresponding to "%s"."%s"\n' 'Error message: %s.') % (table_name, geo_col, msg) - raise Exception, Exception(new_msg), sys.exc_info()[2] + six.reraise(Exception, Exception(new_msg), sys.exc_info()[2]) # TODO: Research way to find a more specific geometry field type for # the column's contents. diff --git a/django/contrib/gis/db/backends/spatialite/base.py b/django/contrib/gis/db/backends/spatialite/base.py index 4ef810e5d2978..7b49d71a619f1 100644 --- a/django/contrib/gis/db/backends/spatialite/base.py +++ b/django/contrib/gis/db/backends/spatialite/base.py @@ -9,6 +9,7 @@ from django.contrib.gis.db.backends.spatialite.creation import SpatiaLiteCreation from django.contrib.gis.db.backends.spatialite.introspection import SpatiaLiteIntrospection from django.contrib.gis.db.backends.spatialite.operations import SpatiaLiteOperations +from django.utils import six class DatabaseWrapper(SQLiteDatabaseWrapper): def __init__(self, *args, **kwargs): @@ -54,6 +55,6 @@ def get_new_connection(self, conn_params): new_msg = ( 'Unable to load the SpatiaLite library extension ' '"%s" because: %s') % (self.spatialite_lib, msg) - raise ImproperlyConfigured, ImproperlyConfigured(new_msg), sys.exc_info()[2] + six.reraise(ImproperlyConfigured, ImproperlyConfigured(new_msg), sys.exc_info()[2]) cur.close() return conn diff --git a/django/contrib/gis/db/backends/spatialite/operations.py b/django/contrib/gis/db/backends/spatialite/operations.py index 2be1c9613d99c..83745476a0fdb 100644 --- a/django/contrib/gis/db/backends/spatialite/operations.py +++ b/django/contrib/gis/db/backends/spatialite/operations.py @@ -131,7 +131,7 @@ def spatial_version(self): 'Cannot determine the SpatiaLite version for the "%s" ' 'database (error was "%s"). Was the SpatiaLite initialization ' 'SQL loaded on this database?') % (self.connection.settings_dict['NAME'], msg) - raise ImproperlyConfigured, ImproperlyConfigured(new_msg), sys.exc_info()[2] + six.reraise(ImproperlyConfigured, ImproperlyConfigured(new_msg), sys.exc_info()[2]) if version < (2, 3, 0): raise ImproperlyConfigured('GeoDjango only supports SpatiaLite versions ' '2.3.0 and above') diff --git a/django/contrib/gis/utils/layermapping.py b/django/contrib/gis/utils/layermapping.py index 44d00643cdb7a..282dbc7450d3b 100644 --- a/django/contrib/gis/utils/layermapping.py +++ b/django/contrib/gis/utils/layermapping.py @@ -430,7 +430,7 @@ def coord_transform(self): return CoordTransform(self.source_srs, target_srs) except Exception as msg: new_msg = 'Could not translate between the data source and model geometry: %s' % msg - raise LayerMapError, LayerMapError(new_msg), sys.exc_info()[2] + six.reraise(LayerMapError, LayerMapError(new_msg), sys.exc_info()[2]) def geometry_field(self): "Returns the GeometryField instance associated with the geographic column." diff --git a/django/core/management/commands/flush.py b/django/core/management/commands/flush.py index 81b9a22d71a10..10066417a162e 100644 --- a/django/core/management/commands/flush.py +++ b/django/core/management/commands/flush.py @@ -9,6 +9,7 @@ from django.core.management.sql import sql_flush, emit_post_sync_signal from django.utils.importlib import import_module from django.utils.six.moves import input +from django.utils import six class Command(NoArgsCommand): @@ -70,7 +71,7 @@ def handle_noargs(self, **options): " * The SQL was invalid.\n" "Hint: Look at the output of 'django-admin.py sqlflush'. That's the SQL this command wasn't able to run.\n" "The full error: %s") % (connection.settings_dict['NAME'], e) - raise CommandError, CommandError(new_msg), sys.exc_info()[2] + six.reraise(CommandError, CommandError(new_msg), sys.exc_info()[2]) # Emit the post sync signal. This allows individual # applications to respond as if the database had been # sync'd from scratch. diff --git a/django/core/serializers/json.py b/django/core/serializers/json.py index f7c9a100f261b..64357bf9d55ce 100644 --- a/django/core/serializers/json.py +++ b/django/core/serializers/json.py @@ -73,7 +73,7 @@ def Deserializer(stream_or_string, **options): raise except Exception as e: # Map to deserializer error - raise DeserializationError, DeserializationError(e), sys.exc_info()[2] + six.reraise(DeserializationError, DeserializationError(e), sys.exc_info()[2]) class DjangoJSONEncoder(json.JSONEncoder): diff --git a/django/core/serializers/pyyaml.py b/django/core/serializers/pyyaml.py index 7b1dfcde4e090..478f14b53f31e 100644 --- a/django/core/serializers/pyyaml.py +++ b/django/core/serializers/pyyaml.py @@ -72,4 +72,4 @@ def Deserializer(stream_or_string, **options): raise except Exception as e: # Map to deserializer error - raise DeserializationError, DeserializationError(e), sys.exc_info()[2] + six.reraise(DeserializationError, DeserializationError(e), sys.exc_info()[2]) diff --git a/django/core/servers/basehttp.py b/django/core/servers/basehttp.py index e826e9c55ee68..8e390bce272b3 100644 --- a/django/core/servers/basehttp.py +++ b/django/core/servers/basehttp.py @@ -24,6 +24,7 @@ from django.core.management.color import color_style from django.core.wsgi import get_wsgi_application from django.utils.module_loading import import_by_path +from django.utils import six __all__ = ['WSGIServer', 'WSGIRequestHandler'] @@ -121,7 +122,7 @@ def server_bind(self): try: super(WSGIServer, self).server_bind() except Exception as e: - raise WSGIServerException, WSGIServerException(e), sys.exc_info()[2] + six.reraise(WSGIServerException, WSGIServerException(e), sys.exc_info()[2]) self.setup_environ() diff --git a/django/forms/fields.py b/django/forms/fields.py index 729921051dd21..e708ef846e5d4 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -620,7 +620,7 @@ def to_python(self, data): # raised. Catch and re-raise. raise except Exception: # Python Imaging Library doesn't recognize it as an image - raise ValidationError, ValidationError(self.error_messages['invalid_image']), sys.exc_info()[2] + six.reraise(ValidationError, ValidationError(self.error_messages['invalid_image']), sys.exc_info()[2]) if hasattr(f, 'seek') and callable(f.seek): f.seek(0) return f diff --git a/django/forms/util.py b/django/forms/util.py index ca629593504a4..f1b864e6b35ff 100644 --- a/django/forms/util.py +++ b/django/forms/util.py @@ -6,6 +6,7 @@ from django.utils.safestring import mark_safe from django.utils import timezone from django.utils.translation import ugettext_lazy as _ +from django.utils import six import sys # Import ValidationError so that it can be imported from this @@ -84,7 +85,7 @@ def from_current_timezone(value): 'in time zone %(current_timezone)s; it ' 'may be ambiguous or it may not exist.') % {'datetime': value, 'current_timezone': current_timezone} - raise ValidationError, ValidationError(msg), sys.exc_info()[2] + six.reraise(ValidationError, ValidationError(msg), sys.exc_info()[2]) return value def to_current_timezone(value): diff --git a/django/http/multipartparser.py b/django/http/multipartparser.py index 20b2794fcea7f..0c07335f27d47 100644 --- a/django/http/multipartparser.py +++ b/django/http/multipartparser.py @@ -211,7 +211,7 @@ def parse(self): except Exception as e: # Since this is only a chunk, any error is an unfixable error. msg = "Could not decode base64 data: %r" % e - raise MultiPartParserError, MultiPartParserError(msg), sys.exc_info()[2] + six.reraise(MultiPartParserError, MultiPartParserError(msg), sys.exc_info()[2]) for i, handler in enumerate(handlers): chunk_length = len(chunk) diff --git a/django/templatetags/i18n.py b/django/templatetags/i18n.py index 43937b5aa9978..14f0382fc73c1 100644 --- a/django/templatetags/i18n.py +++ b/django/templatetags/i18n.py @@ -428,7 +428,7 @@ def do_block_translate(parser, token): msg = ( '"context" in %r tag expected ' 'exactly one argument.') % bits[0] - raise TemplateSyntaxError, TemplateSyntaxError(msg), sys.exc_info()[2] + six.reraise(TemplateSyntaxError, TemplateSyntaxError(msg), sys.exc_info()[2]) else: raise TemplateSyntaxError('Unknown argument for %r tag: %r.' % (bits[0], option)) diff --git a/django/test/testcases.py b/django/test/testcases.py index 5f27259348e70..9c90aa58d7f86 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -1119,7 +1119,7 @@ def setUpClass(cls): for port in range(extremes[0], extremes[1] + 1): possible_ports.append(port) except Exception: - raise ImproperlyConfigured, ImproperlyConfigured(msg), sys.exc_info()[2] + six.reraise(ImproperlyConfigured, ImproperlyConfigured(msg), sys.exc_info()[2]) cls.server_thread = LiveServerThread( host, possible_ports, connections_override) cls.server_thread.daemon = True diff --git a/django/utils/http.py b/django/utils/http.py index b18bcce1de01c..73b6396286da3 100644 --- a/django/utils/http.py +++ b/django/utils/http.py @@ -144,7 +144,7 @@ def parse_http_date(date): result = datetime.datetime(year, month, day, hour, min, sec) return calendar.timegm(result.utctimetuple()) except Exception: - raise ValueError, ValueError("%r is not a valid date" % date), sys.exc_info()[2] + six.reraise(ValueError, ValueError("%r is not a valid date" % date), sys.exc_info()[2]) def parse_http_date_safe(date): """