Fixed #5445: added some compatibility code for the lack of __iter__ in Jython 2.2. Thanks, Leo Soto.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6211 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jacob Kaplan-Moss 2007-09-14 19:55:24 +00:00
parent 1ea702dd23
commit ad077ccbc0
6 changed files with 29 additions and 13 deletions

View File

@ -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 File

@ -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 File

@ -304,7 +304,7 @@ class HttpResponse(object):
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 File

@ -58,6 +58,7 @@ import re
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 @@ class Library(object):
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 File

@ -16,6 +16,7 @@ from django.test import signals
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 File

@ -57,3 +57,13 @@ else:
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