mirror of https://github.com/django/django.git
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:
parent
1ea702dd23
commit
ad077ccbc0
1
AUTHORS
1
AUTHORS
|
@ -263,6 +263,7 @@ answer newbie questions, and generally made Django that much better:
|
||||||
SmileyChris <smileychris@gmail.com>
|
SmileyChris <smileychris@gmail.com>
|
||||||
smurf@smurf.noris.de
|
smurf@smurf.noris.de
|
||||||
sopel
|
sopel
|
||||||
|
Leo Soto <leo.soto@gmail.com>
|
||||||
Wiliam Alves de Souza <wiliamsouza83@gmail.com>
|
Wiliam Alves de Souza <wiliamsouza83@gmail.com>
|
||||||
Georgi Stanojevski <glisha@gmail.com>
|
Georgi Stanojevski <glisha@gmail.com>
|
||||||
Vasiliy Stavenko <stavenko@gmail.com>
|
Vasiliy Stavenko <stavenko@gmail.com>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import sys
|
import sys
|
||||||
from django.core.management.color import color_style
|
from django.core.management.color import color_style
|
||||||
|
from django.utils.itercompat import is_iterable
|
||||||
|
|
||||||
class ModelErrorCollection:
|
class ModelErrorCollection:
|
||||||
def __init__(self, outfile=sys.stdout):
|
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):
|
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)
|
e.add(opts, '"%s": prepopulate_from should be a list or tuple.' % f.name)
|
||||||
if f.choices:
|
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)
|
e.add(opts, '"%s": "choices" should be iterable (e.g., a tuple or list).' % f.name)
|
||||||
else:
|
else:
|
||||||
for c in f.choices:
|
for c in f.choices:
|
||||||
|
|
|
@ -304,7 +304,7 @@ class HttpResponse(object):
|
||||||
content = property(_get_content, _set_content)
|
content = property(_get_content, _set_content)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
self._iterator = self._container.__iter__()
|
self._iterator = iter(self._container)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def next(self):
|
def next(self):
|
||||||
|
|
|
@ -58,6 +58,7 @@ import re
|
||||||
from inspect import getargspec
|
from inspect import getargspec
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.template.context import Context, RequestContext, ContextPopException
|
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.functional import curry, Promise
|
||||||
from django.utils.text import smart_split
|
from django.utils.text import smart_split
|
||||||
from django.utils.encoding import smart_unicode, force_unicode
|
from django.utils.encoding import smart_unicode, force_unicode
|
||||||
|
@ -900,7 +901,7 @@ class Library(object):
|
||||||
|
|
||||||
if not getattr(self, 'nodelist', False):
|
if not getattr(self, 'nodelist', False):
|
||||||
from django.template.loader import get_template, select_template
|
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)
|
t = select_template(file_name)
|
||||||
else:
|
else:
|
||||||
t = get_template(file_name)
|
t = get_template(file_name)
|
||||||
|
|
|
@ -16,6 +16,7 @@ from django.test import signals
|
||||||
from django.utils.functional import curry
|
from django.utils.functional import curry
|
||||||
from django.utils.encoding import smart_str
|
from django.utils.encoding import smart_str
|
||||||
from django.utils.http import urlencode
|
from django.utils.http import urlencode
|
||||||
|
from django.utils.itercompat import is_iterable
|
||||||
|
|
||||||
BOUNDARY = 'BoUnDaRyStRiNg'
|
BOUNDARY = 'BoUnDaRyStRiNg'
|
||||||
MULTIPART_CONTENT = 'multipart/form-data; boundary=%s' % BOUNDARY
|
MULTIPART_CONTENT = 'multipart/form-data; boundary=%s' % BOUNDARY
|
||||||
|
@ -74,21 +75,22 @@ def encode_multipart(boundary, data):
|
||||||
'',
|
'',
|
||||||
value.read()
|
value.read()
|
||||||
])
|
])
|
||||||
elif hasattr(value, '__iter__'):
|
else:
|
||||||
for item in value:
|
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([
|
lines.extend([
|
||||||
'--' + boundary,
|
'--' + boundary,
|
||||||
'Content-Disposition: form-data; name="%s"' % to_str(key),
|
'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([
|
lines.extend([
|
||||||
'--' + boundary + '--',
|
'--' + boundary + '--',
|
||||||
|
|
|
@ -57,3 +57,13 @@ else:
|
||||||
tee = compat_tee
|
tee = compat_tee
|
||||||
if hasattr(itertools, 'groupby'):
|
if hasattr(itertools, 'groupby'):
|
||||||
groupby = 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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue