diff --git a/django/utils/copycompat.py b/django/utils/copycompat.py new file mode 100644 index 0000000000..bd1a761f8a --- /dev/null +++ b/django/utils/copycompat.py @@ -0,0 +1,18 @@ +""" +Fixes Python 2.4's failure to deepcopy unbound functions. +""" + +import copy +import types +import warnings + +warnings.warn("django.utils.copycompat is deprecated; use the native copy module instead", + PendingDeprecationWarning) + +# Monkeypatch copy's deepcopy registry to handle functions correctly. +if (hasattr(copy, '_deepcopy_dispatch') and types.FunctionType not in copy._deepcopy_dispatch): + copy._deepcopy_dispatch[types.FunctionType] = copy._deepcopy_atomic + +# Pose as the copy module now. +del copy, types +from copy import * diff --git a/django/utils/hashcompat.py b/django/utils/hashcompat.py new file mode 100644 index 0000000000..57435b14be --- /dev/null +++ b/django/utils/hashcompat.py @@ -0,0 +1,24 @@ +""" +The md5 and sha modules are deprecated since Python 2.5, replaced by the +hashlib module containing both hash algorithms. Here, we provide a common +interface to the md5 and sha constructors, depending on system version. +""" +import sys +import warnings + +warnings.warn("django.utils.hashcompat is deprecated; use hashlib instead", + PendingDeprecationWarning) + +if sys.version_info >= (2, 5): + import hashlib + md5_constructor = hashlib.md5 + md5_hmac = md5_constructor + sha_constructor = hashlib.sha1 + sha_hmac = sha_constructor +else: + import md5 + md5_constructor = md5.new + md5_hmac = md5 + import sha + sha_constructor = sha.new + sha_hmac = sha diff --git a/django/utils/itercompat.py b/django/utils/itercompat.py index b302e22b2a..38058e227c 100644 --- a/django/utils/itercompat.py +++ b/django/utils/itercompat.py @@ -5,6 +5,7 @@ these implementations if necessary. """ import itertools +import warnings # Fallback for Python 2.4, Python 2.5 def product(*args, **kwds): @@ -31,3 +32,19 @@ def is_iterable(x): return False else: return True + +def all(iterable): + warnings.warn("django.utils.itercompat.all is deprecated; use the native version instead", + PendingDeprecationWarning) + for item in iterable: + if not item: + return False + return True + +def any(iterable): + warnings.warn("django.utils.itercompat.any is deprecated; use the native version instead", + PendingDeprecationWarning) + for item in iterable: + if item: + return True + return False diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt index 72152544f0..b1f0286384 100644 --- a/docs/internals/deprecation.txt +++ b/docs/internals/deprecation.txt @@ -171,6 +171,14 @@ their deprecation, as per the :ref:`Django deprecation policy with a trailing slash to ensure there is a consistent way to combine paths in templates. + * 1.6 + + * The compatibility modules ``django.utils.copycompat`` and + ``django.utils.hashcompat`` as well as the functions + ``django.utils.itercompat.all`` and ``django.utils.itercompat.any`` + have been deprecated since the 1.4 release. The native versions + should be used instead. + * 2.0 * ``django.views.defaults.shortcut()``. This function has been moved to ``django.contrib.contenttypes.views.shortcut()`` as part of the