Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #7718 -- Added a naive implementation of sorted() for Python 2.…

…3 compatibility, and modified test cases to import the function when required.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7914 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 32b8c3e1c015902b72ef7caade5c35a10e80fb1a 1 parent 502e9a5
@freakboy3742 freakboy3742 authored
View
5 django/utils/itercompat.py
@@ -67,3 +67,8 @@ def is_iterable(x):
else:
return True
+def sorted(in_value):
+ "A naive implementation of sorted"
+ out_value = in_value[:]
+ out_value.sort()
+ return out_value
View
8 tests/modeltests/basic/models.py
@@ -4,12 +4,18 @@
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):
View
5 tests/modeltests/or_lookups/models.py
@@ -8,6 +8,11 @@
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
View
5 tests/regressiontests/admin_scripts/management/commands/app_command.py
@@ -1,4 +1,9 @@
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'
View
5 tests/regressiontests/admin_scripts/management/commands/base_command.py
@@ -1,5 +1,10 @@
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 + (
View
5 tests/regressiontests/admin_scripts/management/commands/label_command.py
@@ -1,4 +1,9 @@
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"
View
5 tests/regressiontests/admin_scripts/management/commands/noargs_command.py
@@ -1,4 +1,9 @@
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"
View
6 tests/regressiontests/defaultfilters/tests.py
@@ -537,6 +537,12 @@
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()
View
6 tests/regressiontests/model_inheritance_regress/models.py
@@ -6,6 +6,12 @@
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)
View
6 tests/regressiontests/queries/models.py
@@ -8,6 +8,12 @@
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,
View
9 tests/regressiontests/utils/datastructures.py
@@ -48,4 +48,11 @@
['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
+
View
15 tests/regressiontests/utils/itercompat.py
@@ -0,0 +1,15 @@
+"""
+# 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]
+
+"""
View
2  tests/regressiontests/utils/tests.py
@@ -8,12 +8,14 @@
import timesince
import datastructures
+import itercompat
from decorators import DecoratorFromMiddlewareTests
# Extra tests
__test__ = {
'timesince': timesince,
'datastructures': datastructures,
+ 'itercompat': itercompat,
}
class TestUtilsHtml(TestCase):
Please sign in to comment.
Something went wrong with that request. Please try again.