Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.1.X] Fixed #11753 - Q objects with callables no longer explode on …

…Python 2.4. Thanks, Jeremy Dunck.

Backport of [11901].

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@11903 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 321fe61f642aa26b638a04c25f4c27534c4c2158 1 parent de2c7d9
Jacob Kaplan-Moss authored December 17, 2009
2  django/contrib/admin/widgets.py
@@ -2,7 +2,7 @@
2 2
 Form Widget classes specific to the Django admin site.
3 3
 """
4 4
 
5  
-import copy
  5
+import django.utils.copycompat as copy
6 6
 
7 7
 from django import forms
8 8
 from django.forms.widgets import RadioFieldRenderer
2  django/contrib/gis/geos/tests/test_geos.py
@@ -778,7 +778,7 @@ def test21_test_gdal(self):
778 778
 
779 779
     def test22_copy(self):
780 780
         "Testing use with the Python `copy` module."
781  
-        import copy
  781
+        import django.utils.copycompat as copy
782 782
         poly = GEOSGeometry('POLYGON((0 0, 0 23, 23 23, 23 0, 0 0), (5 5, 5 10, 10 10, 10 5, 5 5))')
783 783
         cpy1 = copy.copy(poly)
784 784
         cpy2 = copy.deepcopy(poly)
4  django/contrib/gis/geos/tests/test_geos_mutation.py
@@ -2,9 +2,11 @@
2 2
 # Modified from original contribution by Aryeh Leib Taurog, which was
3 3
 # released under the New BSD license.
4 4
 import unittest
  5
+
  6
+import django.utils.copycompat as copy
  7
+
5 8
 from django.contrib.gis.geos import *
6 9
 from django.contrib.gis.geos.error import GEOSIndexError
7  
-import copy
8 10
 
9 11
 def getItem(o,i): return o[i]
10 12
 def delItem(o,i): del o[i]
2  django/contrib/gis/tests/layermap/tests.py
... ...
@@ -1,10 +1,10 @@
1 1
 import os, unittest
2  
-from copy import copy
3 2
 from decimal import Decimal
4 3
 from models import City, County, CountyFeat, Interstate, ICity1, ICity2, State, city_mapping, co_mapping, cofeat_mapping, inter_mapping
5 4
 from django.contrib.gis.db.backend import SpatialBackend
6 5
 from django.contrib.gis.utils.layermapping import LayerMapping, LayerMapError, InvalidDecimal, MissingForeignKey
7 6
 from django.contrib.gis.gdal import DataSource
  7
+from django.utils.copycompat import copy
8 8
 
9 9
 shp_path = os.path.dirname(__file__)
10 10
 city_shp = os.path.join(shp_path, '../data/cities/cities.shp')
2  django/db/models/base.py
... ...
@@ -1,4 +1,3 @@
1  
-import copy
2 1
 import types
3 2
 import sys
4 3
 import os
@@ -18,6 +17,7 @@
18 17
 from django.db import connection, transaction, DatabaseError
19 18
 from django.db.models import signals
20 19
 from django.db.models.loading import register_models, get_model
  20
+import django.utils.copycompat as copy
21 21
 from django.utils.functional import curry
22 22
 from django.utils.encoding import smart_str, force_unicode, smart_unicode
23 23
 from django.conf import settings
2  django/db/models/expressions.py
... ...
@@ -1,7 +1,7 @@
1  
-from copy import deepcopy
2 1
 from datetime import datetime
3 2
 
4 3
 from django.utils import tree
  4
+from django.utils.copycompat import deepcopy
5 5
 
6 6
 class ExpressionNode(tree.Node):
7 7
     """
8  django/db/models/fields/__init__.py
... ...
@@ -1,12 +1,10 @@
1  
-import copy
2 1
 import datetime
  2
+import decimal
3 3
 import os
4 4
 import re
5 5
 import time
6  
-try:
7  
-    import decimal
8  
-except ImportError:
9  
-    from django.utils import _decimal as decimal    # for Python 2.3
  6
+
  7
+import django.utils.copycompat as copy
10 8
 
11 9
 from django.db import connection
12 10
 from django.db.models import signals
3  django/db/models/fields/files.py
... ...
@@ -1,7 +1,8 @@
1  
-import copy
2 1
 import datetime
