Fixed #12164 -- Removed the Python 2.3 compatibility imports and workarounds. Thanks to timo and claudep for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13094 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2010-05-04 14:00:30 +00:00
parent 7202eb8e31
commit 5211f48ae3
59 changed files with 32 additions and 3399 deletions

View File

@ -12,10 +12,6 @@ from django.utils.html import escape
from django.utils.safestring import mark_safe
from django.utils.text import capfirst
from django.utils.translation import ugettext_lazy, ugettext as _
try:
set
except NameError:
from sets import Set as set # Python 2.3 fallback
def delete_selected(modeladmin, request, queryset):
"""

View File

@ -23,10 +23,6 @@ from django.utils.text import capfirst, get_text_list
from django.utils.translation import ugettext as _
from django.utils.translation import ungettext, ugettext_lazy
from django.utils.encoding import force_unicode
try:
set
except NameError:
from sets import Set as set # Python 2.3 fallback
HORIZONTAL, VERTICAL = 1, 2
# returns the <ul> class for a given radio_admin field

View File

@ -14,10 +14,6 @@ from django.utils.text import capfirst
from django.utils.translation import ugettext_lazy, ugettext as _
from django.views.decorators.cache import never_cache
from django.conf import settings
try:
set
except NameError:
from sets import Set as set # Python 2.3 fallback
ERROR_MESSAGE = ugettext_lazy("Please enter a correct username and password. Note that both fields are case-sensitive.")
LOGIN_FORM_KEY = 'this_is_the_login_form'

View File

@ -2,7 +2,7 @@ import base64
try:
from functools import wraps
except ImportError:
from django.utils.functional import wraps # Python 2.3, 2.4 fallback.
from django.utils.functional import wraps # Python 2.4 fallback.
from django import http, template
from django.conf import settings

View File

@ -9,11 +9,6 @@ from django.utils.translation import ugettext
from django.utils.http import urlencode
import operator
try:
set
except NameError:
from sets import Set as set # Python 2.3 fallback
# The system will display a "Show all" link on the change list only if the
# total result count is less than or equal to this setting.
MAX_SHOW_ALL_ALLOWED = 200

View File

@ -1,8 +1,3 @@
try:
set
except NameError:
from sets import Set as set # Python 2.3 fallback
from django.db import connection
from django.contrib.auth.models import User, Permission

View File

@ -1,7 +1,7 @@
try:
from functools import update_wrapper, wraps
except ImportError:
from django.utils.functional import update_wrapper, wraps # Python 2.3, 2.4 fallback.
from django.utils.functional import update_wrapper, wraps # Python 2.4 fallback.
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.http import HttpResponseRedirect

View File

@ -32,7 +32,7 @@ def security_hash(request, form, *args):
data.append(settings.SECRET_KEY)
# Use HIGHEST_PROTOCOL because it's the most efficient. It requires
# Python 2.3, but Django requires 2.3 anyway, so that's OK.
# Python 2.3, but Django requires 2.4 anyway, so that's OK.
pickled = pickle.dumps(data, pickle.HIGHEST_PROTOCOL)
return md5_constructor(pickled).hexdigest()

View File

@ -10,11 +10,6 @@ from django.utils.encoding import smart_unicode
from django.utils.translation import ugettext_lazy as _
import re
try:
set
except NameError:
from sets import Set as set # For Python 2.3
phone_digits_re = re.compile(r'^(\d{2})[-\.]?(\d{4})[-\.]?(\d{4})$')
class BRZipCodeField(RegexField):

View File

@ -1,11 +1,6 @@
from django.contrib.messages.storage.base import BaseStorage
from django.contrib.messages.storage.cookie import CookieStorage
from django.contrib.messages.storage.session import SessionStorage
try:
set
except NameError:
from sets import Set as set # Python 2.3
class FallbackStorage(BaseStorage):
"""

View File

@ -77,7 +77,7 @@ class CacheClass(BaseCache):
def set(self, key, value, timeout=None):
self._lock.writer_enters()
# Python 2.3 and 2.4 don't allow combined try-except-finally blocks.
# Python 2.4 doesn't allow combined try-except-finally blocks.
try:
try:
self._set(key, pickle.dumps(value), timeout)

View File

