Author: jezdez
Date: 2011-03-30 01:34:05 -0700 (Wed, 30 Mar 2011)
New Revision: 15944

Added:
   django/trunk/django/utils/copycompat.py
   django/trunk/django/utils/hashcompat.py
Modified:
   django/trunk/django/utils/itercompat.py
   django/trunk/docs/internals/deprecation.txt
Log:
Re-added a few compatibility modules that were removed in r15927 to lower the 
impact on 3rd party apps.

Added: django/trunk/django/utils/copycompat.py
===================================================================
--- django/trunk/django/utils/copycompat.py                             (rev 0)
+++ django/trunk/django/utils/copycompat.py     2011-03-30 08:34:05 UTC (rev 
15944)
@@ -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 *

Added: django/trunk/django/utils/hashcompat.py
===================================================================
--- django/trunk/django/utils/hashcompat.py                             (rev 0)
+++ django/trunk/django/utils/hashcompat.py     2011-03-30 08:34:05 UTC (rev 
15944)
@@ -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

Modified: django/trunk/django/utils/itercompat.py
===================================================================
--- django/trunk/django/utils/itercompat.py     2011-03-29 10:25:18 UTC (rev 
15943)
+++ django/trunk/django/utils/itercompat.py     2011-03-30 08:34:05 UTC (rev 
15944)
@@ -5,6 +5,7 @@
 """
 
 import itertools
+import warnings
 
 # Fallback for Python 2.4, Python 2.5
 def product(*args, **kwds):
@@ -31,3 +32,19 @@
         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

Modified: django/trunk/docs/internals/deprecation.txt
===================================================================
--- django/trunk/docs/internals/deprecation.txt 2011-03-29 10:25:18 UTC (rev 
15943)
+++ django/trunk/docs/internals/deprecation.txt 2011-03-30 08:34:05 UTC (rev 
15944)
@@ -171,6 +171,14 @@
           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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to