[py3] Used six.reraise wherever necessary.
This commit is contained in:
parent
473d5f4ba1
commit
d796c94b03
|
@ -7,6 +7,7 @@ from django.core import signals
|
|||
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 @@ class BaseHandler(object):
|
|||
|
||||
# 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)
|
||||
|
|
|
@ -39,6 +39,7 @@ from django.db.backends.mysql.introspection import DatabaseIntrospection
|
|||
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 @@ class CursorWrapper(object):
|
|||
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__:
|
||||
|
|
|
@ -53,6 +53,7 @@ from django.db.backends.oracle.client import DatabaseClient
|
|||
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 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
|||
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 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
|||
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 @@ class FormatStylePlaceholderCursor(object):
|
|||
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 @@ class FormatStylePlaceholderCursor(object):
|
|||
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()
|
||||
|
|
|
@ -15,6 +15,7 @@ from django.db.backends.postgresql_psycopg2.version import get_version
|
|||
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 @@ class CursorWrapper(object):
|
|||
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 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
|||
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])
|
||||
|
|
|
@ -21,6 +21,7 @@ from django.db.backends.sqlite3.introspection import DatabaseIntrospection
|
|||
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 @@ class SQLiteCursorWrapper(Database.Cursor):
|
|||
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('%%','%')
|
||||
|
|
|
@ -14,6 +14,7 @@ from django.db.models.query_utils import (Q, select_related_descend,
|
|||
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 @@ class QuerySet(object):
|
|||
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):
|
||||
"""
|
||||
|
|
|
@ -84,6 +84,7 @@ from django.http.utils import *
|
|||
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 @@ class HttpRequest(object):
|
|||
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
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ from django.utils.encoding import smart_str
|
|||
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 @@ class Client(RequestFactory):
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue