Skip to content

Commit b14ec81

Browse files
committed
remove duplication in page cration
1 parent 0b8c58e commit b14ec81

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/msgraph_core/tasks/page_iterator.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ async def iterate(self, callback: Callable) -> None:
131131
self.current_page = next_page
132132
self.pause_index = 0
133133

134+
@staticmethod
135+
def create_page_result(value: Any, next_link: str) -> PageResult:
136+
page: PageResult[Any] = PageResult()
137+
page.odata_next_link = next_link
138+
page.set_value(value)
139+
return page
140+
134141
async def next(self) -> Optional[PageResult]:
135142
"""
136143
Fetches the next page of items.
@@ -140,10 +147,7 @@ async def next(self) -> Optional[PageResult]:
140147
if self.current_page is not None and not self.current_page.odata_next_link:
141148
return None
142149
response = self.convert_to_page(await self.fetch_next_page())
143-
page: PageResult[Any] = PageResult()
144-
page.odata_next_link = response.odata_next_link
145-
page.set_value(response.get('value', []) if isinstance(response, dict) else [])
146-
return page
150+
return PageIterator.create_page_result(response.value, response.odata_next_link)
147151

148152
@staticmethod
149153
def convert_to_page(response: Union[T, list, object]) -> PageResult:
@@ -174,11 +178,7 @@ def convert_to_page(response: Union[T, list, object]) -> PageResult:
174178
next_link = parsable_page.get('odata_next_link', '') if isinstance(
175179
parsable_page, dict
176180
) else getattr(parsable_page, 'odata_next_link', '')
177-
178-
page: PageResult[Any] = PageResult()
179-
page.odata_next_link = next_link
180-
page.set_value(value)
181-
return page
181+
return PageIterator.create_page_result(value, next_link)
182182

183183
async def fetch_next_page(self) -> dict:
184184
"""

0 commit comments

Comments
 (0)