Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[py3] Used six.reraise wherever necessary.

  • Loading branch information...
commit d796c94b03ffbe90895ec68c5041806907cb9577 1 parent 473d5f4
@aaugustin aaugustin authored
View
3  django/core/handlers/base.py
@@ -7,6 +7,7 @@
from django.utils.encoding import force_unicode
from django.utils.importlib import import_module
from django.utils.log import getLogger
+from django.utils import six
logger = getLogger('django.request')
@@ -224,7 +225,7 @@ def handle_uncaught_exception(self, request, resolver, exc_info):
# If Http500 handler is not installed, re-raise last exception
if resolver.urlconf_module is None:
- raise exc_info[1], None, exc_info[2]
+ six.reraise(exc_info[1], None, exc_info[2])
# Return an HttpResponse that displays a friendly error message.
callback, param_dict = resolver.resolve500()
return callback(request, **param_dict)
View
17 django/db/backends/mysql/base.py
@@ -39,6 +39,7 @@
from django.db.backends.mysql.validation import DatabaseValidation
from django.utils.functional import cached_property
from django.utils.safestring import SafeString, SafeUnicode
+from django.utils import six
from django.utils import timezone
# Raise exceptions for database warnings if DEBUG is on
@@ -117,29 +118,29 @@ def execute(self, query, args=None):
try:
return self.cursor.execute(query, args)
except Database.IntegrityError as e:
- raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
+ six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2])
except Database.OperationalError as e:
# Map some error codes to IntegrityError, since they seem to be
# misclassified and Django would prefer the more logical place.
if e[0] in self.codes_for_integrityerror:
- raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
- raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
+ six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2])
+ six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2])
except Database.DatabaseError as e:
- raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
+ six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2])
def executemany(self, query, args):
try:
return self.cursor.executemany(query, args)
except Database.IntegrityError as e:
- raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
+ six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2])
except Database.OperationalError as e:
# Map some error codes to IntegrityError, since they seem to be
# misclassified and Django would prefer the more logical place.
if e[0] in self.codes_for_integrityerror:
- raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
- raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
+ six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2])
+ six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2])
except Database.DatabaseError as e:
- raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
+ six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2])
def __getattr__(self, attr):
if attr in self.__dict__:
View
19 django/db/backends/oracle/base.py
@@ -53,6 +53,7 @@ def _setup_environment(environ):
from django.db.backends.oracle.creation import DatabaseCreation
from django.db.backends.oracle.introspection import DatabaseIntrospection
from django.utils.encoding import smart_str, force_unicode
+from django.utils import six
from django.utils import timezone
DatabaseError = Database.DatabaseError
@@ -549,7 +550,7 @@ def _commit(self):
except Database.IntegrityError as e:
# In case cx_Oracle implements (now or in a future version)
# raising this specific exception
- raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
+ six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2])
except Database.DatabaseError as e:
# cx_Oracle 5.0.4 raises a cx_Oracle.DatabaseError exception
# with the following attributes and values:
@@ -561,8 +562,8 @@ def _commit(self):
x = e.args[0]
if hasattr(x, 'code') and hasattr(x, 'message') \
and x.code == 2091 and 'ORA-02291' in x.message:
- raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
- raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
+ six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2])
+ six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2])
class OracleParam(object):
@@ -688,12 +689,12 @@ def execute(self, query, params=None):
try:
return self.cursor.execute(query, self._param_generator(params))
except Database.IntegrityError as e:
- raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
+ six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2])
except Database.DatabaseError as e:
# cx_Oracle <= 4.4.0 wrongly raises a DatabaseError for ORA-01400.
if hasattr(e.args[0], 'code') and e.args[0].code == 1400 and not isinstance(e, IntegrityError):
- raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
- raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
+ six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2])
+ six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2])
def executemany(self, query, params=None):
# cx_Oracle doesn't support iterators, convert them to lists
@@ -717,12 +718,12 @@ def executemany(self, query, params=None):
return self.cursor.executemany(query,
[self._param_generator(p) for p in formatted])
except Database.IntegrityError as e:
- raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
+ six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2])
except Database.DatabaseError as e:
# cx_Oracle <= 4.4.0 wrongly raises a DatabaseError for ORA-01400.
if hasattr(e.args[0], 'code') and e.args[0].code == 1400 and not isinstance(e, IntegrityError):
- raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
- raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
+ six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2])
+ six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2])
def fetchone(self):
row = self.cursor.fetchone()
View
11 django/db/backends/postgresql_psycopg2/base.py
@@ -15,6 +15,7 @@
from django.db.backends.postgresql_psycopg2.introspection import DatabaseIntrospection
from django.utils.log import getLogger
from django.utils.safestring import SafeUnicode, SafeString
+from django.utils import six
from django.utils.timezone import utc
try:
@@ -51,17 +52,17 @@ def execute(self, query, args=None):
try:
return self.cursor.execute(query, args)
except Database.IntegrityError as e:
- raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
+ six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2])
except Database.DatabaseError as e:
- raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
+ six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2])
def executemany(self, query, args):
try:
return self.cursor.executemany(query, args)
except Database.IntegrityError as e:
- raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
+ six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2])
except Database.DatabaseError as e:
- raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
+ six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2])
def __getattr__(self, attr):
if attr in self.__dict__:
@@ -236,4 +237,4 @@ def _commit(self):
try:
return self.connection.commit()
except Database.IntegrityError as e:
- raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
+ six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2])
View
9 django/db/backends/sqlite3/base.py
@@ -21,6 +21,7 @@
from django.utils.dateparse import parse_date, parse_datetime, parse_time
from django.utils.functional import cached_property
from django.utils.safestring import SafeString
+from django.utils import six
from django.utils import timezone
try:
@@ -348,18 +349,18 @@ def execute(self, query, params=()):
try:
return Database.Cursor.execute(self, query, params)
except Database.IntegrityError as e:
- raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
+ six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2])
except Database.DatabaseError as e:
- raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
+ six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2])
def executemany(self, query, param_list):
query = self.convert_query(query)
try:
return Database.Cursor.executemany(self, query, param_list)
except Database.IntegrityError as e:
- raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
+ six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2])
except Database.DatabaseError as e:
- raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
+ six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2])
def convert_query(self, query):
return FORMAT_QMARK_REGEX.sub('?', query).replace('%%','%')
View
3  django/db/models/query.py
@@ -14,6 +14,7 @@
from django.db.models.deletion import Collector
from django.db.models import sql
from django.utils.functional import partition
+from django.utils import six
# Used to control how many objects are worked with at once in some cases (e.g.
# when deleting objects).
@@ -470,7 +471,7 @@ def get_or_create(self, **kwargs):
return self.get(**lookup), False
except self.model.DoesNotExist:
# Re-raise the IntegrityError with its original traceback.
- raise exc_info[1], None, exc_info[2]
+ six.reraise(exc_info[1], None, exc_info[2])
def latest(self, field_name=None):
"""
View
3  django/http/__init__.py
@@ -84,6 +84,7 @@ def _BaseCookie__set(self, key, real_value, coded_value):
from django.utils.datastructures import MultiValueDict, ImmutableList
from django.utils.encoding import smart_str, iri_to_uri, force_unicode
from django.utils.http import cookie_date
+from django.utils import six
from django.utils import timezone
RESERVED_CHARS="!*'();:@&=+$,/?%#[]"
@@ -290,7 +291,7 @@ def body(self):
try:
self._body = self.read()
except IOError as e:
- raise UnreadablePostError, e, sys.exc_traceback
+ six.reraise(UnreadablePostError, e, sys.exc_traceback)
self._stream = BytesIO(self._body)
return self._body
View
3  django/test/client.py
@@ -20,6 +20,7 @@
from django.utils.http import urlencode
from django.utils.importlib import import_module
from django.utils.itercompat import is_iterable
+from django.utils import six
from django.db import close_connection
from django.test.utils import ContextList
@@ -381,7 +382,7 @@ def request(self, **request):
if self.exc_info:
exc_info = self.exc_info
self.exc_info = None
- raise exc_info[1], None, exc_info[2]
+ six.reraise(exc_info[1], None, exc_info[2])
# Save the client and request that stimulated the response.
response.client = self
Please sign in to comment.
Something went wrong with that request. Please try again.