Commits

Anonymous committed 03b3f6a

Fixed #7718 -- Added a naive implementation of sorted() for Python 2.3 compatibility, and modified test cases to import the function when required.

Comments (0)

Files changed (13)

django/utils/itercompat.py

     else:
         return True
 
+def sorted(in_value):
+    "A naive implementation of sorted"
+    out_value = in_value[:]
+    out_value.sort()
+    return out_value

tests/modeltests/basic/models.py

 
 This is a basic model with only two non-primary-key fields.
 """
-
+# Python 2.3 doesn't have set as a builtin
 try:
     set
 except NameError:
     from sets import Set as set
 
+# Python 2.3 doesn't have sorted()
+try:
+    sorted
+except NameError:
+    from django.utils.itercompat import sorted
+
 from django.db import models
 
 class Article(models.Model):

tests/modeltests/or_lookups/models.py

 clauses using the variable ``django.db.models.Q`` (or any object with an
 add_to_query method).
 """
+# Python 2.3 doesn't have sorted()
+try:
+    sorted
+except NameError:
+    from django.utils.itercompat import sorted
 
 from django.db import models
 

tests/regressiontests/admin_scripts/management/commands/app_command.py

 from django.core.management.base import AppCommand
+# Python 2.3 doesn't have sorted()
+try:
+    sorted
+except NameError:
+    from django.utils.itercompat import sorted
 
 class Command(AppCommand):
     help = 'Test Application-based commands'

tests/regressiontests/admin_scripts/management/commands/base_command.py

 from django.core.management.base import BaseCommand
 from optparse import make_option
+# Python 2.3 doesn't have sorted()
+try:
+    sorted
+except NameError:
+    from django.utils.itercompat import sorted
 
 class Command(BaseCommand):
     option_list = BaseCommand.option_list + (

tests/regressiontests/admin_scripts/management/commands/label_command.py

 from django.core.management.base import LabelCommand
+# Python 2.3 doesn't have sorted()
+try:
+    sorted
+except NameError:
+    from django.utils.itercompat import sorted
 
 class Command(LabelCommand):
     help = "Test Label-based commands"

tests/regressiontests/admin_scripts/management/commands/noargs_command.py

 from django.core.management.base import NoArgsCommand
+# Python 2.3 doesn't have sorted()
+try:
+    sorted
+except NameError:
+    from django.utils.itercompat import sorted
 
 class Command(NoArgsCommand):
     help = "Test No-args commands"

tests/regressiontests/defaultfilters/tests.py

 from django.template.defaultfilters import *
 import datetime
 
+# Python 2.3 doesn't have sorted()
+try:
+    sorted
+except NameError:
+    from django.utils.itercompat import sorted
+
 if __name__ == '__main__':
     import doctest
     doctest.testmod()

tests/regressiontests/model_inheritance_regress/models.py

 
 from django.db import models
 
+# Python 2.3 doesn't have sorted()
+try:
+    sorted
+except NameError:
+    from django.utils.itercompat import sorted
+
 class Place(models.Model):
     name = models.CharField(max_length=50)
     address = models.CharField(max_length=80)

tests/regressiontests/queries/models.py

 from django.db import models
 from django.db.models.query import Q
 
+# Python 2.3 doesn't have sorted()
+try:
+    sorted
+except NameError:
+    from django.utils.itercompat import sorted
+                
 class Tag(models.Model):
     name = models.CharField(max_length=10)
     parent = models.ForeignKey('self', blank=True, null=True,

tests/regressiontests/utils/datastructures.py

 ['one', 'second-two']
 >>> d.values() # Here the order of SortedDict values *is* what we are testing
 ['second-two', 'one']
-"""
+"""
+
+# Python 2.3 doesn't have sorted()
+try:
+    sorted
+except NameError:
+    from django.utils.itercompat import sorted
+        

tests/regressiontests/utils/itercompat.py

+"""
+# Tests of the utils itercompat library.
+
+>>> from django.utils.itercompat import sorted as compat_sorted
+
+# Check the replacement version of sorted
+>>> x = [5,1,4,2,3]
+>>> y = compat_sorted(x)
+>>> print y
+[1, 2, 3, 4, 5]
+
+>>> print x 
+[5, 1, 4, 2, 3]
+
+"""

tests/regressiontests/utils/tests.py

 
 import timesince
 import datastructures
+import itercompat
 from decorators import DecoratorFromMiddlewareTests
 
 # Extra tests
 __test__ = {
     'timesince': timesince,
     'datastructures': datastructures,
+    'itercompat': itercompat,
 }
 
 class TestUtilsHtml(TestCase):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.