Skip to content

Commit

Permalink
Fixed #4607 -- Tweaked checks for features missing in Python 2.3 to n…
Browse files Browse the repository at this point in the history
…ot 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
  • Loading branch information
malcolmt committed Jun 23, 2007
1 parent 284c6ba commit 08aa5c5
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 20 deletions.
8 changes: 6 additions & 2 deletions django/contrib/admin/views/main.py
Expand Up @@ -14,6 +14,11 @@
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."
Expand Down Expand Up @@ -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:
Expand All @@ -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.
Expand Down
10 changes: 7 additions & 3 deletions django/contrib/auth/models.py
Expand Up @@ -5,6 +5,11 @@
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
Expand Down Expand Up @@ -175,7 +180,6 @@ def check_password(self, raw_password):
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("""
Expand All @@ -200,13 +204,13 @@ def get_group_permissions(self):
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

Expand Down
7 changes: 4 additions & 3 deletions django/core/management.py
Expand Up @@ -7,9 +7,10 @@
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
Expand Down
7 changes: 4 additions & 3 deletions django/db/models/fields/related.py
Expand Up @@ -10,9 +10,10 @@
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
Expand Down
7 changes: 4 additions & 3 deletions django/db/models/query.py
Expand Up @@ -7,9 +7,10 @@
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 = '__'
Expand Down
4 changes: 2 additions & 2 deletions django/newforms/fields.py
Expand Up @@ -27,9 +27,9 @@
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
Expand Down
5 changes: 3 additions & 2 deletions django/newforms/widgets.py
Expand Up @@ -3,9 +3,10 @@
"""

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
Expand Down
6 changes: 4 additions & 2 deletions django/template/defaulttags.py
Expand Up @@ -8,8 +8,10 @@
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):
Expand Down

0 comments on commit 08aa5c5

Please sign in to comment.