Skip to content

Commit

Permalink
Removed some conditional code only needed under Python 2.6.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaugustin committed Jul 1, 2013
1 parent a763915 commit d5589b4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 25 deletions.
12 changes: 4 additions & 8 deletions django/conf/__init__.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -59,14 +59,10 @@ def _configure_logging(self):
Setup logging from LOGGING_CONFIG and LOGGING settings. Setup logging from LOGGING_CONFIG and LOGGING settings.
""" """
if not sys.warnoptions: if not sys.warnoptions:
try: # Route warnings through python logging
# Route warnings through python logging logging.captureWarnings(True)
logging.captureWarnings(True) # Allow DeprecationWarnings through the warnings filters
# Allow DeprecationWarnings through the warnings filters warnings.simplefilter("default", DeprecationWarning)
warnings.simplefilter("default", DeprecationWarning)
except AttributeError:
# No captureWarnings on Python 2.6, DeprecationWarnings are on anyway
pass


if self.LOGGING_CONFIG: if self.LOGGING_CONFIG:
from django.utils.log import DEFAULT_LOGGING from django.utils.log import DEFAULT_LOGGING
Expand Down
10 changes: 2 additions & 8 deletions django/db/backends/sqlite3/base.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -78,14 +78,8 @@ def decoder(conv_func):


Database.register_adapter(datetime.datetime, adapt_datetime_with_timezone_support) Database.register_adapter(datetime.datetime, adapt_datetime_with_timezone_support)
Database.register_adapter(decimal.Decimal, util.rev_typecast_decimal) Database.register_adapter(decimal.Decimal, util.rev_typecast_decimal)
if Database.version_info >= (2, 4, 1): Database.register_adapter(str, lambda s: s.decode('utf-8'))
# Starting in 2.4.1, the str type is not accepted anymore, therefore, Database.register_adapter(SafeBytes, lambda s: s.decode('utf-8'))
# we convert all str objects to Unicode
# As registering a adapter for a primitive type causes a small
# slow-down, this adapter is only registered for sqlite3 versions
# needing it (Python 2.6 and up).
Database.register_adapter(str, lambda s: s.decode('utf-8'))
Database.register_adapter(SafeBytes, lambda s: s.decode('utf-8'))


class DatabaseFeatures(BaseDatabaseFeatures): class DatabaseFeatures(BaseDatabaseFeatures):
# SQLite cannot handle us only partially reading from a cursor's result set # SQLite cannot handle us only partially reading from a cursor's result set
Expand Down
4 changes: 1 addition & 3 deletions django/db/models/fields/related.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1362,9 +1362,7 @@ def __init__(self, to, db_constraint=True, **kwargs):
assert not to._meta.abstract, "%s cannot define a relation with abstract class %s" % (self.__class__.__name__, to._meta.object_name) assert not to._meta.abstract, "%s cannot define a relation with abstract class %s" % (self.__class__.__name__, to._meta.object_name)
except AttributeError: # to._meta doesn't exist, so it must be RECURSIVE_RELATIONSHIP_CONSTANT except AttributeError: # to._meta doesn't exist, so it must be RECURSIVE_RELATIONSHIP_CONSTANT
assert isinstance(to, six.string_types), "%s(%r) is invalid. First parameter to ManyToManyField must be either a model, a model name, or the string %r" % (self.__class__.__name__, to, RECURSIVE_RELATIONSHIP_CONSTANT) assert isinstance(to, six.string_types), "%s(%r) is invalid. First parameter to ManyToManyField must be either a model, a model name, or the string %r" % (self.__class__.__name__, to, RECURSIVE_RELATIONSHIP_CONSTANT)
# Python 2.6 and earlier require dictionary keys to be of str type, # Class names must be ASCII in Python 2.x, so we forcibly coerce it here to break early if there's a problem.
# not unicode and class names must be ASCII (in Python 2.x), so we
# forcibly coerce it here (breaks early if there's a problem).
to = str(to) to = str(to)


kwargs['verbose_name'] = kwargs.get('verbose_name', None) kwargs['verbose_name'] = kwargs.get('verbose_name', None)
Expand Down
7 changes: 1 addition & 6 deletions django/db/utils.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -85,12 +85,7 @@ def __exit__(self, exc_type, exc_value, traceback):
): ):
db_exc_type = getattr(self.wrapper.Database, dj_exc_type.__name__) db_exc_type = getattr(self.wrapper.Database, dj_exc_type.__name__)
if issubclass(exc_type, db_exc_type): if issubclass(exc_type, db_exc_type):
# Under Python 2.6, exc_value can still be a string. dj_exc_value = dj_exc_type(*exc_value.args)
try:
args = tuple(exc_value.args)
except AttributeError:
args = (exc_value,)
dj_exc_value = dj_exc_type(*args)
dj_exc_value.__cause__ = exc_value dj_exc_value.__cause__ = exc_value
# Only set the 'errors_occurred' flag for errors that may make # Only set the 'errors_occurred' flag for errors that may make
# the connection unusable. # the connection unusable.
Expand Down

0 comments on commit d5589b4

Please sign in to comment.