Skip to content

Commit

Permalink
Now download_attachments is respected when using batch (googleapis#173)
Browse files Browse the repository at this point in the history
Paginator can now accept any extra arguments to pass to the constructor
  • Loading branch information
janscas committed Jan 18, 2019
1 parent f056785 commit a6db122
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 2 additions & 4 deletions O365/mailbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,6 @@ def get_messages(self, limit=25, *, query=None, order_by=None, batch=None,
if limit is None or limit > self.protocol.max_top_value:
batch = self.protocol.max_top_value

if batch:
download_attachments = False

params = {'$top': batch if batch else limit}

if order_by:
Expand Down Expand Up @@ -204,7 +201,8 @@ def get_messages(self, limit=25, *, query=None, order_by=None, batch=None,
if batch and next_link:
return Pagination(parent=self, data=messages,
constructor=self.message_constructor,
next_link=next_link, limit=limit)
next_link=next_link, limit=limit,
download_attachments=download_attachments)
else:
return messages

Expand Down
12 changes: 8 additions & 4 deletions O365/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class Pagination(ApiComponent):
""" Utility class that allows batching requests to the server """

def __init__(self, *, parent=None, data=None, constructor=None,
next_link=None, limit=None):
next_link=None, limit=None, **kwargs):
""" Returns an iterator that returns data until it's exhausted.
Then will request more data (same amount as the original request)
to the server until this data is exhausted as well.
Expand All @@ -158,6 +158,8 @@ def __init__(self, *, parent=None, data=None, constructor=None,
It can be a function.
:param str next_link: the link to request more data to
:param int limit: when to stop retrieving more data
:param kwargs: any extra key-word arguments to pass to the
construtctor.
"""
if parent is None:
raise ValueError('Parent must be another Api Component')
Expand All @@ -180,12 +182,14 @@ def __init__(self, *, parent=None, data=None, constructor=None,
self.data_count = data_count
self.total_count = data_count
self.state = 0
self.extra_args = kwargs

def __str__(self):
return self.__repr__()

def __repr__(self):
if callable(self.constructor):
if callable(self.constructor) and not isinstance(
self.constructor, type):
return 'Pagination Iterator'
else:
return "'{}' Iterator".format(
Expand Down Expand Up @@ -222,10 +226,10 @@ def __next__(self):
if callable(self.constructor) and not isinstance(self.constructor,
type):
self.data = [self.constructor(value)(parent=self.parent, **{
self._cloud_data_key: value}) for value in data]
self._cloud_data_key: value}, **self.extra_args) for value in data]
else:
self.data = [self.constructor(parent=self.parent,
**{self._cloud_data_key: value})
**{self._cloud_data_key: value}, **self.extra_args)
for value in data]
else:
self.data = data
Expand Down

0 comments on commit a6db122

Please sign in to comment.