@@ -712,7 +712,7 @@ def http_get(self, path, query_data={}, streamed=False, **kwargs):
712712 else :
713713 return result
714714
715- def http_list (self , path , query_data = {}, ** kwargs ):
715+ def http_list (self , path , query_data = {}, as_list = None , ** kwargs ):
716716 """Make a GET request to the Gitlab server for list-oriented queries.
717717
718718 Args:
@@ -723,19 +723,33 @@ def http_list(self, path, query_data={}, **kwargs):
723723 all)
724724
725725 Returns:
726- GitlabList: A generator giving access to the objects. If an ``all``
727- kwarg is defined and True, returns a list of all the objects (will
728- possibly make numerous calls to the Gtilab server and eat a lot of
729- memory)
726+ list: A list of the objects returned by the server. If `as_list` is
727+ False and no pagination-related arguments (`page`, `per_page`,
728+ `all`) are defined then a GitlabList object (generator) is returned
729+ instead. This object will make API calls when needed to fetch the
730+ next items from the server.
730731
731732 Raises:
732733 GitlabHttpError: When the return code is not 2xx
733734 GitlabParsingError: If the json data could not be parsed
734735 """
736+
737+ # In case we want to change the default behavior at some point
738+ as_list = True if as_list is None else as_list
739+
740+ get_all = kwargs .get ('all' , False )
735741 url = self ._build_url (path )
736- get_all = kwargs .pop ('all' , False )
737- obj_gen = GitlabList (self , url , query_data , ** kwargs )
738- return list (obj_gen ) if get_all else obj_gen
742+
743+ if get_all is True :
744+ return list (GitlabList (self , url , query_data , ** kwargs ))
745+
746+ if 'page' in kwargs or 'per_page' in kwargs or as_list is True :
747+ # pagination requested, we return a list
748+ return list (GitlabList (self , url , query_data , get_next = False ,
749+ ** kwargs ))
750+
751+ # No pagination, generator requested
752+ return GitlabList (self , url , query_data , ** kwargs )
739753
740754 def http_post (self , path , query_data = {}, post_data = {}, ** kwargs ):
741755 """Make a POST request to the Gitlab server.
@@ -816,9 +830,10 @@ class GitlabList(object):
816830 the API again when needed.
817831 """
818832
819- def __init__ (self , gl , url , query_data , ** kwargs ):
833+ def __init__ (self , gl , url , query_data , get_next = True , ** kwargs ):
820834 self ._gl = gl
821835 self ._query (url , query_data , ** kwargs )
836+ self ._get_next = get_next
822837
823838 def _query (self , url , query_data = {}, ** kwargs ):
824839 result = self ._gl .http_request ('get' , url , query_data = query_data ,
@@ -856,7 +871,7 @@ def next(self):
856871 self ._current += 1
857872 return item
858873 except IndexError :
859- if self ._next_url :
874+ if self ._next_url and self . _get_next is True :
860875 self ._query (self ._next_url )
861876 return self .next ()
862877
0 commit comments