Permalink
Browse files

Removed a bunch more Python 2.4 workarounds now that we don't support…

… that version. Refs #15702 -- thanks to jonash for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15927 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent a87be35 commit 13864703bc1d5dd4dac63c96c6a4b42a392bc57f @adrianholovaty adrianholovaty committed Mar 28, 2011
Showing with 113 additions and 326 deletions.
  1. +11 −14 django/core/mail/backends/console.py
  2. +1 −4 django/core/mail/message.py
  3. +0 −5 django/core/management/validation.py
  4. +0 −1 django/db/__init__.py
  5. +3 −4 django/db/backends/util.py
  6. +4 −3 django/db/models/base.py
  7. +2 −3 django/db/models/deletion.py
  8. +0 −2 django/db/models/expressions.py
  9. +1 −2 django/db/models/fields/__init__.py
  10. +0 −2 django/db/models/fields/files.py
  11. +1 −1 django/db/models/manager.py
  12. +0 −5 django/db/models/options.py
  13. +2 −2 django/db/models/query.py
  14. +0 −1 django/db/models/query_utils.py
  15. +7 −7 django/db/models/sql/query.py
  16. +4 −17 django/db/transaction.py
  17. +1 −1 django/dispatch/saferef.py
  18. +1 −5 django/forms/extras/widgets.py
  19. +1 −1 django/forms/fields.py
  20. +2 −2 django/forms/forms.py
  21. +3 −2 django/forms/widgets.py
  22. +1 −1 django/http/__init__.py
  23. +2 −2 django/middleware/common.py
  24. +3 −4 django/middleware/csrf.py
  25. +4 −3 django/template/base.py
  26. +2 −5 django/template/defaultfilters.py
  27. +2 −2 django/template/loaders/cached.py
  28. +2 −2 django/templatetags/cache.py
  29. +1 −1 django/test/client.py
  30. +0 −6 django/test/simple.py
  31. +3 −12 django/test/testcases.py
  32. +5 −5 django/utils/cache.py
  33. +0 −14 django/utils/copycompat.py
  34. +4 −8 django/utils/crypto.py
  35. +3 −6 django/utils/datastructures.py
  36. +1 −4 django/utils/decorators.py
  37. +3 −58 django/utils/functional.py
  38. +0 −20 django/utils/hashcompat.py
  39. +0 −12 django/utils/itercompat.py
  40. +4 −33 django/utils/log.py
  41. +3 −3 django/utils/tree.py
  42. +1 −5 django/views/decorators/cache.py
  43. +1 −5 django/views/decorators/csrf.py
  44. +1 −5 django/views/decorators/http.py
  45. +1 −5 django/views/decorators/vary.py
  46. +1 −1 django/views/generic/base.py
  47. +3 −3 tests/regressiontests/cache/tests.py
  48. +2 −2 tests/regressiontests/comment_tests/tests/comment_form_tests.py
  49. +0 −1 tests/regressiontests/dispatch/tests/test_dispatcher.py
  50. +1 −2 tests/regressiontests/extra_regress/models.py
  51. +4 −3 tests/regressiontests/file_uploads/tests.py
  52. +3 −3 tests/regressiontests/file_uploads/views.py
  53. +3 −2 tests/regressiontests/forms/tests/widgets.py
  54. +2 −2 tests/regressiontests/introspection/tests.py
  55. +2 −1 tests/regressiontests/utils/datastructures.py
  56. +1 −1 tests/regressiontests/utils/simplelazyobject.py
