Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #5445: added some compatibility code for the lack of __iter__ i…

…n Jython 2.2. Thanks, Leo Soto.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6211 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ad077ccbc03f11c3db3951aab110ec98c5907729 1 parent 1ea702d
@jacobian jacobian authored
View
1  AUTHORS
@@ -263,6 +263,7 @@ answer newbie questions, and generally made Django that much better:
SmileyChris <smileychris@gmail.com>
smurf@smurf.noris.de
sopel
+ Leo Soto <leo.soto@gmail.com>
Wiliam Alves de Souza <wiliamsouza83@gmail.com>
Georgi Stanojevski <glisha@gmail.com>
Vasiliy Stavenko <stavenko@gmail.com>
View
4 django/core/management/validation.py
@@ -1,5 +1,6 @@
import sys
from django.core.management.color import color_style
+from django.utils.itercompat import is_iterable
class ModelErrorCollection:
def __init__(self, outfile=sys.stdout):
@@ -51,7 +52,8 @@ def get_validation_errors(outfile, app=None):
if f.prepopulate_from is not None and type(f.prepopulate_from) not in (list, tuple):
e.add(opts, '"%s": prepopulate_from should be a list or tuple.' % f.name)
if f.choices:
- if not hasattr(f.choices, '__iter__'):
+ if isinstance(f.choices, basestring) or \
+ not is_iterable(f.choices):
e.add(opts, '"%s": "choices" should be iterable (e.g., a tuple or list).' % f.name)
else:
for c in f.choices:
View
2  django/http/__init__.py
@@ -304,7 +304,7 @@ def _set_content(self, value):
content = property(_get_content, _set_content)
def __iter__(self):
- self._iterator = self._container.__iter__()
+ self._iterator = iter(self._container)
return self
def next(self):
View
3  django/template/__init__.py
@@ -58,6 +58,7 @@
from inspect import getargspec
from django.conf import settings
from django.template.context import Context, RequestContext, ContextPopException
+from django.utils.itercompat import is_iterable
from django.utils.functional import curry, Promise
from django.utils.text import smart_split
from django.utils.encoding import smart_unicode, force_unicode
@@ -900,7 +901,7 @@ def render(self, context):
if not getattr(self, 'nodelist', False):
from django.template.loader import get_template, select_template
- if hasattr(file_name, '__iter__'):
+ if not isinstance(file_name, basestring) and is_iterable(file_name):
t = select_template(file_name)
else:
t = get_template(file_name)
View
22 django/test/client.py
@@ -16,6 +16,7 @@
from django.utils.functional import curry
from django.utils.encoding import smart_str
from django.utils.http import urlencode
+from django.utils.itercompat import is_iterable
BOUNDARY = 'BoUnDaRyStRiNg'
MULTIPART_CONTENT = 'multipart/form-data; boundary=%s' % BOUNDARY
@@ -74,21 +75,22 @@ def encode_multipart(boundary, data):
'',
value.read()
])
- elif hasattr(value, '__iter__'):
- for item in value:
+ else:
+ if not isinstance(value, basestring) and is_iterable(value):
+ for item in value:
+ lines.extend([
+ '--' + boundary,
+ 'Content-Disposition: form-data; name="%s"' % to_str(key),
+ '',
+ to_str(item)
+ ])
+ else:
lines.extend([
'--' + boundary,
'Content-Disposition: form-data; name="%s"' % to_str(key),
'',
- to_str(item)
+ to_str(value)
])
- else:
- lines.extend([
- '--' + boundary,
- 'Content-Disposition: form-data; name="%s"' % to_str(key),
- '',
- to_str(value)
- ])
lines.extend([
'--' + boundary + '--',
View
10 django/utils/itercompat.py
@@ -57,3 +57,13 @@ def reversed(data):
tee = compat_tee
if hasattr(itertools, 'groupby'):
groupby = itertools.groupby
+
+def is_iterable(x):
+ "A implementation independent way of checking for iterables"
+ try:
+ iter(x)
+ except TypeError:
+ return False
+ else:
+ return True
+
Please sign in to comment.
Something went wrong with that request. Please try again.