Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #4607 -- Tweaked checks for features missing in Python 2.3 to n…

…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...
commit 08aa5c585b511cfaf97ced38f2b5f7fb96492203 1 parent 284c6ba
@malcolmt malcolmt authored
View
8 django/contrib/admin/views/main.py
@@ -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."
@@ -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
10 django/contrib/auth/models.py
@@ -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
@@ -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("""
@@ -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
View
7 django/core/management.py
@@ -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
View
7 django/db/models/fields/related.py
@@ -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
View
7 django/db/models/query.py
@@ -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 = '__'
View
4 django/newforms/fields.py
@@ -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
View
5 django/newforms/widgets.py
@@ -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
View
6 django/template/defaulttags.py
@@ -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):
Please sign in to comment.
Something went wrong with that request. Please try again.