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:
parent
502e9a5ab4
commit
32b8c3e1c0
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
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
|
||||
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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 + (
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -537,6 +537,12 @@ u'123'
|
|||
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()
|
||||
|
|
|
@ -6,6 +6,12 @@ import datetime
|
|||
|
||||
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)
|
||||
|
|
|
@ -8,6 +8,12 @@ import pickle
|
|||
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,
|
||||
|
|
|
@ -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
|
||||
|
|
@ -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]
|
||||
|
||||
"""
|
|
@ -8,12 +8,14 @@ from django.utils import html, checksums
|
|||
|
||||
import timesince
|
||||
import datastructures
|
||||
import itercompat
|
||||
from decorators import DecoratorFromMiddlewareTests
|
||||
|
||||
# Extra tests
|
||||
__test__ = {
|
||||
'timesince': timesince,
|
||||
'datastructures': datastructures,
|
||||
'itercompat': itercompat,
|
||||
}
|
||||
|
||||
class TestUtilsHtml(TestCase):
|
||||
|
|
Loading…
Reference in New Issue