@ -13,11 +13,6 @@ from django.core.exceptions import ImproperlyConfigured
from django.core.management.color import color_style
from django.utils.encoding import smart_str
try:
set
except NameError:
from sets import Set as set # For Python 2.3
class CommandError(Exception):
"""
Exception class indicating a problem while executing a management

View File

@ -9,11 +9,6 @@ from django.db import models
from django.db.models import get_models
from django.db.backends.util import truncate_name
try:
set
except NameError:
from sets import Set as set # Python 2.3 fallback
def sql_create(app, style, connection):
"Returns a list of the CREATE TABLE SQL statements for the given app."

View File

@ -3,6 +3,7 @@ Serialize data to/from JSON
"""
import datetime
import decimal
from StringIO import StringIO
from django.core.serializers.python import Serializer as PythonSerializer
@ -10,11 +11,6 @@ from django.core.serializers.python import Deserializer as PythonDeserializer
from django.utils import datetime_safe
from django.utils import simplejson
try:
import decimal
except ImportError:
from django.utils import _decimal as decimal # Python 2.3 fallback
class Serializer(PythonSerializer):
"""
Convert a queryset to JSON.

View File

@ -19,12 +19,6 @@ from django.utils.importlib import import_module
from django.utils.regex_helper import normalize
from django.utils.thread_support import currentThread
try:
reversed
except NameError:
from django.utils.itercompat import reversed # Python 2.3 fallback
from sets import Set as set
_resolver_cache = {} # Maps URLconf modules to RegexURLResolver instances.
_callable_cache = {} # Maps view and url pattern names to their view functions.

View File

@ -1,10 +1,5 @@
import sys
import time
try:
set
except NameError:
# Python 2.3 compat
from sets import Set as set
from django.conf import settings
from django.core.management import call_command

View File

@ -9,10 +9,7 @@ import datetime
import os
import sys
import time
try:
from decimal import Decimal
except ImportError:
from django.utils._decimal import Decimal
from decimal import Decimal
# Oracle takes client-side character set encoding from the environment.
os.environ['NLS_LANG'] = '.UTF8'

View File

@ -1,7 +1,7 @@
"""
SQLite3 backend for django.
Python 2.3 and 2.4 require pysqlite2 (http://pysqlite.org/).
Python 2.4 requires pysqlite2 (http://pysqlite.org/).
Python 2.5 and later can use a pysqlite2 module or the sqlite3 module in the
standard library.

View File

@ -1,13 +1,9 @@
import datetime
import decimal
from time import time
from django.utils.hashcompat import md5_constructor
try:
import decimal
except ImportError:
from django.utils import _decimal as decimal # for Python 2.3
class CursorDebugWrapper(object):
def __init__(self, cursor, db):
self.cursor = cursor

View File

@ -3,6 +3,7 @@ import decimal
import re
import time
import math
from itertools import tee
import django.utils.copycompat as copy
@ -14,7 +15,6 @@ from django import forms
from django.core import exceptions, validators
from django.utils.datastructures import DictWrapper
from django.utils.functional import curry
from django.utils.itercompat import tee
from django.utils.text import capfirst
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_unicode, force_unicode, smart_str

View File

@ -1,9 +1,5 @@
import re
from bisect import bisect
try:
set
except NameError:
from sets import Set as set # Python 2.3 fallback
from django.conf import settings
from django.db.models.related import RelatedObject

View File

@ -19,7 +19,7 @@ except ImportError:
try:
from functools import wraps
except ImportError:
from django.utils.functional import wraps # Python 2.3, 2.4 fallback.
from django.utils.functional import wraps # Python 2.4 fallback.
from django.db import connections, DEFAULT_DB_ALIAS
from django.conf import settings

View File

@ -1,8 +1,4 @@
import weakref
try:
set
except NameError:
from sets import Set as set # Python 2.3 fallback
from django.dispatch import saferef

View File

@ -18,11 +18,6 @@ from widgets import SelectMultiple, HiddenInput, MultipleHiddenInput
from widgets import media_property
from formsets import BaseFormSet, formset_factory, DELETION_FIELD_NAME
try:
set
except NameError:
from sets import Set as set # Python 2.3 fallback
__all__ = (
'ModelForm', 'BaseModelForm', 'model_to_dict', 'fields_for_model',
'save_instance', 'form_for_fields', 'ModelChoiceField',

View File

@ -1,17 +1,12 @@
"""Default variable filters."""
import re
try:
from decimal import Decimal, InvalidOperation, ROUND_HALF_UP
except ImportError:
from django.utils._decimal import Decimal, InvalidOperation, ROUND_HALF_UP
from decimal import Decimal, InvalidOperation, ROUND_HALF_UP
import random as random_module
try:
from functools import wraps
except ImportError:
from django.utils.functional import wraps # Python 2.3, 2.4 fallback.
from django.utils.functional import wraps # Python 2.4 fallback.
from django.template import Variable, Library
from django.conf import settings

View File

@ -2,7 +2,7 @@
import sys
import re
from itertools import cycle as itertools_cycle
from itertools import groupby, cycle as itertools_cycle
from django.template import Node, NodeList, Template, Context, Variable
from django.template import TemplateSyntaxError, VariableDoesNotExist, BLOCK_TAG_START, BLOCK_TAG_END, VARIABLE_TAG_START, VARIABLE_TAG_END, SINGLE_BRACE_START, SINGLE_BRACE_END, COMMENT_TAG_START, COMMENT_TAG_END
@ -10,7 +10,6 @@ from django.template import get_library, Library, InvalidTemplateLibrary
from django.template.smartif import IfParser, Literal
from django.conf import settings
from django.utils.encoding import smart_str, smart_unicode
from django.utils.itercompat import groupby
from django.utils.safestring import mark_safe
register = Library()

View File

@ -185,14 +185,6 @@ def build_test(label):
# Construct a suite out of the tests that matched.
return unittest.TestSuite(tests)
# Python 2.3 compatibility: TestSuites were made iterable in 2.4.
# We need to iterate over them, so we add the missing method when
# necessary.
try:
getattr(unittest.TestSuite, '__iter__')
except AttributeError:
setattr(unittest.TestSuite, '__iter__', lambda s: iter(s._tests))
def partition_suite(suite, classes, bins):
"""
Partitions a test suite by test type.

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@ import types
try:
from functools import wraps, update_wrapper, WRAPPER_ASSIGNMENTS
except ImportError:
from django.utils.functional import wraps, update_wrapper, WRAPPER_ASSIGNMENTS # Python 2.3, 2.4 fallback.
from django.utils.functional import wraps, update_wrapper, WRAPPER_ASSIGNMENTS # Python 2.4 fallback.
def method_decorator(decorator):

View File

@ -3,15 +3,10 @@ import urllib
import locale
import datetime
import codecs
from decimal import Decimal
from django.utils.functional import Promise
try:
from decimal import Decimal
except ImportError:
from django.utils._decimal import Decimal # Python 2.3 fallback
class DjangoUnicodeDecodeError(UnicodeDecodeError):
def __init__(self, obj, *args):
self.obj = obj

View File

@ -60,9 +60,6 @@ def curry(_curried_func, *args, **kwargs):
# Summary of changes made to the Python 2.5 code below:
# * swapped ``partial`` for ``curry`` to maintain backwards-compatibility
# in Django.
# * Wrapped the ``setattr`` call in ``update_wrapper`` with a try-except
# block to make it compatible with Python 2.3, which doesn't allow
# assigning to ``__name__``.
# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007 Python Software Foundation.
# All Rights Reserved.
@ -90,10 +87,7 @@ def update_wrapper(wrapper,
function (defaults to functools.WRAPPER_UPDATES)
"""
for attr in assigned:
try:
setattr(wrapper, attr, getattr(wrapped, attr))
except TypeError: # Python 2.3 doesn't allow assigning to __name__.
pass
setattr(wrapper, attr, getattr(wrapped, attr))
for attr in updated:
getattr(wrapper, attr).update(getattr(wrapped, attr))
# Return the wrapper so this can be used as a decorator via curry()

View File

@ -6,45 +6,7 @@ these implementations if necessary.
import itertools
def compat_tee(iterable):
"""
Return two independent iterators from a single iterable.
Based on http://www.python.org/doc/2.3.5/lib/itertools-example.html
"""
# Note: Using a dictionary and a list as the default arguments here is
# deliberate and safe in this instance.
def gen(next, data={}, cnt=[0]):
dpop = data.pop
for i in itertools.count():
if i == cnt[0]:
item = data[i] = next()
cnt[0] += 1
else:
item = dpop(i)
yield item
next = iter(iterable).next
return gen(next), gen(next)
def groupby(iterable, keyfunc=None):
"""
Taken from http://docs.python.org/lib/itertools-functions.html
"""
if keyfunc is None:
keyfunc = lambda x:x
iterable = iter(iterable)
l = [iterable.next()]
lastkey = keyfunc(l[0])
for item in iterable:
key = keyfunc(item)
if key != lastkey:
yield lastkey, l
lastkey = key
l = [item]
else:
l.append(item)
yield lastkey, l
# Fallback for Python 2.4, Python 2.5
def product(*args, **kwds):
"""
Taken from http://docs.python.org/library/itertools.html#itertools.product
@ -58,18 +20,6 @@ def product(*args, **kwds):
for prod in result:
yield tuple(prod)
# Not really in itertools, since it's a builtin in Python 2.4 and later, but it
# does operate as an iterator.
def reversed(data):
for index in xrange(len(data)-1, -1, -1):
yield data[index]
if hasattr(itertools, 'tee'):
tee = itertools.tee
else:
tee = compat_tee
if hasattr(itertools, 'groupby'):
groupby = itertools.groupby
if hasattr(itertools, 'product'):
product = itertools.product
@ -82,12 +32,6 @@ 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
def all(iterable):
for item in iterable:
if not item:

View File

@ -14,7 +14,7 @@ account on caching -- just like the middleware does.
try:
from functools import wraps
except ImportError:
from django.utils.functional import wraps # Python 2.3, 2.4 fallback.
from django.utils.functional import wraps # Python 2.4 fallback.
from django.utils.decorators import decorator_from_middleware_with_args, available_attrs
from django.utils.cache import patch_cache_control, add_never_cache_headers

View File

@ -4,7 +4,7 @@ from django.utils.decorators import decorator_from_middleware, available_attrs
try:
from functools import wraps
except ImportError:
from django.utils.functional import wraps # Python 2.3, 2.4 fallback.
from django.utils.functional import wraps # Python 2.4 fallback.
csrf_protect = decorator_from_middleware(CsrfViewMiddleware)
csrf_protect.__name__ = "csrf_protect"

View File

@ -5,7 +5,7 @@ Decorators for views based on HTTP headers.
try:
from functools import wraps
except ImportError:
from django.utils.functional import wraps # Python 2.3, 2.4 fallback.
from django.utils.functional import wraps # Python 2.4 fallback.
from calendar import timegm
from datetime import timedelta

View File

@ -1,7 +1,7 @@
try:
from functools import wraps
except ImportError:
from django.utils.functional import wraps # Python 2.3, 2.4 fallback.
from django.utils.functional import wraps # Python 2.4 fallback.
from django.utils.cache import patch_vary_headers
from django.utils.decorators import available_attrs

View File

@ -1,11 +1,6 @@
# coding: utf-8
from django.db import models
try:
sorted
except NameError:
from django.utils.itercompat import sorted # For Python 2.3
class Author(models.Model):
name = models.CharField(max_length=100)
age = models.IntegerField()
@ -48,10 +43,7 @@ class Store(models.Model):
# Different backends and numbers.
__test__ = {'API_TESTS': """
>>> from django.core import management
>>> try:
... from decimal import Decimal
... except:
... from django.utils._decimal import Decimal
>>> from decimal import Decimal
>>> from datetime import date
# Reset the database representation of this app.

View File

@ -4,18 +4,6 @@
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, DEFAULT_DB_ALIAS
class Article(models.Model):

View File

@ -2,11 +2,6 @@ import datetime
from django import forms
from django.db import models
try:
sorted
except NameError:
from django.utils.itercompat import sorted
class Author(models.Model):
name = models.CharField(max_length=100)

View File

@ -8,11 +8,6 @@ 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

View File

@ -6,11 +6,7 @@
``QuerySet`` objects to and from "flat" data (i.e. strings).
"""
try:
from decimal import Decimal
except ImportError:
from django.utils._decimal import Decimal # Python 2.3 fallback
from decimal import Decimal
from django.db import models
class Category(models.Model):

View File

@ -1,9 +1,4 @@
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 File

@ -1,10 +1,5 @@
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 File

@ -1,9 +1,4 @@
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 File

@ -1,9 +1,4 @@
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 File

@ -4,11 +4,6 @@ import pickle
from django.db import connection, models, DEFAULT_DB_ALIAS
from django.conf import settings
try:
sorted
except NameError:
from django.utils.itercompat import sorted # For Python 2.3
class Author(models.Model):
name = models.CharField(max_length=100)
age = models.IntegerField()

View File

@ -3,7 +3,7 @@ from sys import version_info
try:
from functools import wraps
except ImportError:
from django.utils.functional import wraps # Python 2.3, 2.4 fallback.
from django.utils.functional import wraps # Python 2.4 fallback.
from django.http import HttpResponse, HttpRequest
from django.utils.functional import allow_lazy, lazy, memoize

View File

@ -580,12 +580,6 @@ 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()

View File

@ -5,10 +5,7 @@ tests = r"""
>>> import datetime
>>> import time
>>> import re
>>> try:
... from decimal import Decimal
... except ImportError:
... from django.utils._decimal import Decimal
>>> from decimal import Decimal
###############
# Extra stuff #

View File

@ -28,6 +28,7 @@ import datetime
import time
import re
import os
from decimal import Decimal
from unittest import TestCase
@ -35,11 +36,6 @@ from django.core.files.uploadedfile import SimpleUploadedFile
from django.forms import *
from django.forms.widgets import RadioFieldRenderer
try:
from decimal import Decimal
except ImportError:
from django.utils._decimal import Decimal
def fix_os_paths(x):
if isinstance(x, basestring):

View File

@ -5,10 +5,7 @@ tests = r"""
>>> import datetime
>>> import time
>>> import re
>>> try:
... from decimal import Decimal
... except ImportError:
... from django.utils._decimal import Decimal
>>> from decimal import Decimal
#########
# Forms #

View File

@ -7,10 +7,7 @@ tests = r"""
>>> import datetime
>>> import time
>>> import re
>>> try:
... from decimal import Decimal
... except ImportError:
... from django.utils._decimal import Decimal
>>> from decimal import Decimal
>>> from django.utils.translation import activate, deactivate
>>> from django.conf import settings

View File

@ -1,11 +1,6 @@
import os
import tempfile
try:
import decimal
except ImportError:
from django.utils import _decimal as decimal # Python 2.3 fallback
# Try to import PIL in either of the two ways it can end up installed.
# Checking for the existence of Image is enough for CPython, but for PyPy,
# you need to check for the underlying modules.

View File

@ -1,5 +1,6 @@
import datetime
import unittest
from decimal import Decimal
import django.test
from django import forms
@ -8,12 +9,6 @@ from django.core.exceptions import ValidationError
from models import Foo, Bar, Whiz, BigD, BigS, Image, BigInt, Post, NullBooleanModel, BooleanModel
try:
from decimal import Decimal
except ImportError:
from django.utils._decimal import Decimal
# If PIL available, do these tests.
if Image:
from imagefield import \

View File

@ -6,12 +6,6 @@ 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)

View File

@ -12,12 +12,6 @@ from django.db import models, DEFAULT_DB_ALIAS
from django.db.models import Count
from django.db.models.query import Q, ITER_CHUNK_SIZE, EmptyQuerySet
# Python 2.3 doesn't have sorted()
try:
sorted
except NameError:
from django.utils.itercompat import sorted
class DumbCategory(models.Model):
pass
@ -1279,12 +1273,12 @@ True
"""}
# In Python 2.3 and the Python 2.6 beta releases, exceptions raised in __len__
# In Python 2.6 beta releases, exceptions raised in __len__
# are swallowed (Python issue 1242657), so these cases return an empty list,
# rather than raising an exception. Not a lot we can do about that,
# unfortunately, due to the way Python handles list() calls internally. Thus,
# we skip the tests for Python 2.3 and 2.6.
if (2, 4) <= sys.version_info < (2, 6):
# we skip the tests for Python 2.6.
if sys.version_info < (2, 6):
__test__["API_TESTS"] += """
# If you're not careful, it's possible to introduce infinite loops via default
# ordering on foreign keys in a cycle. We detect that.

View File

@ -1,15 +0,0 @@
"""
# 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

@ -10,25 +10,16 @@ from django.utils.functional import SimpleLazyObject
import timesince
import datastructures
import datetime_safe
import itercompat
import tzinfo
from decorators import DecoratorFromMiddlewareTests
from functional import FunctionalTestCase
# We need this because "datastructures" uses sorted() and the tests are run in
# the scope of this module.
try:
sorted
except NameError:
from django.utils.itercompat import sorted # For Python 2.3
# Extra tests
__test__ = {
'timesince': timesince,
'datastructures': datastructures,
'datetime_safe': datetime_safe,
'itercompat': itercompat,
'tzinfo': tzinfo,
}

View File

@ -5,12 +5,6 @@ import unittest
import django.contrib as contrib
try:
set
except NameError:
from sets import Set as set # For Python 2.3
CONTRIB_DIR_NAME = 'django.contrib'
MODEL_TESTS_DIR_NAME = 'modeltests'
REGRESSION_TESTS_DIR_NAME = 'regressiontests'