diff --git a/django/core/cache/__init__.py b/django/core/cache/__init__.py index 41cbc76bc8..7c3f0927eb 100644 --- a/django/core/cache/__init__.py +++ b/django/core/cache/__init__.py @@ -16,9 +16,16 @@ See docs/cache.txt for information on the public API. """ try: - from urlparse import parse_qsl + # The mod_python version is more efficient, so try importing it first. + from mod_python.util import parse_qsl except ImportError: - from cgi import parse_qsl + try: + # Python 2.6 and greater + from urlparse import parse_qsl + except ImportError: + # Python 2.5, 2.4. Works on Python 2.6 but raises + # PendingDeprecationWarning + from cgi import parse_qsl from django.conf import settings from django.core import signals diff --git a/django/http/__init__.py b/django/http/__init__.py index 46232bee18..406c217b28 100644 --- a/django/http/__init__.py +++ b/django/http/__init__.py @@ -10,7 +10,13 @@ try: # The mod_python version is more efficient, so try importing it first. from mod_python.util import parse_qsl except ImportError: - from cgi import parse_qsl + try: + # Python 2.6 and greater + from urlparse import parse_qsl + except ImportError: + # Python 2.5, 2.4. Works on Python 2.6 but raises + # PendingDeprecationWarning + from cgi import parse_qsl from django.utils.datastructures import MultiValueDict, ImmutableList from django.utils.encoding import smart_str, iri_to_uri, force_unicode