Commit 23d34597 authored by Claude Paroz's avatar Claude Paroz
Browse files

Fixed #17965 -- Definitely dropped support for Python 2.5. Thanks jonash for...

Fixed #17965 -- Definitely dropped support for Python 2.5. Thanks jonash for the initial patch and Aymeric Augustin for the review.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@17834 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 27322df9
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -407,10 +407,7 @@ class SessionMiddlewareTests(unittest.TestCase):

        # Handle the response through the middleware
        response = middleware.process_response(request, response)
        # If it isn't in the cookie, that's fine (Python 2.5)
        if 'httponly' in settings.SESSION_COOKIE_NAME:
            self.assertFalse(
               response.cookies[settings.SESSION_COOKIE_NAME]['httponly'])
        self.assertFalse(response.cookies[settings.SESSION_COOKIE_NAME]['httponly'])

        self.assertNotIn('httponly',
                         str(response.cookies[settings.SESSION_COOKIE_NAME]))
+1 −6
Original line number Diff line number Diff line
@@ -25,12 +25,7 @@ try:
    # The mod_python version is more efficient, so try importing it first.
    from mod_python.util import parse_qsl
except ImportError:
    try:
        # Python 2.6 and greater
    from urlparse import parse_qsl
    except ImportError:
        # Python 2.5.  Works on Python 2.6 but raises PendingDeprecationWarning
        from cgi import parse_qsl

__all__ = [
    'get_cache', 'cache', 'DEFAULT_CACHE_ALIAS'
+1 −1
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ from django.core.management.color import no_style
from django.db import (connections, router, transaction, DEFAULT_DB_ALIAS,
      IntegrityError, DatabaseError)
from django.db.models import get_apps
from django.utils.itercompat import product
from itertools import product

try:
    import bz2
+4 −30
Original line number Diff line number Diff line
@@ -18,17 +18,9 @@ try:
    # The mod_python version is more efficient, so try importing it first.
    from mod_python.util import parse_qsl
except ImportError:
    try:
        # Python 2.6 and greater
    from urlparse import parse_qsl
    except ImportError:
        # Python 2.5. Works on Python 2.6 but raises PendingDeprecationWarning
        from cgi import parse_qsl

import Cookie
# httponly support exists in Python 2.6's Cookie library,
# but not in Python 2.5.
_morsel_supports_httponly = 'httponly' in Cookie.Morsel._reserved
# Some versions of Python 2.7 and later won't need this encoding bug fix:
_cookie_encodes_correctly = Cookie.SimpleCookie().value_encode(';') == (';', '"\\073"')
# See ticket #13007, http://bugs.python.org/issue2193 and http://trac.edgewall.org/ticket/2256
@@ -39,26 +31,8 @@ try:
except Cookie.CookieError:
    _cookie_allows_colon_in_names = False

if _morsel_supports_httponly and _cookie_encodes_correctly and _cookie_allows_colon_in_names:
if _cookie_encodes_correctly and _cookie_allows_colon_in_names:
    SimpleCookie = Cookie.SimpleCookie
else:
    if not _morsel_supports_httponly:
        class Morsel(Cookie.Morsel):
            def __setitem__(self, K, V):
                K = K.lower()
                if K == "httponly":
                    if V:
                        # The superclass rejects httponly as a key,
                        # so we jump to the grandparent.
                        super(Cookie.Morsel, self).__setitem__(K, V)
                else:
                    super(Morsel, self).__setitem__(K, V)

            def OutputString(self, attrs=None):
                output = super(Morsel, self).OutputString(attrs)
                if "httponly" in self:
                    output += "; httponly"
                return output
else:
    Morsel = Cookie.Morsel

@@ -88,7 +62,7 @@ else:

                return val, encoded

        if not _cookie_allows_colon_in_names or not _morsel_supports_httponly:
        if not _cookie_allows_colon_in_names:
            def load(self, rawdata):
                self.bad_cookies = set()
                super(SimpleCookie, self).load(rawdata)
+7 −17
Original line number Diff line number Diff line
@@ -8,23 +8,6 @@ import __builtin__
import itertools
import warnings

# Fallback for Python 2.5
def product(*args, **kwds):
    """
    Taken from http://docs.python.org/library/itertools.html#itertools.product
    """
    # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
    # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
    pools = map(tuple, args) * kwds.get('repeat', 1)
    result = [[]]
    for pool in pools:
        result = [x+[y] for x in result for y in pool]
    for prod in result:
        yield tuple(prod)

if hasattr(itertools, 'product'):
    product = itertools.product

def is_iterable(x):
    "A implementation independent way of checking for iterables"
    try:
@@ -34,6 +17,13 @@ def is_iterable(x):
    else:
        return True

def product(*args, **kwds):
    # PendingDeprecationWarning in 1.5, remove this comment when the Deprecations
    # will have been advanced for 1.5
    warnings.warn("django.utils.itercompat.product is deprecated; use the native version instead",
                  PendingDeprecationWarning)
    return itertools.product(*args, **kwds)

def all(iterable):
    warnings.warn("django.utils.itercompat.all is deprecated; use the native version instead",
                  PendingDeprecationWarning)
Loading