3 2
 import os
4 3
 
  4
+import django.utils.copycompat as copy
  5
+
5 6
 from django.conf import settings
6 7
 from django.db.models.fields import Field
7 8
 from django.core.files.base import File, ContentFile
3  django/db/models/manager.py
... ...
@@ -1,5 +1,4 @@
1  
-import copy
2  
-
  1
+import django.utils.copycompat as copy
3 2
 from django.db.models.query import QuerySet, EmptyQuerySet, insert_query
4 3
 from django.db.models import signals
5 4
 from django.db.models.fields import FieldDoesNotExist
3  django/db/models/query.py
@@ -7,13 +7,12 @@
7 7
 except NameError:
8 8
     from sets import Set as set     # Python 2.3 fallback
9 9
 
10  
-from copy import deepcopy
11  
-
12 10
 from django.db import connection, transaction, IntegrityError
13 11
 from django.db.models.aggregates import Aggregate
14 12
 from django.db.models.fields import DateField
15 13
 from django.db.models.query_utils import Q, select_related_descend, CollectedObjects, CyclicDependency, deferred_class_factory
16 14
 from django.db.models import signals, sql
  15
+from django.utils.copycompat import deepcopy
17 16
 
18 17
 
19 18
 # Used to control how many objects are worked with at once in some cases (e.g.
7  django/db/models/query_utils.py
@@ -7,16 +7,11 @@
7 7
 """
8 8
 
9 9
 import weakref
10  
-from copy import deepcopy
  10
+from django.utils.copycompat import deepcopy
11 11
 
12 12
 from django.utils import tree
13 13
 from django.utils.datastructures import SortedDict
14 14
 
15  
-try:
16  
-    sorted
17  
-except NameError:
18  
-    from django.utils.itercompat import sorted  # For Python 2.3.
19  
-
20 15
 
21 16
 class CyclicDependency(Exception):
22 17
     """
3  django/db/models/sql/query.py
@@ -7,8 +7,7 @@
7 7
 all about the internals of models in order to get the information it needs.
8 8
 """
9 9
 
10  
-from copy import deepcopy
11  
-
  10
+from django.utils.copycompat import deepcopy
12 11
 from django.utils.tree import Node
13 12
 from django.utils.datastructures import SortedDict
14 13
 from django.utils.encoding import force_unicode
13  django/forms/fields.py
@@ -2,28 +2,19 @@
2 2
 Field classes.
3 3
 """
4 4
 
5  
-import copy
6 5
 import datetime
7 6
 import os
8 7
 import re
9 8
 import time
10 9
 import urlparse
  10
+from decimal import Decimal, DecimalException
11 11
 try:
12 12
     from cStringIO import StringIO
13 13
 except ImportError:
14 14
     from StringIO import StringIO
15 15
 
16  
-# Python 2.3 fallbacks
17  
-try:
18  
-    from decimal import Decimal, DecimalException
19  
-except ImportError:
20  
-    from django.utils._decimal import Decimal, DecimalException
21  
-try:
22  
-    set
23  
-except NameError:
24  
-    from sets import Set as set
25  
-
26 16
 import django.core.exceptions
  17
+import django.utils.copycompat as copy
27 18
 from django.utils.translation import ugettext_lazy as _
28 19
 from django.utils.encoding import smart_unicode, smart_str
29 20
 
3  django/forms/forms.py
@@ -2,8 +2,7 @@
2 2
 Form classes
3 3
 """
4 4
 
5  
-from copy import deepcopy
6  
-
  5
+from django.utils.copycompat import deepcopy
7 6
 from django.utils.datastructures import SortedDict
8 7
 from django.utils.html import conditional_escape
9 8
 from django.utils.encoding import StrAndUnicode, smart_unicode, force_unicode
7  django/forms/widgets.py
@@ -2,12 +2,7 @@
2 2
 HTML Widget classes
3 3
 """
4 4
 
5  
-try:
6  
-    set
7  
-except NameError:
8  
-    from sets import Set as set   # Python 2.3 fallback
9  
-
10  
-import copy
  5
+import django.utils.copycompat as copy
11 6
 from itertools import chain
12 7
 from django.conf import settings
13 8
 from django.utils.datastructures import MultiValueDict, MergeDict