@@ -18,20 +18,17 @@ def send_messages(self, email_messages):
return
self._lock.acquire()
try:
- # The try-except is nested to allow for
- # Python 2.4 support (Refs #12147)
- try:
- stream_created = self.open()
- for message in email_messages:
- self.stream.write('%s\n' % message.message().as_string())
- self.stream.write('-'*79)
- self.stream.write('\n')
- self.stream.flush() # flush after each message
- if stream_created:
- self.close()
- except:
- if not self.fail_silently:
- raise
+ stream_created = self.open()
+ for message in email_messages:
+ self.stream.write('%s\n' % message.message().as_string())
+ self.stream.write('-'*79)
+ self.stream.write('\n')
+ self.stream.flush() # flush after each message
+ if stream_created:
+ self.close()
+ except:
+ if not self.fail_silently:
+ raise
finally:
self._lock.release()
return len(email_messages)
@@ -3,10 +3,7 @@
import random
import time
from email import Charset, Encoders
-try:
- from email.generator import Generator
-except ImportError:
- from email.Generator import Generator # TODO: Remove when remove Python 2.4 support
+from email.generator import Generator
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
@@ -4,11 +4,6 @@
from django.core.management.color import color_style
from django.utils.itercompat import is_iterable
-try:
- any
-except NameError:
- from django.utils.itercompat import any
-
class ModelErrorCollection:
def __init__(self, outfile=sys.stdout):
self.errors = []
@@ -3,7 +3,6 @@
from django.core.exceptions import ImproperlyConfigured
from django.db.utils import ConnectionHandler, ConnectionRouter, load_backend, DEFAULT_DB_ALIAS, \
DatabaseError, IntegrityError
-from django.utils.functional import curry
__all__ = ('backend', 'connection', 'connections', 'router', 'DatabaseError',
'IntegrityError', 'DEFAULT_DB_ALIAS')
@@ -1,8 +1,8 @@
import datetime
import decimal
+import hashlib
from time import time
-from django.utils.hashcompat import md5_constructor
from django.utils.log import getLogger
@@ -130,9 +130,8 @@ def truncate_name(name, length=None, hash_len=4):
if length is None or len(name) <= length:
return name
- hash = md5_constructor(name).hexdigest()[:hash_len]
-
- return '%s%s' % (name[:length-hash_len], hash)
+ hsh = hashlib.md5(name).hexdigest()[:hash_len]
+ return '%s%s' % (name[:length-hash_len], hsh)
def format_number(value, max_digits, decimal_places):
"""
@@ -1,5 +1,7 @@
-import types
+import copy
import sys
+import types
+from functools import update_wrapper
from itertools import izip
import django.db.models.manager # Imported to register signal handler.
@@ -17,8 +19,7 @@
from django.db.models import signals
from django.db.models.loading import register_models, get_model
from django.utils.translation import ugettext_lazy as _
-import django.utils.copycompat as copy
-from django.utils.functional import curry, update_wrapper
+from django.utils.functional import curry
from django.utils.encoding import smart_str, force_unicode
from django.utils.text import get_text_list, capfirst
from django.conf import settings
@@ -1,17 +1,16 @@
+from functools import wraps
from operator import attrgetter
from django.db import connections, transaction, IntegrityError
from django.db.models import signals, sql
from django.db.models.sql.constants import GET_ITERATOR_CHUNK_SIZE
from django.utils.datastructures import SortedDict
-from django.utils.functional import wraps
class ProtectedError(IntegrityError):
def __init__(self, msg, protected_objects):
self.protected_objects = protected_objects
- # TODO change this to use super() when we drop Python 2.4
- IntegrityError.__init__(self, msg, protected_objects)
+ super(ProtectedError, self).__init__(msg, protected_objects)
def CASCADE(collector, field, sub_objs, using):
@@ -1,7 +1,5 @@
import datetime
-
from django.utils import tree
-from django.utils.copycompat import deepcopy
class ExpressionNode(tree.Node):
"""
@@ -1,12 +1,11 @@
+import copy
import datetime
import decimal
import re
import time
import math
from itertools import tee
-import django.utils.copycompat as copy
-
from django.db import connection
from django.db.models.fields.subclassing import LegacyConnection
from django.db.models.query_utils import QueryWrapper
@@ -1,8 +1,6 @@
import datetime
import os
-import django.utils.copycompat as copy
-
from django.conf import settings
from django.db.models.fields import Field
from django.core.files.base import File, ContentFile
@@ -1,4 +1,4 @@
-from django.utils import copycompat as copy
+import copy
from django.conf import settings
from django.db import router
from django.db.models.query import QuerySet, EmptyQuerySet, insert_query, RawQuerySet
@@ -11,11 +11,6 @@
from django.utils.encoding import force_unicode, smart_str
from django.utils.datastructures import SortedDict
-try:
- all
-except NameError:
- from django.utils.itercompat import all
-
# Calculate the verbose_name by converting from InitialCaps to "lowercase with spaces".
get_verbose_name = lambda class_name: re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))', ' \\1', class_name).lower().strip()
@@ -2,6 +2,7 @@
The main QuerySet implementation. This provides the public API for the ORM.
"""
+import copy
from itertools import izip
from django.db import connections, router, transaction, IntegrityError
@@ -11,7 +12,6 @@
deferred_class_factory, InvalidQuery)
from django.db.models.deletion import Collector
from django.db.models import signals, sql
-from django.utils.copycompat import deepcopy
# Used to control how many objects are worked with at once in some cases (e.g.
# when deleting objects).
@@ -51,7 +51,7 @@ def __deepcopy__(self, memo):
if k in ('_iter','_result_cache'):
obj.__dict__[k] = None
else:
- obj.__dict__[k] = deepcopy(v, memo)
+ obj.__dict__[k] = copy.deepcopy(v, memo)
return obj
def __getstate__(self):
@@ -7,7 +7,6 @@
"""
import weakref
-from django.utils.copycompat import deepcopy
from django.db.backends import util
from django.utils import tree
@@ -7,7 +7,7 @@
all about the internals of models in order to get the information it needs.
"""
-from django.utils.copycompat import deepcopy
+import copy
from django.utils.tree import Node
from django.utils.datastructures import SortedDict
from django.utils.encoding import force_unicode
@@ -244,19 +244,19 @@ def clone(self, klass=None, memo=None, **kwargs):
obj.dupe_avoidance = self.dupe_avoidance.copy()
obj.select = self.select[:]
obj.tables = self.tables[:]
- obj.where = deepcopy(self.where, memo=memo)
+ obj.where = copy.deepcopy(self.where, memo=memo)
obj.where_class = self.where_class
if self.group_by is None:
obj.group_by = None
else:
obj.group_by = self.group_by[:]
- obj.having = deepcopy(self.having, memo=memo)
+ obj.having = copy.deepcopy(self.having, memo=memo)
obj.order_by = self.order_by[:]
obj.low_mark, obj.high_mark = self.low_mark, self.high_mark
obj.distinct = self.distinct
obj.select_related = self.select_related
obj.related_select_cols = []
- obj.aggregates = deepcopy(self.aggregates, memo=memo)
+ obj.aggregates = copy.deepcopy(self.aggregates, memo=memo)
if self.aggregate_select_mask is None:
obj.aggregate_select_mask = None
else:
@@ -279,7 +279,7 @@ def clone(self, klass=None, memo=None, **kwargs):
obj._extra_select_cache = self._extra_select_cache.copy()
obj.extra_tables = self.extra_tables
obj.extra_order_by = self.extra_order_by
- obj.deferred_loading = deepcopy(self.deferred_loading, memo=memo)
+ obj.deferred_loading = copy.deepcopy(self.deferred_loading, memo=memo)
if self.filter_is_sticky and self.used_aliases:
obj.used_aliases = self.used_aliases.copy()
else:
@@ -476,7 +476,7 @@ def combine(self, rhs, connector):
# Now relabel a copy of the rhs where-clause and add it to the current
# one.
if rhs.where:
- w = deepcopy(rhs.where)
+ w = copy.deepcopy(rhs.where)
w.relabel_aliases(change_map)
if not self.where:
# Since 'self' matches everything, add an explicit "include
@@ -497,7 +497,7 @@ def combine(self, rhs, connector):
if isinstance(col, (list, tuple)):
self.select.append((change_map.get(col[0], col[0]), col[1]))
else:
- item = deepcopy(col)
+ item = copy.deepcopy(col)
item.relabel_aliases(change_map)
self.select.append(item)
self.select_fields = rhs.select_fields[:]
@@ -11,12 +11,9 @@
Managed transactions don't do those commits, but will need some kind of manual
or implicit commits or rollbacks.
"""
-import sys
-try:
- from functools import wraps
-except ImportError:
- from django.utils.functional import wraps # Python 2.4 fallback.
+import sys
+from functools import wraps
from django.conf import settings
from django.db import connections, DEFAULT_DB_ALIAS
@@ -209,18 +206,8 @@ def __exit__(self, exc_type, exc_value, traceback):
def __call__(self, func):
@wraps(func)
def inner(*args, **kwargs):
- # Once we drop support for Python 2.4 this block should become:
- # with self:
- # func(*args, **kwargs)
- self.__enter__()
- try:
- res = func(*args, **kwargs)
- except:
- self.__exit__(*sys.exc_info())
- raise
- else:
- self.__exit__(None, None, None)
- return res
+ with self:
+ func(*args, **kwargs)
return inner
def _transaction_func(entering, exiting, using):
@@ -230,7 +230,7 @@ def __call__(self):
if target is not None:
function = self.weakFunc()
if function is not None:
- # Using curry() would be another option, but it erases the
+ # Using partial() would be another option, but it erases the
# "signature" of the function. That is, after a function is
# curried, the inspect module can't be used to determine how
# many arguments the function expects, nor what keyword
@@ -68,11 +68,7 @@ def render(self, name, value, attrs=None):
if settings.USE_L10N:
try:
input_format = get_format('DATE_INPUT_FORMATS')[0]
- # Python 2.4 compatibility:
- # v = datetime.datetime.strptime(value, input_format)
- # would be clearer, but datetime.strptime was added in
- # Python 2.5
- v = datetime.datetime(*(time.strptime(value, input_format)[0:6]))
+ v = datetime.datetime.strptime(value, input_format)
year_val, month_val, day_val = v.year, v.month, v.day
except ValueError:
pass
@@ -2,6 +2,7 @@
Field classes.
"""
+import copy
import datetime
import os
import re
@@ -16,7 +17,6 @@
from django.core.exceptions import ValidationError
from django.core import validators
-import django.utils.copycompat as copy
from django.utils import formats
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_unicode, smart_str
@@ -2,8 +2,8 @@
Form classes
"""
+import copy
from django.core.exceptions import ValidationError
-from django.utils.copycompat import deepcopy
from django.utils.datastructures import SortedDict
from django.utils.html import conditional_escape
from django.utils.encoding import StrAndUnicode, smart_unicode, force_unicode
@@ -89,7 +89,7 @@ def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
# alter self.fields, we create self.fields here by copying base_fields.
# Instances should always modify self.fields; they should not modify
# self.base_fields.
- self.fields = deepcopy(self.base_fields)
+ self.fields = copy.deepcopy(self.base_fields)
def __unicode__(self):
return self.as_table()
@@ -1,13 +1,14 @@
"""
HTML Widget classes
"""
+
+import copy
import datetime
-from itertools import chain
import time
+from itertools import chain
from urlparse import urljoin
from util import flatatt
-import django.utils.copycompat as copy
from django.conf import settings
from django.utils.datastructures import MultiValueDict, MergeDict
from django.utils.html import escape, conditional_escape
@@ -364,7 +364,7 @@ def __copy__(self):
return result
def __deepcopy__(self, memo):
- import django.utils.copycompat as copy
+ import copy
result = self.__class__('', mutable=True, encoding=self.encoding)
memo[id(self)] = result
for key, value in dict.items(self):
Oops, something went wrong. Retry.

0 comments on commit 1386470

Please sign in to comment.