diff options
| author | Jannis Leidel <jannis@leidel.info> | 2011-03-30 08:34:05 +0000 |
|---|---|---|
| committer | Jannis Leidel <jannis@leidel.info> | 2011-03-30 08:34:05 +0000 |
| commit | 37ed6f26812e960a034cb1312257bf7436bad965 (patch) | |
| tree | 758256dd6b4acda837bdfc83ea97994cd3560137 /django/utils | |
| parent | 99b2728b74cc33afc0a3ee15a0ed23c749ac63ab (diff) | |
Re-added a few compatibility modules that were removed in r15927 to lower the impact on 3rd party apps.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15944 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/copycompat.py | 18 | ||||
| -rw-r--r-- | django/utils/hashcompat.py | 24 | ||||
| -rw-r--r-- | django/utils/itercompat.py | 17 |
3 files changed, 59 insertions, 0 deletions
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 |
