Commits

Anonymous committed 5b0907b

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

  • Participants
  • Parent commits 76e6f5f

Comments (0)

Files changed (6)

     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>

File django/core/management/validation.py

 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):
             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:

File django/http/__init__.py

     content = property(_get_content, _set_content)
 
     def __iter__(self):
-        self._iterator = self._container.__iter__()
+        self._iterator = iter(self._container)
         return self
 
     def next(self):

File django/template/__init__.py

 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
 
                     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)

File django/test/client.py

 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
                 '',
                 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 + '--',

File django/utils/itercompat.py

     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
+