Django

Code

Changeset 6211

Show
Ignore:
Timestamp:
09/14/07 14:55:24 (8 months ago)
Author:
jacob
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/AUTHORS

    r6202 r6211  
    264264    smurf@smurf.noris.de 
    265265    sopel 
     266    Leo Soto <leo.soto@gmail.com> 
    266267    Wiliam Alves de Souza <wiliamsouza83@gmail.com> 
    267268    Georgi Stanojevski <glisha@gmail.com> 
  • django/trunk/django/core/management/validation.py

    r5898 r6211  
    11import sys 
    22from django.core.management.color import color_style 
     3from django.utils.itercompat import is_iterable 
    34 
    45class ModelErrorCollection: 
     
    5253                e.add(opts, '"%s": prepopulate_from should be a list or tuple.' % f.name) 
    5354            if f.choices: 
    54                 if not hasattr(f.choices, '__iter__'): 
     55                if isinstance(f.choices, basestring) or \ 
     56                       not is_iterable(f.choices): 
    5557                    e.add(opts, '"%s": "choices" should be iterable (e.g., a tuple or list).' % f.name) 
    5658                else: 
  • django/trunk/django/http/__init__.py

    r6167 r6211  
    305305 
    306306    def __iter__(self): 
    307         self._iterator = self._container.__iter__(
     307        self._iterator = iter(self._container
    308308        return self 
    309309 
  • django/trunk/django/template/__init__.py

    r5630 r6211  
    5959from django.conf import settings 
    6060from django.template.context import Context, RequestContext, ContextPopException 
     61from django.utils.itercompat import is_iterable 
    6162from django.utils.functional import curry, Promise 
    6263from django.utils.text import smart_split 
     
    901902                    if not getattr(self, 'nodelist', False): 
    902903                        from django.template.loader import get_template, select_template 
    903                         if hasattr(file_name, '__iter__'): 
     904                        if not isinstance(file_name, basestring) and is_iterable(file_name): 
    904905                            t = select_template(file_name) 
    905906                        else: 
  • django/trunk/django/test/client.py

    r6039 r6211  
    1717from django.utils.encoding import smart_str 
    1818from django.utils.http import urlencode 
     19from django.utils.itercompat import is_iterable 
    1920 
    2021BOUNDARY = 'BoUnDaRyStRiNg' 
     
    7576                value.read() 
    7677            ]) 
    77         elif hasattr(value, '__iter__'): 
    78             for item in value: 
     78        else: 
     79            if not isinstance(value, basestring) and is_iterable(value): 
     80                for item in value: 
     81                    lines.extend([ 
     82                        '--' + boundary, 
     83                        'Content-Disposition: form-data; name="%s"' % to_str(key), 
     84                        '', 
     85                        to_str(item) 
     86                    ]) 
     87            else: 
    7988                lines.extend([ 
    8089                    '--' + boundary, 
    8190                    'Content-Disposition: form-data; name="%s"' % to_str(key), 
    8291                    '', 
    83                     to_str(item
     92                    to_str(value
    8493                ]) 
    85         else: 
    86             lines.extend([ 
    87                 '--' + boundary, 
    88                 'Content-Disposition: form-data; name="%s"' % to_str(key), 
    89                 '', 
    90                 to_str(value) 
    91             ]) 
    9294 
    9395    lines.extend([ 
  • django/trunk/django/utils/itercompat.py

    r5526 r6211  
    5858if hasattr(itertools, 'groupby'): 
    5959    groupby = itertools.groupby 
     60 
     61def is_iterable(x): 
     62    "A implementation independent way of checking for iterables" 
     63    try: 
     64        iter(x) 
     65    except TypeError: 
     66        return False 
     67    else: 
     68        return True 
     69