@@ -45,6 +45,46 @@ def _create_body(body, representation):
4545
4646 return {representation : {"value" : body , "representation" : representation }}
4747
48+ def _get_paged (self , url , params = None , data = None , flags = None , trailing = None , absolute = False ):
49+ """
50+ Used to get the paged data
51+
52+ :param url: string: The url to retrieve
53+ :param params: dict (default is None): The parameters
54+ :param data: dict (default is None): The data
55+ :param flags: string[] (default is None): The flags
56+ :param trailing: bool (default is None): If True, a trailing slash is added to the url
57+ :param absolute: bool (default is False): If True, the url is used absolute and not relative to the root
58+
59+ :return: A generator object for the data elements
60+ """
61+
62+ if params is None :
63+ params = {}
64+
65+ while True :
66+ response = self .get (url , trailing = trailing , params = params , data = data , flags = flags , absolute = absolute )
67+ if "results" not in response :
68+ return
69+
70+ for value in response .get ("results" , []):
71+ yield value
72+
73+ # According to Cloud and Server documentation the links are returned the same way:
74+ # https://developer.atlassian.com/cloud/confluence/rest/api-group-content/#api-wiki-rest-api-content-get
75+ # https://developer.atlassian.com/server/confluence/pagination-in-the-rest-api/
76+ url = response .get ("_links" , {}).get ("next" )
77+ if url is None :
78+ break
79+ # From now on we have absolute URLs with parameters
80+ absolute = True
81+ # Params are now provided by the url
82+ params = {}
83+ # Trailing should not be added as it is already part of the url
84+ trailing = False
85+
86+ return
87+
4888 def page_exists (self , space , title ):
4989 try :
5090 if self .get_page_by_title (space , title ):
@@ -79,7 +119,13 @@ def get_page_child_by_type(self, page_id, type="page", start=None, limit=None, e
79119 log .info (url )
80120
81121 try :
82- response = self .get (url , params = params )
122+ if not self .advanced_mode and start is None and limit is None :
123+ return self ._get_paged (url , params = params )
124+ else :
125+ response = self .get (url , params = params )
126+ if self .advanced_mode :
127+ return response
128+ return response .get ("results" )
83129 except HTTPError as e :
84130 if e .response .status_code == 404 :
85131 # Raise ApiError as the documented reason is ambiguous
@@ -91,10 +137,6 @@ def get_page_child_by_type(self, page_id, type="page", start=None, limit=None, e
91137
92138 raise
93139
94- if self .advanced_mode :
95- return response
96- return response .get ("results" )
97-
98140 def get_child_title_list (self , page_id , type = "page" , start = None , limit = None ):
99141 """
100142 Find a list of Child title
0 commit comments