2  django/http/__init__.py
@@ -183,7 +183,7 @@ def __copy__(self):
183 183
         return result
184 184
 
185 185
     def __deepcopy__(self, memo):
186  
-        import copy
  186
+        import django.utils.copycompat as copy
187 187
         result = self.__class__('', mutable=True)
188 188
         memo[id(self)] = result
189 189
         for key, value in dict.items(self):
2  django/utils/_decimal.py
@@ -134,7 +134,7 @@
134 134
     'setcontext', 'getcontext'
135 135
 ]
136 136
 
137  
-import copy as _copy
  137
+import django.utils.copycompat as _copy
138 138
 
139 139
 #Rounding
140 140
 ROUND_DOWN = 'ROUND_DOWN'
14  django/utils/copycompat.py
... ...
@@ -0,0 +1,14 @@
  1
+"""
  2
+Fixes Python 2.4's failure to deepcopy unbound functions.
  3
+"""
  4
+
  5
+import copy
  6
+import types
  7
+
  8
+# Monkeypatch copy's deepcopy registry to handle functions correctly.
  9
+if (hasattr(copy, '_deepcopy_dispatch') and types.FunctionType not in copy._deepcopy_dispatch):
  10
+    copy._deepcopy_dispatch[types.FunctionType] = copy._deepcopy_atomic
  11
+
  12
+# Pose as the copy module now.
  13
+del copy, types
  14
+from copy import *
4  django/utils/datastructures.py
... ...
@@ -1,4 +1,4 @@
1  
-from copy import deepcopy
  1
+from django.utils.copycompat import deepcopy
2 2
 
3 3
 
4 4
 class MergeDict(object):
@@ -214,7 +214,7 @@ def __copy__(self):
214 214
         return self.__class__(super(MultiValueDict, self).items())
215 215
 
216 216
     def __deepcopy__(self, memo=None):
217  
-        import copy
  217
+        import django.utils.copycompat as copy
218 218
         if memo is None:
219 219
             memo = {}
220 220
         result = self.__class__()
6  django/utils/functional.py
@@ -331,8 +331,10 @@ def __deepcopy__(self, memo):
331 331
             memo[id(self)] = result
332 332
             return result
333 333
         else:
334  
-            import copy
335  
-            return copy.deepcopy(self._wrapped, memo)
  334
+            # Changed to use deepcopy from copycompat, instead of copy
  335
+            # For Python 2.4.
  336
+            from django.utils.copycompat import deepcopy
  337
+            return deepcopy(self._wrapped, memo)
336 338
 
337 339
     # Need to pretend to be the wrapped class, for the sake of objects that care
338 340
     # about this (especially in equality tests)
2  django/utils/tree.py
@@ -3,7 +3,7 @@
3 3
 ORM.
4 4
 """
5 5
 
6  
-from copy import deepcopy
  6
+from django.utils.copycompat import deepcopy
7 7
 
8 8
 class Node(object):
9 9
     """
2  tests/regressiontests/dispatch/tests/test_dispatcher.py
... ...
@@ -1,8 +1,8 @@
1 1
 from django.dispatch import Signal
2 2
 import unittest
3  
-import copy
4 3
 import sys
5 4
 import gc
  5
+import django.utils.copycompat as copy
6 6
 
7 7
 if sys.platform.startswith('java'):
8 8
     def garbage_collect():
3  tests/regressiontests/extra_regress/models.py
... ...
@@ -1,6 +1,7 @@
1  
-import copy
2 1
 import datetime
3 2
 
  3
+import django.utils.copycompat as copy
  4
+
4 5
 from django.contrib.auth.models import User
5 6
 from django.db import models
6 7
 from django.db.models.query import Q
2  tests/regressiontests/utils/tests.py
@@ -220,7 +220,7 @@ def test_class(self):
220 220
         self.assertEqual(_ComplexObject, SimpleLazyObject(complex_object).__class__)
221 221
 
222 222
     def test_deepcopy(self):
223  
-        import copy
  223
+        import django.utils.copycompat as copy
224 224
         # Check that we *can* do deep copy, and that it returns the right
225 225
         # objects.
226 226
 

0 notes on commit 321fe61

Please sign in to comment.
Something went wrong with that request. Please try again.