Ticket #5445: iterables3.2.patch
File iterables3.2.patch, 4.5 KB (added by , 17 years ago) |
---|
-
django/http/__init__.py
304 289 content = property(_get_content, _set_content) 305 290 306 291 def __iter__(self): 307 self._iterator = self._container.__iter__()292 self._iterator = iter(self._container) 308 293 return self 309 294 310 295 def next(self): -
django/test/client.py
16 16 from django.utils.functional import curry 17 17 from django.utils.encoding import smart_str 18 18 from django.utils.http import urlencode 19 from django.utils.itercompat import is_iterable 19 20 20 21 BOUNDARY = 'BoUnDaRyStRiNg' 21 22 MULTIPART_CONTENT = 'multipart/form-data; boundary=%s' % BOUNDARY … … 74 75 '', 75 76 value.read() 76 77 ]) 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: 79 88 lines.extend([ 80 89 '--' + boundary, 81 90 'Content-Disposition: form-data; name="%s"' % to_str(key), 82 91 '', 83 to_str( item)92 to_str(value) 84 93 ]) 85 else:86 lines.extend([87 '--' + boundary,88 'Content-Disposition: form-data; name="%s"' % to_str(key),89 '',90 to_str(value)91 ])92 94 93 95 lines.extend([ 94 96 '--' + boundary + '--', -
django/core/management/validation.py
1 1 import sys 2 2 from django.core.management.color import color_style 3 from django.utils.itercompat import is_iterable 3 4 4 5 class ModelErrorCollection: 5 6 def __init__(self, outfile=sys.stdout): … … 51 52 if f.prepopulate_from is not None and type(f.prepopulate_from) not in (list, tuple): 52 53 e.add(opts, '"%s": prepopulate_from should be a list or tuple.' % f.name) 53 54 if f.choices: 54 if not hasattr(f.choices, '__iter__'): 55 if isinstance(f.choices, basestring) or \ 56 not is_iterable(f.choices): 55 57 e.add(opts, '"%s": "choices" should be iterable (e.g., a tuple or list).' % f.name) 56 58 else: 57 59 for c in f.choices: -
django/utils/itercompat.py
57 57 tee = compat_tee 58 58 if hasattr(itertools, 'groupby'): 59 59 groupby = itertools.groupby 60 61 def 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 -
django/template/__init__.py
58 58 from inspect import getargspec 59 59 from django.conf import settings 60 60 from django.template.context import Context, RequestContext, ContextPopException 61 from django.utils.itercompat import is_iterable 61 62 from django.utils.functional import curry, Promise 62 63 from django.utils.text import smart_split 63 64 from django.utils.encoding import smart_unicode, force_unicode … … 900 901 901 902 if not getattr(self, 'nodelist', False): 902 903 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): 904 905 t = select_template(file_name) 905 906 else: 906 907 t = get_template(file_name)