INSTRUCTION stringlengths 1 46.3k | RESPONSE stringlengths 75 80.2k |
|---|---|
Makes a request to url using an oauth session
:param str url: url to send request to
:param str method: type of request (get/put/post/patch/delete)
:param kwargs: extra params to send to the request api
:return: Response of the request
:rtype: requests.Response | def oauth_request(self, url, method, **kwargs):
""" Makes a request to url using an oauth session
:param str url: url to send request to
:param str method: type of request (get/put/post/patch/delete)
:param kwargs: extra params to send to the request api
:return: Response of the... |
Shorthand for self.oauth_request(url, 'get')
:param str url: url to send get oauth request to
:param dict params: request parameter to get the service data
:param kwargs: extra params to send to request api
:return: Response of the request
:rtype: requests.Response | def get(self, url, params=None, **kwargs):
""" Shorthand for self.oauth_request(url, 'get')
:param str url: url to send get oauth request to
:param dict params: request parameter to get the service data
:param kwargs: extra params to send to request api
:return: Response of the ... |
Shorthand for self.oauth_request(url, 'post')
:param str url: url to send post oauth request to
:param dict data: post data to update the service
:param kwargs: extra params to send to request api
:return: Response of the request
:rtype: requests.Response | def post(self, url, data=None, **kwargs):
""" Shorthand for self.oauth_request(url, 'post')
:param str url: url to send post oauth request to
:param dict data: post data to update the service
:param kwargs: extra params to send to request api
:return: Response of the request
... |
Shorthand for self.oauth_request(url, 'put')
:param str url: url to send put oauth request to
:param dict data: put data to update the service
:param kwargs: extra params to send to request api
:return: Response of the request
:rtype: requests.Response | def put(self, url, data=None, **kwargs):
""" Shorthand for self.oauth_request(url, 'put')
:param str url: url to send put oauth request to
:param dict data: put data to update the service
:param kwargs: extra params to send to request api
:return: Response of the request
... |
Shorthand for self.oauth_request(url, 'patch')
:param str url: url to send patch oauth request to
:param dict data: patch data to update the service
:param kwargs: extra params to send to request api
:return: Response of the request
:rtype: requests.Response | def patch(self, url, data=None, **kwargs):
""" Shorthand for self.oauth_request(url, 'patch')
:param str url: url to send patch oauth request to
:param dict data: patch data to update the service
:param kwargs: extra params to send to request api
:return: Response of the request... |
Name of the attachment
:getter: get attachment name
:setter: set new name for the attachment
:type: str | def attachment_name(self):
""" Name of the attachment
:getter: get attachment name
:setter: set new name for the attachment
:type: str
"""
if self.__attachment_name is not None:
return self.__attachment_name
if self.__attachment_name_property:
... |
Returns a dict to communicate with the server
:rtype: dict | def to_api_data(self):
""" Returns a dict to communicate with the server
:rtype: dict
"""
data = {'@odata.type': self._gk(
'{}_attachment_type'.format(self.attachment_type)),
self._cc('name'): self.name}
if self.attachment_type == 'file':
dat... |
Save the attachment locally to disk
:param str location: path string to where the file is to be saved.
:param str custom_name: a custom name to be saved as
:return: Success / Failure
:rtype: bool | def save(self, location=None, custom_name=None):
""" Save the attachment locally to disk
:param str location: path string to where the file is to be saved.
:param str custom_name: a custom name to be saved as
:return: Success / Failure
:rtype: bool
"""
if not se... |
Attach this attachment to an existing api_object. This
BaseAttachment object must be an orphan BaseAttachment created for the
sole purpose of attach it to something and therefore run this method.
:param api_object: object to attach to
:param on_cloud: if the attachment is on cloud or no... | def attach(self, api_object, on_cloud=False):
""" Attach this attachment to an existing api_object. This
BaseAttachment object must be an orphan BaseAttachment created for the
sole purpose of attach it to something and therefore run this method.
:param api_object: object to attach to
... |
Returns a dict to communicate with the server
:rtype: dict | def to_api_data(self):
""" Returns a dict to communicate with the server
:rtype: dict
"""
return [attachment.to_api_data() for attachment in self.__attachments if
attachment.on_cloud is False] |
Clear the attachments | def clear(self):
""" Clear the attachments """
for attachment in self.__attachments:
if attachment.on_cloud:
self.__removed_attachments.append(attachment)
self.__attachments = []
self._update_parent_attachments()
self._track_changes() |
Tries to update the parent property 'has_attachments' | def _update_parent_attachments(self):
""" Tries to update the parent property 'has_attachments' """
try:
self._parent.has_attachments = bool(len(self.__attachments))
except AttributeError:
pass |
Add more attachments
:param attachments: list of attachments
:type attachments: list[str] or list[Path] or str or Path or dict | def add(self, attachments):
""" Add more attachments
:param attachments: list of attachments
:type attachments: list[str] or list[Path] or str or Path or dict
"""
if attachments:
if isinstance(attachments, (str, Path)):
attachments = [attachments]
... |
Remove the specified attachments
:param attachments: list of attachments
:type attachments: list[str] or list[Path] or str or Path or dict | def remove(self, attachments):
""" Remove the specified attachments
:param attachments: list of attachments
:type attachments: list[str] or list[Path] or str or Path or dict
"""
if isinstance(attachments, (list, tuple)):
attachments = ({attachment.name
... |
Downloads this message attachments into memory.
Need a call to 'attachment.save' to save them on disk.
:return: Success / Failure
:rtype: bool | def download_attachments(self):
""" Downloads this message attachments into memory.
Need a call to 'attachment.save' to save them on disk.
:return: Success / Failure
:rtype: bool
"""
if not self._parent.has_attachments:
log.debug(
'Parent {} h... |
Update the track_changes on the parent to reflect a
needed update on this field | def _track_changes(self):
""" Update the track_changes on the parent to reflect a
needed update on this field """
if self._field and getattr(self._parent, '_track_changes',
None) is not None:
self._parent._track_changes.add(self._field) |
Update the track_changes on the parent to reflect a
needed update on this field | def _track_changes(self):
""" Update the track_changes on the parent to reflect a
needed update on this field """
if self._field and getattr(self._parent, '_track_changes',
None) is not None and self.untrack is False:
self._parent._track_changes.add... |
Add the supplied recipients to the exiting list
:param recipients: list of either address strings or
tuples (name, address) or dictionary elements
:type recipients: list[str] or list[tuple] or list[dict] | def add(self, recipients):
""" Add the supplied recipients to the exiting list
:param recipients: list of either address strings or
tuples (name, address) or dictionary elements
:type recipients: list[str] or list[tuple] or list[dict]
"""
if recipients:
if ... |
Remove an address or multiple addresses
:param address: list of addresses to remove
:type address: str or list[str] | def remove(self, address):
""" Remove an address or multiple addresses
:param address: list of addresses to remove
:type address: str or list[str]
"""
recipients = []
if isinstance(address, str):
address = {address} # set
elif isinstance(address, (li... |
Returns the first recipient found with a non blank address
:return: First Recipient
:rtype: Recipient | def get_first_recipient_with_address(self):
""" Returns the first recipient found with a non blank address
:return: First Recipient
:rtype: Recipient
"""
recipients_with_address = [recipient for recipient in self._recipients
if recipient.addres... |
Transform a recipient from cloud data to object data | def _recipients_from_cloud(self, recipients, field=None):
""" Transform a recipient from cloud data to object data """
recipients_data = []
for recipient in recipients:
recipients_data.append(
self._recipient_from_cloud(recipient, field=field))
return Recipien... |
Transform a recipient from cloud data to object data | def _recipient_from_cloud(self, recipient, field=None):
""" Transform a recipient from cloud data to object data """
if recipient:
recipient = recipient.get(self._cc('emailAddress'),
recipient if isinstance(recipient,
... |
Transforms a Recipient object to a cloud dict | def _recipient_to_cloud(self, recipient):
""" Transforms a Recipient object to a cloud dict """
data = None
if recipient:
data = {self._cc('emailAddress'): {
self._cc('address'): recipient.address}}
if recipient.name:
data[self._cc('emailAd... |
Parses and completes resource information | def _parse_resource(resource):
""" Parses and completes resource information """
resource = resource.strip() if resource else resource
if resource in {ME_RESOURCE, USERS_RESOURCE}:
return resource
elif '@' in resource and not resource.startswith(USERS_RESOURCE):
#... |
Parses and convert to protocol timezone a dateTimeTimeZone resource
This resource is a dict with a date time and a windows timezone
This is a common structure on Microsoft apis so it's included here. | def _parse_date_time_time_zone(self, date_time_time_zone):
""" Parses and convert to protocol timezone a dateTimeTimeZone resource
This resource is a dict with a date time and a windows timezone
This is a common structure on Microsoft apis so it's included here.
"""
if date_time_... |
Converts a datetime to a dateTimeTimeZone resource | def _build_date_time_time_zone(self, date_time):
""" Converts a datetime to a dateTimeTimeZone resource """
timezone = date_time.tzinfo.zone if date_time.tzinfo is not None else None
return {
self._cc('dateTime'): date_time.strftime('%Y-%m-%dT%H:%M:%S'),
self._cc('timeZon... |
Adds the attribute to the $select parameter
:param str attributes: the attributes tuple to select.
If empty, the on_attribute previously set is added.
:rtype: Query | def select(self, *attributes):
""" Adds the attribute to the $select parameter
:param str attributes: the attributes tuple to select.
If empty, the on_attribute previously set is added.
:rtype: Query
"""
if attributes:
for attribute in attributes:
... |
Adds the relationships (e.g. "event" or "attachments")
that should be expanded with the $expand parameter
Important: The ApiComponent using this should know how to handle this relationships.
eg: Message knows how to handle attachments, and event (if it's an EventMessage).
Important: ... | def expand(self, *relationships):
""" Adds the relationships (e.g. "event" or "attachments")
that should be expanded with the $expand parameter
Important: The ApiComponent using this should know how to handle this relationships.
eg: Message knows how to handle attachments, and event ... |
Perform a search.
Not from graph docs:
You can currently search only message and person collections.
A $search request returns up to 250 results.
You cannot use $filter or $orderby in a search request.
:param str text: the text to search
:return: the Query instance | def search(self, text):
"""
Perform a search.
Not from graph docs:
You can currently search only message and person collections.
A $search request returns up to 250 results.
You cannot use $filter or $orderby in a search request.
:param str text: the text to se... |
Returns the filters, orders, select, expands and search as query parameters
:rtype: dict | def as_params(self):
""" Returns the filters, orders, select, expands and search as query parameters
:rtype: dict
"""
params = {}
if self.has_filters:
params['$filter'] = self.get_filters()
if self.has_order:
params['$orderby'] = self.get_order()
... |
Returns the result filters
:rtype: str or None | def get_filters(self):
""" Returns the result filters
:rtype: str or None
"""
if self._filters:
filters_list = self._filters
if isinstance(filters_list[-1], Enum):
filters_list = filters_list[:-1]
return ' '.join(
[fs.v... |
Returns the result order by clauses
:rtype: str or None | def get_order(self):
""" Returns the result order by clauses
:rtype: str or None
"""
# first get the filtered attributes in order as they must appear
# in the order_by first
if not self.has_order:
return None
filter_order_clauses = OrderedDict([(filte... |
Combine with a new query
:param str attribute: attribute of new query
:param ChainOperator operation: operation to combine to new query
:rtype: Query | def new(self, attribute, operation=ChainOperator.AND):
""" Combine with a new query
:param str attribute: attribute of new query
:param ChainOperator operation: operation to combine to new query
:rtype: Query
"""
if isinstance(operation, str):
operation = Cha... |
Clear everything
:rtype: Query | def clear(self):
""" Clear everything
:rtype: Query
"""
self._filters = []
self._order_by = OrderedDict()
self._selects = set()
self._negation = False
self._attribute = None
self._chain = None
self._search = None
return self |
Start a chain operation
:param ChainOperator, str operation: how to combine with a new one
:rtype: Query | def chain(self, operation=ChainOperator.AND):
""" Start a chain operation
:param ChainOperator, str operation: how to combine with a new one
:rtype: Query
"""
if isinstance(operation, str):
operation = ChainOperator(operation)
self._chain = operation
... |
Removes a filter given the attribute name | def remove_filter(self, filter_attr):
""" Removes a filter given the attribute name """
filter_attr = self._get_mapping(filter_attr)
new_filters = []
remove_chain = False
for flt in self._filters:
if isinstance(flt, tuple):
if flt[0] == filter_attr:
... |
Converts the word parameter into the correct format | def _parse_filter_word(self, word):
""" Converts the word parameter into the correct format """
if isinstance(word, str):
word = "'{}'".format(word)
elif isinstance(word, dt.date):
if isinstance(word, dt.datetime):
if word.tzinfo is None:
... |
Apply a logical operator
:param str operation: how to combine with a new one
:param word: other parameter for the operation
(a = b) would be like a.logical_operator('eq', 'b')
:rtype: Query | def logical_operator(self, operation, word):
""" Apply a logical operator
:param str operation: how to combine with a new one
:param word: other parameter for the operation
(a = b) would be like a.logical_operator('eq', 'b')
:rtype: Query
"""
word = self._parse_... |
Apply a function on given word
:param str function_name: function to apply
:param str word: word to apply function on
:rtype: Query | def function(self, function_name, word):
""" Apply a function on given word
:param str function_name: function to apply
:param str word: word to apply function on
:rtype: Query
"""
word = self._parse_filter_word(word)
self._add_filter(
*self._prepare... |
Performs a filter with the OData 'iterable_name' keyword
on the collection
For example:
q.iterable('any', collection='email_addresses', attribute='address',
operation='eq', word='george@best.com')
will transform to a filter such as:
emailAddresses/any(a:a/address eq 'ge... | def iterable(self, iterable_name, *, collection, attribute, word, func=None,
operation=None):
""" Performs a filter with the OData 'iterable_name' keyword
on the collection
For example:
q.iterable('any', collection='email_addresses', attribute='address',
operati... |
Performs a filter with the OData 'any' keyword on the collection
For example:
q.any(collection='email_addresses', attribute='address',
operation='eq', word='george@best.com')
will transform to a filter such as:
emailAddresses/any(a:a/address eq 'george@best.com')
:par... | def any(self, *, collection, attribute, word, func=None, operation=None):
""" Performs a filter with the OData 'any' keyword on the collection
For example:
q.any(collection='email_addresses', attribute='address',
operation='eq', word='george@best.com')
will transform to a filte... |
Performs a filter with the OData 'all' keyword on the collection
For example:
q.any(collection='email_addresses', attribute='address',
operation='eq', word='george@best.com')
will transform to a filter such as:
emailAddresses/all(a:a/address eq 'george@best.com')
:par... | def all(self, *, collection, attribute, word, func=None, operation=None):
""" Performs a filter with the OData 'all' keyword on the collection
For example:
q.any(collection='email_addresses', attribute='address',
operation='eq', word='george@best.com')
will transform to a filte... |
Applies a order_by clause
:param str attribute: attribute to apply on
:param bool ascending: should it apply ascending order or descending
:rtype: Query | def order_by(self, attribute=None, *, ascending=True):
""" Applies a order_by clause
:param str attribute: attribute to apply on
:param bool ascending: should it apply ascending order or descending
:rtype: Query
"""
attribute = self._get_mapping(attribute) or self._attri... |
Returns a list of open planner tasks assigned to me
:rtype: tasks | def get_my_tasks(self, *args):
""" Returns a list of open planner tasks assigned to me
:rtype: tasks
"""
url = self.build_url(self._endpoints.get('get_my_tasks'))
response = self.con.get(url)
if not response:
return None
data = response.json()
... |
Returns a valid pytz TimeZone (Iana/Olson Timezones) from a given
windows TimeZone
:param windows_tz: windows format timezone usually returned by
microsoft api response
:return:
:rtype: | def get_iana_tz(windows_tz):
""" Returns a valid pytz TimeZone (Iana/Olson Timezones) from a given
windows TimeZone
:param windows_tz: windows format timezone usually returned by
microsoft api response
:return:
:rtype:
"""
timezone = WIN_TO_IANA.get(windows_tz)
if timezone is None:... |
Returns a valid windows TimeZone from a given pytz TimeZone
(Iana/Olson Timezones)
Note: Windows Timezones are SHIT!... no ... really THEY ARE
HOLY FUCKING SHIT!. | def get_windows_tz(iana_tz):
""" Returns a valid windows TimeZone from a given pytz TimeZone
(Iana/Olson Timezones)
Note: Windows Timezones are SHIT!... no ... really THEY ARE
HOLY FUCKING SHIT!.
"""
timezone = IANA_TO_WIN.get(
iana_tz.zone if isinstance(iana_tz, tzinfo) else iana_tz)
... |
Update the value for a field(s) in the listitem
:param update: A dict of {'field name': newvalue} | def update_fields(self, updates):
"""
Update the value for a field(s) in the listitem
:param update: A dict of {'field name': newvalue}
"""
for field in updates:
if self._valid_field(field):
self._track_changes.add(field)
else:
... |
Save the updated fields to the cloud | def save_updates(self):
"""Save the updated fields to the cloud"""
if not self._track_changes:
return True # there's nothing to update
url = self.build_url(self._endpoints.get('update_list_item').format(item_id=self.object_id))
update = {field: value for field, value in se... |
Returns a collection of Sharepoint Items
:rtype: list[SharepointListItem] | def get_items(self):
""" Returns a collection of Sharepoint Items
:rtype: list[SharepointListItem]
"""
url = self.build_url(self._endpoints.get('get_items'))
response = self.con.get(url)
if not response:
return []
data = response.json()
re... |
Returns a sharepoint list item based on id | def get_item_by_id(self, item_id):
""" Returns a sharepoint list item based on id"""
url = self.build_url(self._endpoints.get('get_item_by_id').format(item_id=item_id))
response = self.con.get(url)
if not response:
return []
data = response.json()
return ... |
Returns the sharepoint list columns | def get_list_columns(self):
""" Returns the sharepoint list columns """
url = self.build_url(self._endpoints.get('get_list_columns'))
response = self.con.get(url)
if not response:
return []
data = response.json()
return [self.list_column_constructor(paren... |
Create new list item
:param new_data: dictionary of {'col_name': col_value}
:rtype: SharepointListItem | def create_list_item(self, new_data):
"""Create new list item
:param new_data: dictionary of {'col_name': col_value}
:rtype: SharepointListItem
"""
url = self.build_url(self._endpoints.get('get_items'))
response = self.con.post(url, {'fields': new_data})
if no... |
Delete an existing list item
:param item_id: Id of the item to be delted | def delete_list_item(self, item_id):
""" Delete an existing list item
:param item_id: Id of the item to be delted
"""
url = self.build_url(self._endpoints.get('get_item_by_id').format(item_id=item_id))
response = self.con.delete(url)
return bool(response) |
Returns a collection of document libraries for this site
(a collection of Drive instances)
:param int limit: max no. of items to get. Over 999 uses batch.
:param query: applies a OData filter to the request
:type query: Query or str
:param order_by: orders the result set based o... | def list_document_libraries(self, limit=None, *, query=None, order_by=None,
batch=None):
""" Returns a collection of document libraries for this site
(a collection of Drive instances)
:param int limit: max no. of items to get. Over 999 uses batch.
:param ... |
Returns a list of subsites defined for this site
:rtype: list[Site] | def get_subsites(self):
""" Returns a list of subsites defined for this site
:rtype: list[Site]
"""
url = self.build_url(
self._endpoints.get('get_subsites').format(id=self.object_id))
response = self.con.get(url)
if not response:
return []
... |
Returns a collection of lists within this site
:rtype: list[SharepointList] | def get_lists(self):
""" Returns a collection of lists within this site
:rtype: list[SharepointList]
"""
url = self.build_url(self._endpoints.get('get_lists'))
response = self.con.get(url)
if not response:
return []
data = response.json()
r... |
Returns a sharepoint list based on the display name of the list | def get_list_by_name(self, display_name):
"""
Returns a sharepoint list based on the display name of the list
"""
if not display_name:
raise ValueError('Must provide a valid list display name')
url = self.build_url(self._endpoints.get('get_list_by_name').format(disp... |
Search a sharepoint host for sites with the provided keyword
:param keyword: a keyword to search sites
:rtype: list[Site] | def search_site(self, keyword):
""" Search a sharepoint host for sites with the provided keyword
:param keyword: a keyword to search sites
:rtype: list[Site]
"""
if not keyword:
raise ValueError('Must provide a valid keyword')
url = self.build_url(
... |
Returns a sharepoint site
:param args: It accepts multiple ways of retrieving a site:
get_site(host_name): the host_name: host_name ej.
'contoso.sharepoint.com' or 'root'
get_site(site_id): the site_id: a comma separated string of
(host_name, site_collection_id, site_id)
... | def get_site(self, *args):
""" Returns a sharepoint site
:param args: It accepts multiple ways of retrieving a site:
get_site(host_name): the host_name: host_name ej.
'contoso.sharepoint.com' or 'root'
get_site(site_id): the site_id: a comma separated string of
(ho... |
Returns a list of child folders matching the query
:param int limit: max no. of folders to get. Over 999 uses batch.
:param query: applies a filter to the request such as
"displayName eq 'HelloFolder'"
:type query: Query or str
:param order_by: orders the result set based on th... | def get_folders(self, limit=None, *, query=None, order_by=None, batch=None):
""" Returns a list of child folders matching the query
:param int limit: max no. of folders to get. Over 999 uses batch.
:param query: applies a filter to the request such as
"displayName eq 'HelloFolder'"
... |
Get one message from the query result.
A shortcut to get_messages with limit=1
:param object_id: the message id to be retrieved.
:param query: applies a filter to the request such as
"displayName eq 'HelloFolder'"
:type query: Query or str
:param bool download_attachmen... | def get_message(self, object_id=None, query=None, *, download_attachments=False):
""" Get one message from the query result.
A shortcut to get_messages with limit=1
:param object_id: the message id to be retrieved.
:param query: applies a filter to the request such as
"displayN... |
Downloads messages from this folder
:param int limit: limits the result set. Over 999 uses batch.
:param query: applies a filter to the request such as
"displayName eq 'HelloFolder'"
:type query: Query or str
:param order_by: orders the result set based on this condition
... | def get_messages(self, limit=25, *, query=None, order_by=None, batch=None,
download_attachments=False):
"""
Downloads messages from this folder
:param int limit: limits the result set. Over 999 uses batch.
:param query: applies a filter to the request such as
... |
Get a folder by it's id or name
:param str folder_id: the folder_id to be retrieved.
Can be any folder Id (child or not)
:param str folder_name: the folder name to be retrieved.
Must be a child of this folder.
:return: a single folder
:rtype: mailbox.Folder or None | def get_folder(self, *, folder_id=None, folder_name=None):
""" Get a folder by it's id or name
:param str folder_id: the folder_id to be retrieved.
Can be any folder Id (child or not)
:param str folder_name: the folder name to be retrieved.
Must be a child of this folder.
... |
Re-download folder data
Inbox Folder will be unable to download its own data (no folder_id)
:param bool update_parent_if_changed: updates self.parent with new
parent Folder if changed
:return: Refreshed or Not
:rtype: bool | def refresh_folder(self, update_parent_if_changed=False):
""" Re-download folder data
Inbox Folder will be unable to download its own data (no folder_id)
:param bool update_parent_if_changed: updates self.parent with new
parent Folder if changed
:return: Refreshed or Not
... |
Get the parent folder from attribute self.parent or
getting it from the cloud
:return: Parent Folder
:rtype: mailbox.Folder or None | def get_parent_folder(self):
""" Get the parent folder from attribute self.parent or
getting it from the cloud
:return: Parent Folder
:rtype: mailbox.Folder or None
"""
if self.root:
return None
if self.parent:
return self.parent
... |
Change this folder name
:param str name: new name to change to
:param bool update_folder_data: whether or not to re-fetch the data
:return: Updated or Not
:rtype: bool | def update_folder_name(self, name, update_folder_data=True):
""" Change this folder name
:param str name: new name to change to
:param bool update_folder_data: whether or not to re-fetch the data
:return: Updated or Not
:rtype: bool
"""
if self.root:
... |
Copy this folder and it's contents to into another folder
:param to_folder: the destination Folder/folder_id to copy into
:type to_folder: mailbox.Folder or str
:return: The new folder after copying
:rtype: mailbox.Folder or None | def copy_folder(self, to_folder):
""" Copy this folder and it's contents to into another folder
:param to_folder: the destination Folder/folder_id to copy into
:type to_folder: mailbox.Folder or str
:return: The new folder after copying
:rtype: mailbox.Folder or None
"""... |
Move this folder to another folder
:param to_folder: the destination Folder/folder_id to move into
:type to_folder: mailbox.Folder or str
:param bool update_parent_if_changed: updates self.parent with the
new parent Folder if changed
:return: The new folder after copying
... | def move_folder(self, to_folder, *, update_parent_if_changed=True):
""" Move this folder to another folder
:param to_folder: the destination Folder/folder_id to move into
:type to_folder: mailbox.Folder or str
:param bool update_parent_if_changed: updates self.parent with the
n... |
Creates a new draft message under this folder
:return: new Message
:rtype: Message | def new_message(self):
""" Creates a new draft message under this folder
:return: new Message
:rtype: Message
"""
draft_message = self.message_constructor(parent=self, is_draft=True)
if self.root:
draft_message.folder_id = OutlookWellKnowFolderNames.DRAFTS.... |
Deletes a stored message
:param message: message/message_id to delete
:type message: Message or str
:return: Success / Failure
:rtype: bool | def delete_message(self, message):
""" Deletes a stored message
:param message: message/message_id to delete
:type message: Message or str
:return: Success / Failure
:rtype: bool
"""
message_id = message.object_id if isinstance(message,
... |
Shortcut to get Inbox Folder instance
:rtype: mailbox.Folder | def inbox_folder(self):
""" Shortcut to get Inbox Folder instance
:rtype: mailbox.Folder
"""
return self.folder_constructor(parent=self, name='Inbox',
folder_id=OutlookWellKnowFolderNames
.INBOX.value) |
Shortcut to get Junk Folder instance
:rtype: mailbox.Folder | def junk_folder(self):
""" Shortcut to get Junk Folder instance
:rtype: mailbox.Folder
"""
return self.folder_constructor(parent=self, name='Junk',
folder_id=OutlookWellKnowFolderNames
.JUNK.value) |
Shortcut to get DeletedItems Folder instance
:rtype: mailbox.Folder | def deleted_folder(self):
""" Shortcut to get DeletedItems Folder instance
:rtype: mailbox.Folder
"""
return self.folder_constructor(parent=self, name='DeletedItems',
folder_id=OutlookWellKnowFolderNames
.DELE... |
Shortcut to get Drafts Folder instance
:rtype: mailbox.Folder | def drafts_folder(self):
""" Shortcut to get Drafts Folder instance
:rtype: mailbox.Folder
"""
return self.folder_constructor(parent=self, name='Drafts',
folder_id=OutlookWellKnowFolderNames
.DRAFTS.value) |
Shortcut to get SentItems Folder instance
:rtype: mailbox.Folder | def sent_folder(self):
""" Shortcut to get SentItems Folder instance
:rtype: mailbox.Folder
"""
return self.folder_constructor(parent=self, name='SentItems',
folder_id=OutlookWellKnowFolderNames
.SENT.value) |
Shortcut to get Outbox Folder instance
:rtype: mailbox.Folder | def outbox_folder(self):
""" Shortcut to get Outbox Folder instance
:rtype: mailbox.Folder
"""
return self.folder_constructor(parent=self, name='Outbox',
folder_id=OutlookWellKnowFolderNames
.OUTBOX.value) |
Request a new session id | def create_session(self):
""" Request a new session id """
url = self.build_url(self._endpoints.get('create_session'))
response = self.con.post(url, data={'persistChanges': self.persist})
if not response:
raise RuntimeError('Could not create session as requested by the user.... |
Close the current session | def close_session(self):
""" Close the current session """
if self.session_id:
url = self.build_url(self._endpoints.get('close_session'))
response = self.con.post(url, headers={'workbook-session-id': self.session_id})
return bool(response)
return False |
If session is in use, prepares the request headers and
checks if the session is expired. | def prepare_request(self, kwargs):
""" If session is in use, prepares the request headers and
checks if the session is expired.
"""
if self.session_id is not None:
actual = dt.datetime.now()
if (self.last_activity + self.inactivity_limit) < actual:
... |
Loads the data into this instance | def _load_data(self):
""" Loads the data into this instance """
url = self.parent.build_url(self.parent._endpoints.get('format'))
response = self.parent.session.get(url)
if not response:
return False
data = response.json()
self._bold = data.get('bold', False)... |
Returns a dict to communicate with the server
:param restrict_keys: a set of keys to restrict the returned data to
:rtype: dict | def to_api_data(self, restrict_keys=None):
""" Returns a dict to communicate with the server
:param restrict_keys: a set of keys to restrict the returned data to
:rtype: dict
"""
cc = self.parent._cc # alias
data = {
cc('bold'): self._bold,
cc('c... |
Returns a dict to communicate with the server
:param restrict_keys: a set of keys to restrict the returned data to
:rtype: dict | def to_api_data(self, restrict_keys=None):
""" Returns a dict to communicate with the server
:param restrict_keys: a set of keys to restrict the returned data to
:rtype: dict
"""
cc = self._cc # alias
data = {
cc('column_width'): self._column_width,
... |
Updates this range format | def update(self):
""" Updates this range format """
if self._track_changes:
data = self.to_api_data(restrict_keys=self._track_changes)
if data:
response = self.session.patch(self.build_url(''), data=data)
if not response:
return... |
Loads the data related to the fill color | def _load_background_color(self):
""" Loads the data related to the fill color """
url = self.build_url(self._endpoints.get('fill'))
response = self.session.get(url)
if not response:
return None
data = response.json()
self._background_color = data.get('color',... |
Changes the width of the columns of the current range
to achieve the best fit, based on the current data in the columns | def auto_fit_columns(self):
""" Changes the width of the columns of the current range
to achieve the best fit, based on the current data in the columns
"""
url = self.build_url(self._endpoints.get('auto_fit_columns'))
return bool(self.session.post(url)) |
Returns a dict to communicate with the server
:param restrict_keys: a set of keys to restrict the returned data to
:rtype: dict | def to_api_data(self, restrict_keys=None):
""" Returns a dict to communicate with the server
:param restrict_keys: a set of keys to restrict the returned data to
:rtype: dict
"""
cc = self._cc # alias
data = {
cc('column_hidden'): self._column_hidden,
... |
Helper that returns another range | def _get_range(self, endpoint, *args, method='GET', **kwargs):
""" Helper that returns another range"""
if args:
url = self.build_url(self._endpoints.get(endpoint).format(*args))
else:
url = self.build_url(self._endpoints.get(endpoint))
if not kwargs:
... |
Gets an object which represents a range that's offset from the specified range.
The dimension of the returned range will match this range.
If the resulting range is forced outside the bounds of the worksheet grid,
an exception will be thrown.
:param int row_offset: The number of rows... | def get_offset_range(self, row_offset, column_offset):
"""
Gets an object which represents a range that's offset from the specified range.
The dimension of the returned range will match this range.
If the resulting range is forced outside the bounds of the worksheet grid,
an ... |
Clear range values, format, fill, border, etc.
:param str apply_to: Optional. Determines the type of clear action.
The possible values are: all, formats, contents. | def clear(self, apply_to='all'):
"""
Clear range values, format, fill, border, etc.
:param str apply_to: Optional. Determines the type of clear action.
The possible values are: all, formats, contents.
"""
url = self.build_url(self._endpoints.get('clear_range'))
r... |
Deletes the cells associated with the range.
:param str shift: Optional. Specifies which way to shift the cells.
The possible values are: up, left. | def delete(self, shift='up'):
"""
Deletes the cells associated with the range.
:param str shift: Optional. Specifies which way to shift the cells.
The possible values are: up, left.
"""
url = self.build_url(self._endpoints.get('delete_range'))
return bool(self.se... |
Merge the range cells into one region in the worksheet.
:param bool across: Optional. Set True to merge cells in each row of the
specified range as separate merged cells. | def merge(self, across=False):
"""
Merge the range cells into one region in the worksheet.
:param bool across: Optional. Set True to merge cells in each row of the
specified range as separate merged cells.
"""
url = self.build_url(self._endpoints.get('merge_range'))
... |
Update this range | def update(self):
""" Update this range """
if not self._track_changes:
return True # there's nothing to update
data = self.to_api_data(restrict_keys=self._track_changes)
response = self.session.patch(self.build_url(''), data=data)
if not response:
retu... |
Returns a RangeFormat instance with the format of this range | def get_format(self):
""" Returns a RangeFormat instance with the format of this range """
url = self.build_url(self._endpoints.get('get_format'))
response = self.session.get(url)
if not response:
return None
return self.range_format_constructor(parent=self, **{self._... |
Updates this row | def update(self, values):
""" Updates this row """
response = self.session.patch(self.build_url(''), data={'values': values})
if not response:
return False
data = response.json()
self.values = data.get('values', self.values)
return True |
Updates this named range
:param bool visible: Specifies whether the object is visible or not
:param str comment: Represents the comment associated with this name
:return: Success or Failure | def update(self, *, visible=None, comment=None):
"""
Updates this named range
:param bool visible: Specifies whether the object is visible or not
:param str comment: Represents the comment associated with this name
:return: Success or Failure
"""
if visible is Non... |
Apply the given filter criteria on the given column.
:param str criteria: the criteria to apply
criteria example:
{
"color": "string",
"criterion1": "string",
"criterion2": "string",
"dynamicCriteria": "string",
"filterOn": "string",
"i... | def apply_filter(self, criteria):
"""
Apply the given filter criteria on the given column.
:param str criteria: the criteria to apply
criteria example:
{
"color": "string",
"criterion1": "string",
"criterion2": "string",
"dynamicCriteria": ... |
Returns the filter applie to this column | def get_filter(self):
""" Returns the filter applie to this column """
q = self.q().select('name').expand('filter')
response = self.session.get(self.build_url(''), params=q.as_params())
if not response:
return None
data = response.json()
return data.get('crite... |
Return the columns of this table
:param int top: specify n columns to retrieve
:param int skip: specify n columns to skip | def get_columns(self, *, top=None, skip=None):
"""
Return the columns of this table
:param int top: specify n columns to retrieve
:param int skip: specify n columns to skip
"""
url = self.build_url(self._endpoints.get('get_columns'))
params = {}
if top is... |
Gets a column from this table by id or name
:param id_or_name: the id or name of the column
:return: WorkBookTableColumn | def get_column(self, id_or_name):
"""
Gets a column from this table by id or name
:param id_or_name: the id or name of the column
:return: WorkBookTableColumn
"""
url = self.build_url(self._endpoints.get('get_column').format(quote(id_or_name)))
response = self.ses... |
Returns a table column by it's index
:param int index: the zero-indexed position of the column in the table | def get_column_at_index(self, index):
"""
Returns a table column by it's index
:param int index: the zero-indexed position of the column in the table
"""
if index is None:
return None
url = self.build_url(self._endpoints.get('get_column_index'))
respo... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.