0
0
mirror of https://github.com/django/django.git synced 2024-12-01 15:42:04 +01:00

Fixed #4607 -- Tweaked checks for features missing in Python 2.3 to not assume

things Python does not guarantee. Patch from SmileyChris.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@5514 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-06-23 03:18:22 +00:00
parent 284c6ba44b
commit 08aa5c585b
8 changed files with 34 additions and 20 deletions

View File

@ -14,6 +14,11 @@ from django.utils.html import escape
from django.utils.text import capfirst, get_text_list
import operator
try:
set
except NameError:
from sets import Set as set # Python 2.3 fallback
from django.contrib.admin.models import LogEntry, ADDITION, CHANGE, DELETION
if not LogEntry._meta.installed:
raise ImproperlyConfigured, "You'll need to put 'django.contrib.admin' in your INSTALLED_APPS setting before you can use the admin application."
@ -489,7 +494,6 @@ def _get_deleted_objects(deleted_objects, perms_needed, user, obj, opts, current
perms_needed.add(related.opts.verbose_name)
def delete_stage(request, app_label, model_name, object_id):
import sets
model = models.get_model(app_label, model_name)
object_id = unquote(object_id)
if model is None:
@ -502,7 +506,7 @@ def delete_stage(request, app_label, model_name, object_id):
# Populate deleted_objects, a data structure of all related objects that
# will also be deleted.
deleted_objects = ['%s: <a href="../../%s/">%s</a>' % (capfirst(opts.verbose_name), object_id, escape(str(obj))), []]
perms_needed = sets.Set()
perms_needed = set()
_get_deleted_objects(deleted_objects, perms_needed, request.user, obj, opts, 1)
if request.POST: # The user has already confirmed the deletion.

View File

@ -5,6 +5,11 @@ from django.contrib.contenttypes.models import ContentType
from django.utils.translation import gettext_lazy as _
import datetime
try:
set
except NameError:
from sets import Set as set # Python 2.3 fallback
def check_password(raw_password, enc_password):
"""
Returns a boolean of whether the raw_password was correct. Handles
@ -175,7 +180,6 @@ class User(models.Model):
def get_group_permissions(self):
"Returns a list of permission strings that this user has through his/her groups."
if not hasattr(self, '_group_perm_cache'):
import sets
cursor = connection.cursor()
# The SQL below works out to the following, after DB quoting:
# cursor.execute("""
@ -200,13 +204,13 @@ class User(models.Model):
backend.quote_name('id'), backend.quote_name('content_type_id'),
backend.quote_name('user_id'),)
cursor.execute(sql, [self.id])
self._group_perm_cache = sets.Set(["%s.%s" % (row[0], row[1]) for row in cursor.fetchall()])
self._group_perm_cache = set(["%s.%s" % (row[0], row[1]) for row in cursor.fetchall()])
return self._group_perm_cache
def get_all_permissions(self):
if not hasattr(self, '_perm_cache'):
import sets
self._perm_cache = sets.Set(["%s.%s" % (p.content_type.app_label, p.codename) for p in self.user_permissions.select_related()])
self._perm_cache = set(["%s.%s" % (p.content_type.app_label, p.codename) for p in self.user_permissions.select_related()])
self._perm_cache.update(self.get_group_permissions())
return self._perm_cache

View File

@ -7,9 +7,10 @@ from optparse import OptionParser
from django.utils import termcolors
import os, re, shutil, sys, textwrap
# For Python 2.3
if not hasattr(__builtins__, 'set'):
from sets import Set as set
try:
set
except NameError:
from sets import Set as set # Python 2.3 fallback
# For backwards compatibility: get_version() used to be in this module.
get_version = django.get_version

View File

@ -10,9 +10,10 @@ from django import oldforms
from django import newforms as forms
from django.dispatch import dispatcher
# For Python 2.3
if not hasattr(__builtins__, 'set'):
from sets import Set as set
try:
set
except NameError:
from sets import Set as set # Python 2.3 fallback
# Values for Relation.edit_inline.
TABULAR, STACKED = 1, 2

View File

@ -7,9 +7,10 @@ from django.contrib.contenttypes import generic
import operator
import re
# For Python 2.3
if not hasattr(__builtins__, 'set'):
from sets import Set as set
try:
set
except NameError:
from sets import Set as set # Python 2.3 fallback
# The string constant used to separate query parts
LOOKUP_SEPARATOR = '__'

View File

@ -27,9 +27,9 @@ __all__ = (
EMPTY_VALUES = (None, '')
try:
set # Only available in Python 2.4+
set
except NameError:
from sets import Set as set # Python 2.3 fallback
from sets import Set as set # Python 2.3 fallback
try:
from decimal import Decimal

View File

@ -3,9 +3,10 @@ HTML Widget classes
"""
try:
set # Only available in Python 2.4+
set
except NameError:
from sets import Set as set # Python 2.3 fallback
from sets import Set as set # Python 2.3 fallback
from itertools import chain
from django.utils.datastructures import MultiValueDict

View File

@ -8,8 +8,10 @@ from django.utils.itercompat import groupby
import sys
import re
if not hasattr(__builtins__, 'reversed'):
# For Python 2.3.
try:
reversed
except NameError:
# Python 2.3 fallback.
# From http://www.python.org/doc/current/tut/node11.html
def reversed(data):
for index in xrange(len(data)-1, -1, -1):