comparison mercurial/templater.py @ 14944:e2c413bde8a5

globally: use safehasattr(x, '__iter__') instead of hasattr(x, '__iter__')
author Augie Fackler <durin42@gmail.com>
date Mon, 25 Jul 2011 15:30:19 -0500
parents d3bb825ddae3
children 67964cda8701
comparison
equal deleted inserted replaced
14943:d3bb825ddae3 14944:e2c413bde8a5
201 201
202 def _flatten(thing): 202 def _flatten(thing):
203 '''yield a single stream from a possibly nested set of iterators''' 203 '''yield a single stream from a possibly nested set of iterators'''
204 if isinstance(thing, str): 204 if isinstance(thing, str):
205 yield thing 205 yield thing
206 elif not hasattr(thing, '__iter__'): 206 elif not util.safehasattr(thing, '__iter__'):
207 if thing is not None: 207 if thing is not None:
208 yield str(thing) 208 yield str(thing)
209 else: 209 else:
210 for i in thing: 210 for i in thing:
211 if isinstance(i, str): 211 if isinstance(i, str):
212 yield i 212 yield i
213 elif not hasattr(i, '__iter__'): 213 elif not util.safehasattr(i, '__iter__'):
214 if i is not None: 214 if i is not None:
215 yield str(i) 215 yield str(i)
216 elif i is not None: 216 elif i is not None:
217 for j in _flatten(i): 217 for j in _flatten(i):
218 yield j 218 yield j