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
This commit is contained in:
Russell Keith-Magee 2008-07-13 08:48:18 +00:00
parent 502e9a5ab4
commit 32b8c3e1c0
13 changed files with 80 additions and 2 deletions

View File

@ -67,3 +67,8 @@ def is_iterable(x):
else: else:
return True return True
def sorted(in_value):
"A naive implementation of sorted"
out_value = in_value[:]
out_value.sort()
return out_value

View File

@ -4,12 +4,18 @@
This is a basic model with only two non-primary-key fields. This is a basic model with only two non-primary-key fields.
""" """
# Python 2.3 doesn't have set as a builtin
try: try:
set set
except NameError: except NameError:
from sets import Set as set 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 from django.db import models
class Article(models.Model): class Article(models.Model):

View File

@ -8,6 +8,11 @@ Alternatively, use positional arguments, and pass one or more expressions of
clauses using the variable ``django.db.models.Q`` (or any object with an clauses using the variable ``django.db.models.Q`` (or any object with an
add_to_query method). 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 from django.db import models

View File

@ -1,4 +1,9 @@
from django.core.management.base import AppCommand 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): class Command(AppCommand):
help = 'Test Application-based commands' help = 'Test Application-based commands'

View File

@ -1,5 +1,10 @@
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from optparse import make_option 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): class Command(BaseCommand):
option_list = BaseCommand.option_list + ( option_list = BaseCommand.option_list + (

View File

@ -1,4 +1,9 @@
from django.core.management.base import LabelCommand 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): class Command(LabelCommand):
help = "Test Label-based commands" help = "Test Label-based commands"

View File

@ -1,4 +1,9 @@
from django.core.management.base import NoArgsCommand 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): class Command(NoArgsCommand):
help = "Test No-args commands" help = "Test No-args commands"

View File

@ -537,6 +537,12 @@ u'123'
from django.template.defaultfilters import * from django.template.defaultfilters import *
import datetime import datetime
# Python 2.3 doesn't have sorted()
try:
sorted
except NameError:
from django.utils.itercompat import sorted
if __name__ == '__main__': if __name__ == '__main__':
import doctest import doctest
doctest.testmod() doctest.testmod()

View File

@ -6,6 +6,12 @@ import datetime
from django.db import models 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): class Place(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
address = models.CharField(max_length=80) address = models.CharField(max_length=80)

View File

@ -8,6 +8,12 @@ import pickle
from django.db import models from django.db import models
from django.db.models.query import Q 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): class Tag(models.Model):
name = models.CharField(max_length=10) name = models.CharField(max_length=10)
parent = models.ForeignKey('self', blank=True, null=True, parent = models.ForeignKey('self', blank=True, null=True,

View File

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

View File

@ -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 File

@ -8,12 +8,14 @@ from django.utils import html, checksums
import timesince import timesince
import datastructures import datastructures
import itercompat
from decorators import DecoratorFromMiddlewareTests from decorators import DecoratorFromMiddlewareTests
# Extra tests # Extra tests
__test__ = { __test__ = {
'timesince': timesince, 'timesince': timesince,
'datastructures': datastructures, 'datastructures': datastructures,
'itercompat': itercompat,
} }
class TestUtilsHtml(TestCase): class TestUtilsHtml(TestCase):