[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.encoding import force_unicode
|
||||||
from django.utils.importlib import import_module
|
from django.utils.importlib import import_module
|
||||||
from django.utils.log import getLogger
|
from django.utils.log import getLogger
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
logger = getLogger('django.request')
|
logger = getLogger('django.request')
|
||||||
|
|
||||||
|
@ -224,7 +225,7 @@ class BaseHandler(object):
|
||||||
|
|
||||||
# If Http500 handler is not installed, re-raise last exception
|
# If Http500 handler is not installed, re-raise last exception
|
||||||
if resolver.urlconf_module is None:
|
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.
|
# Return an HttpResponse that displays a friendly error message.
|
||||||
callback, param_dict = resolver.resolve500()
|
callback, param_dict = resolver.resolve500()
|
||||||
return callback(request, **param_dict)
|
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.db.backends.mysql.validation import DatabaseValidation
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.utils.safestring import SafeString, SafeUnicode
|
from django.utils.safestring import SafeString, SafeUnicode
|
||||||
|
from django.utils import six
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
# Raise exceptions for database warnings if DEBUG is on
|
# Raise exceptions for database warnings if DEBUG is on
|
||||||
|
@ -117,29 +118,29 @@ class CursorWrapper(object):
|
||||||
try:
|
try:
|
||||||
return self.cursor.execute(query, args)
|
return self.cursor.execute(query, args)
|
||||||
except Database.IntegrityError as e:
|
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:
|
except Database.OperationalError as e:
|
||||||
# Map some error codes to IntegrityError, since they seem to be
|
# Map some error codes to IntegrityError, since they seem to be
|
||||||
# misclassified and Django would prefer the more logical place.
|
# misclassified and Django would prefer the more logical place.
|
||||||
if e[0] in self.codes_for_integrityerror:
|
if e[0] in self.codes_for_integrityerror:
|
||||||
raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
|
six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2])
|
||||||
raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
|
six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2])
|
||||||
except Database.DatabaseError as e:
|
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):
|
def executemany(self, query, args):
|
||||||
try:
|
try:
|
||||||
return self.cursor.executemany(query, args)
|
return self.cursor.executemany(query, args)
|
||||||
except Database.IntegrityError as e:
|
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:
|
except Database.OperationalError as e:
|
||||||
# Map some error codes to IntegrityError, since they seem to be
|
# Map some error codes to IntegrityError, since they seem to be
|
||||||
# misclassified and Django would prefer the more logical place.
|
# misclassified and Django would prefer the more logical place.
|
||||||
if e[0] in self.codes_for_integrityerror:
|
if e[0] in self.codes_for_integrityerror:
|
||||||
raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
|
six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2])
|
||||||
raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
|
six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2])
|
||||||
except Database.DatabaseError as e:
|
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):
|
def __getattr__(self, attr):
|
||||||
if attr in self.__dict__:
|
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.creation import DatabaseCreation
|
||||||
from django.db.backends.oracle.introspection import DatabaseIntrospection
|
from django.db.backends.oracle.introspection import DatabaseIntrospection
|
||||||
from django.utils.encoding import smart_str, force_unicode
|
from django.utils.encoding import smart_str, force_unicode
|
||||||
|
from django.utils import six
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
DatabaseError = Database.DatabaseError
|
DatabaseError = Database.DatabaseError
|
||||||
|
@ -549,7 +550,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
except Database.IntegrityError as e:
|
except Database.IntegrityError as e:
|
||||||
# In case cx_Oracle implements (now or in a future version)
|
# In case cx_Oracle implements (now or in a future version)
|
||||||
# raising this specific exception
|
# 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:
|
except Database.DatabaseError as e:
|
||||||
# cx_Oracle 5.0.4 raises a cx_Oracle.DatabaseError exception
|
# cx_Oracle 5.0.4 raises a cx_Oracle.DatabaseError exception
|
||||||
# with the following attributes and values:
|
# with the following attributes and values:
|
||||||
|
@ -561,8 +562,8 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
x = e.args[0]
|
x = e.args[0]
|
||||||
if hasattr(x, 'code') and hasattr(x, 'message') \
|
if hasattr(x, 'code') and hasattr(x, 'message') \
|
||||||
and x.code == 2091 and 'ORA-02291' in x.message:
|
and x.code == 2091 and 'ORA-02291' in x.message:
|
||||||
raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
|
six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2])
|
||||||
raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
|
six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2])
|
||||||
|
|
||||||
|
|
||||||
class OracleParam(object):
|
class OracleParam(object):
|
||||||
|
@ -688,12 +689,12 @@ class FormatStylePlaceholderCursor(object):
|
||||||
try:
|
try:
|
||||||
return self.cursor.execute(query, self._param_generator(params))
|
return self.cursor.execute(query, self._param_generator(params))
|
||||||
except Database.IntegrityError as e:
|
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:
|
except Database.DatabaseError as e:
|
||||||
# cx_Oracle <= 4.4.0 wrongly raises a DatabaseError for ORA-01400.
|
# 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):
|
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]
|
six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2])
|
||||||
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, params=None):
|
def executemany(self, query, params=None):
|
||||||
# cx_Oracle doesn't support iterators, convert them to lists
|
# cx_Oracle doesn't support iterators, convert them to lists
|
||||||
|
@ -717,12 +718,12 @@ class FormatStylePlaceholderCursor(object):
|
||||||
return self.cursor.executemany(query,
|
return self.cursor.executemany(query,
|
||||||
[self._param_generator(p) for p in formatted])
|
[self._param_generator(p) for p in formatted])
|
||||||
except Database.IntegrityError as e:
|
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:
|
except Database.DatabaseError as e:
|
||||||
# cx_Oracle <= 4.4.0 wrongly raises a DatabaseError for ORA-01400.
|
# 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):
|
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]
|
six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2])
|
||||||
raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
|
six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2])
|
||||||
|
|
||||||
def fetchone(self):
|
def fetchone(self):
|
||||||
row = self.cursor.fetchone()
|
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.db.backends.postgresql_psycopg2.introspection import DatabaseIntrospection
|
||||||
from django.utils.log import getLogger
|
from django.utils.log import getLogger
|
||||||
from django.utils.safestring import SafeUnicode, SafeString
|
from django.utils.safestring import SafeUnicode, SafeString
|
||||||
|
from django.utils import six
|
||||||
from django.utils.timezone import utc
|
from django.utils.timezone import utc
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -51,17 +52,17 @@ class CursorWrapper(object):
|
||||||
try:
|
try:
|
||||||
return self.cursor.execute(query, args)
|
return self.cursor.execute(query, args)
|
||||||
except Database.IntegrityError as e:
|
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:
|
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):
|
def executemany(self, query, args):
|
||||||
try:
|
try:
|
||||||
return self.cursor.executemany(query, args)
|
return self.cursor.executemany(query, args)
|
||||||
except Database.IntegrityError as e:
|
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:
|
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):
|
def __getattr__(self, attr):
|
||||||
if attr in self.__dict__:
|
if attr in self.__dict__:
|
||||||
|
@ -236,4 +237,4 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
try:
|
try:
|
||||||
return self.connection.commit()
|
return self.connection.commit()
|
||||||
except Database.IntegrityError as e:
|
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.dateparse import parse_date, parse_datetime, parse_time
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.utils.safestring import SafeString
|
from django.utils.safestring import SafeString
|
||||||
|
from django.utils import six
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -348,18 +349,18 @@ class SQLiteCursorWrapper(Database.Cursor):
|
||||||
try:
|
try:
|
||||||
return Database.Cursor.execute(self, query, params)
|
return Database.Cursor.execute(self, query, params)
|
||||||
except Database.IntegrityError as e:
|
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:
|
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):
|
def executemany(self, query, param_list):
|
||||||
query = self.convert_query(query)
|
query = self.convert_query(query)
|
||||||
try:
|
try:
|
||||||
return Database.Cursor.executemany(self, query, param_list)
|
return Database.Cursor.executemany(self, query, param_list)
|
||||||
except Database.IntegrityError as e:
|
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:
|
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):
|
def convert_query(self, query):
|
||||||
return FORMAT_QMARK_REGEX.sub('?', query).replace('%%','%')
|
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.deletion import Collector
|
||||||
from django.db.models import sql
|
from django.db.models import sql
|
||||||
from django.utils.functional import partition
|
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.
|
# Used to control how many objects are worked with at once in some cases (e.g.
|
||||||
# when deleting objects).
|
# when deleting objects).
|
||||||
|
@ -470,7 +471,7 @@ class QuerySet(object):
|
||||||
return self.get(**lookup), False
|
return self.get(**lookup), False
|
||||||
except self.model.DoesNotExist:
|
except self.model.DoesNotExist:
|
||||||
# Re-raise the IntegrityError with its original traceback.
|
# 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):
|
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.datastructures import MultiValueDict, ImmutableList
|
||||||
from django.utils.encoding import smart_str, iri_to_uri, force_unicode
|
from django.utils.encoding import smart_str, iri_to_uri, force_unicode
|
||||||
from django.utils.http import cookie_date
|
from django.utils.http import cookie_date
|
||||||
|
from django.utils import six
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
RESERVED_CHARS="!*'();:@&=+$,/?%#[]"
|
RESERVED_CHARS="!*'();:@&=+$,/?%#[]"
|
||||||
|
@ -290,7 +291,7 @@ class HttpRequest(object):
|
||||||
try:
|
try:
|
||||||
self._body = self.read()
|
self._body = self.read()
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
raise UnreadablePostError, e, sys.exc_traceback
|
six.reraise(UnreadablePostError, e, sys.exc_traceback)
|
||||||
self._stream = BytesIO(self._body)
|
self._stream = BytesIO(self._body)
|
||||||
return 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.http import urlencode
|
||||||
from django.utils.importlib import import_module
|
from django.utils.importlib import import_module
|
||||||
from django.utils.itercompat import is_iterable
|
from django.utils.itercompat import is_iterable
|
||||||
|
from django.utils import six
|
||||||
from django.db import close_connection
|
from django.db import close_connection
|
||||||
from django.test.utils import ContextList
|
from django.test.utils import ContextList
|
||||||
|
|
||||||
|
@ -381,7 +382,7 @@ class Client(RequestFactory):
|
||||||
if self.exc_info:
|
if self.exc_info:
|
||||||
exc_info = self.exc_info
|
exc_info = self.exc_info
|
||||||
self.exc_info = None
|
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.
|
# Save the client and request that stimulated the response.
|
||||||
response.client = self
|
response.client = self
|
||||||
|
|
Loading…
Reference in New Issue