INSTRUCTION stringlengths 1 8.43k | RESPONSE stringlengths 75 104k |
|---|---|
A helper method to perform the OAuth2 authentication flow. Authenticate and get the oauth token | def oauth_authentication_flow(client_id, client_secret, scopes=None,
protocol=None, **kwargs):
""" A helper method to perform the OAuth2 authentication flow.
Authenticate and get the oauth token
:param str client_id: the client_id
:param str client_secret: the client_secre... |
Returns a list of scopes needed for each of the scope_helpers provided by adding the prefix to them if required | def get_scopes_for(self, user_provided_scopes):
""" Returns a list of scopes needed for each of the
scope_helpers provided, by adding the prefix to them if required
:param user_provided_scopes: a list of scopes or scope helpers
:type user_provided_scopes: list or tuple or str
:r... |
Inserts the protocol scope prefix if required | def _prefix_scope(self, scope):
""" Inserts the protocol scope prefix if required"""
if self.protocol_scope_prefix:
if isinstance(scope, tuple):
return scope[0]
elif scope.startswith(self.protocol_scope_prefix):
return scope
else:
... |
Sets a proxy on the Session | def set_proxy(self, proxy_server, proxy_port, proxy_username,
proxy_password):
""" Sets a proxy on the Session
:param str proxy_server: the proxy server
:param int proxy_port: the proxy port, defaults to 8080
:param str proxy_username: the proxy username
:param... |
Checks if the token file exists at the given position | def check_token_file(self):
""" Checks if the token file exists at the given position
:return: if file exists or not
:rtype: bool
"""
# TODO: remove this method in a future release
warnings.warn('This method will be removed in future versions',
Depr... |
Initializes the oauth authorization flow getting the authorization url that the user must approve. | def get_authorization_url(self, requested_scopes=None,
redirect_uri=OAUTH_REDIRECT_URL, **kwargs):
""" Initializes the oauth authorization flow, getting the
authorization url that the user must approve.
:param list[str] requested_scopes: list of scopes to request a... |
Authenticates for the specified url and gets the token save the token for future based if requested | def request_token(self, authorization_url, store_token=True,
token_path=None, **kwargs):
""" Authenticates for the specified url and gets the token, save the
token for future based if requested
:param str authorization_url: url given by the authorization flow
:para... |
Create a requests Session object | def get_session(self, token_path=None):
""" Create a requests Session object
:param Path token_path: (Only oauth) full path to where the token
should be load from
:return: A ready to use requests session
:rtype: OAuth2Session
"""
# TODO: remove token_path in fut... |
Refresh the OAuth authorization token. This will be called automatically when the access token expires however you can manually call this method to request a new refresh token.: return bool: Success/ Failure | def refresh_token(self):
"""
Refresh the OAuth authorization token.
This will be called automatically when the access token
expires, however, you can manually call this method to
request a new refresh token.
:return bool: Success / Failure
"""
if self.se... |
Checks if a delay is needed between requests and sleeps if True | def _check_delay(self):
""" Checks if a delay is needed between requests and sleeps if True """
if self._previous_request_at:
dif = round(time.time() - self._previous_request_at,
2) * 1000 # difference in miliseconds
if dif < self.requests_delay:
... |
Internal handling of requests. Handles Exceptions. | def _internal_request(self, request_obj, url, method, **kwargs):
""" Internal handling of requests. Handles Exceptions.
:param request_obj: a requests session.
:param str url: url to send request to
:param str method: type of request (get/put/post/patch/delete)
:param kwargs: ex... |
Makes a request to url using an without oauth authorization session but through a normal session | def naive_request(self, url, method, **kwargs):
""" Makes a request to url using an without oauth authorization
session, but through a normal session
:param str url: url to send request to
:param str method: type of request (get/put/post/patch/delete)
:param kwargs: extra params... |
Makes a request to url using an oauth session | 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 ) | 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 ) | 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 ) | 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 ) | 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 | 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 | 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 | 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. | 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 | 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 | 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 | 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. | 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... |
Push new unsaved attachments to the cloud and remove removed attachments. This method should not be called for non draft messages. | def _update_attachments_to_cloud(self):
""" Push new, unsaved attachments to the cloud and remove removed
attachments. This method should not be called for non draft messages.
"""
url = self.build_url(self._endpoints.get('attachments').format(
id=self._parent.object_id))
... |
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 | 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 | 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 | 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 | 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: When using expand on multi - value r... | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 ) | 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 | 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 | 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 | 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 | 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 | 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_attachments: whether or not to download attachments: return: ... | 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 | 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 | 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 ) | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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:
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.