@@ -214,7 +214,9 @@ def call(self, service, method, *args, **kwargs):
214214
215215 """
216216 if kwargs .pop ('iter' , False ):
217- return self .iter_call (service , method , * args , ** kwargs )
217+ # Most of the codebase assumes a non-generator will be returned, so casting to list
218+ # keeps those sections working
219+ return list (self .iter_call (service , method , * args , ** kwargs ))
218220
219221 invalid_kwargs = set (kwargs .keys ()) - VALID_CALL_ARGS
220222 if invalid_kwargs :
@@ -267,55 +269,51 @@ def iter_call(self, service, method, *args, **kwargs):
267269
268270 :param service: the name of the SoftLayer API service
269271 :param method: the method to call on the service
270- :param integer chunk : result size for each API call (defaults to 100)
272+ :param integer limit : result size for each API call (defaults to 100)
271273 :param \\ *args: same optional arguments that ``Service.call`` takes
272- :param \\ *\\ *kwargs: same optional keyword arguments that
273- ``Service.call`` takes
274+ :param \\ *\\ *kwargs: same optional keyword arguments that ``Service.call`` takes
274275
275276 """
276- chunk = kwargs .pop ('chunk' , 100 )
277- limit = kwargs .pop ('limit' , None )
278- offset = kwargs .pop ('offset' , 0 )
279277
280- if chunk <= 0 :
281- raise AttributeError ( "Chunk size should be greater than zero." )
278+ limit = kwargs . pop ( 'limit' , 100 )
279+ offset = kwargs . pop ( 'offset' , 0 )
282280
283- if limit :
284- chunk = min ( chunk , limit )
281+ if limit <= 0 :
282+ raise AttributeError ( "Limit size should be greater than zero." )
285283
286- result_count = 0
284+ # Set to make unit tests, which call this function directly, play nice.
287285 kwargs ['iter' ] = False
288- while True :
289- if limit :
290- # We've reached the end of the results
291- if result_count >= limit :
292- break
293-
294- # Don't over-fetch past the given limit
295- if chunk + result_count > limit :
296- chunk = limit - result_count
297-
298- results = self .call (service , method ,
299- offset = offset , limit = chunk , * args , ** kwargs )
286+ result_count = 0
287+ keep_looping = True
300288
301- # It looks like we ran out results
302- if not results :
303- break
289+ while keep_looping :
290+ # Get the next results
291+ results = self . call ( service , method , offset = offset , limit = limit , * args , ** kwargs )
304292
305293 # Apparently this method doesn't return a list.
306294 # Why are you even iterating over this?
307- if not isinstance (results , list ):
308- yield results
309- break
295+ if not isinstance (results , transports .SoftLayerListResult ):
296+ if isinstance (results , list ):
297+ # Close enough, this makes testing a lot easier
298+ results = transports .SoftLayerListResult (results , len (results ))
299+ else :
300+ yield results
301+ raise StopIteration
310302
311303 for item in results :
312304 yield item
313305 result_count += 1
314306
315- offset += chunk
307+ # Got less results than requested, we are at the end
308+ if len (results ) < limit :
309+ keep_looping = False
310+ # Got all the needed items
311+ if result_count >= results .total_count :
312+ keep_looping = False
313+
314+ offset += limit
316315
317- if len (results ) < chunk :
318- break
316+ raise StopIteration
319317
320318 def __repr__ (self ):
321319 return "Client(transport=%r, auth=%r)" % (self .transport , self .auth )
0 commit comments