text
stringlengths
81
112k
Change this folder name :param to_folder: folder_id/ContactFolder to move into :type to_folder: str or ContactFolder :return: Moved or Not :rtype: bool def move_folder(self, to_folder): """ Change this folder name :param to_folder: folder_id/ContactFolder to move into ...
Creates a new contact to be saved into it's parent folder :return: newly created contact :rtype: Contact def new_contact(self): """ Creates a new contact to be saved into it's parent folder :return: newly created contact :rtype: Contact """ contact = self.conta...
This method returns a new draft Message instance with all the contacts first email as a recipient :param RecipientType recipient_type: section to add recipient into :param query: applies a OData filter to the request :type query: Query or str :return: newly created message ...
Returns a Contact by it's email :param email: email to get contact for :return: Contact for specified email :rtype: Contact def get_contact_by_email(self, email): """ Returns a Contact by it's email :param email: email to get contact for :return: Contact for specified ...
Sets this message as flagged :param start_date: the start datetime of the followUp :param due_date: the due datetime of the followUp def set_flagged(self, *, start_date=None, due_date=None): """ Sets this message as flagged :param start_date: the start datetime of the followUp :...
Sets this message flag as completed :param completition_date: the datetime this followUp was completed def set_completed(self, *, completition_date=None): """ Sets this message flag as completed :param completition_date: the datetime this followUp was completed """ self.__status...
Sets this message as un flagged def delete_flag(self): """ Sets this message as un flagged """ self.__status = Flag.NotFlagged self.__start = None self.__due_date = None self.__completed = None self._track_changes()
Returns this data as a dict to be sent to the server def to_api_data(self): """ Returns this data as a dict to be sent to the server """ data = { self._cc('flagStatus'): self._cc(self.__status.value) } if self.__status is Flag.Flagged: data[self._cc('startDateTim...
sender is a property to force to be always a Recipient class def sender(self, value): """ sender is a property to force to be always a Recipient class """ if isinstance(value, Recipient): if value._parent is None: value._parent = self value._field = 'from' ...
Returns a dict representation of this message prepared to be send to the cloud :param restrict_keys: a set of keys to restrict the returned data to :type restrict_keys: dict or set :return: converted to cloud based keys :rtype: dict def to_api_data(self, restrict_keys=...
Sends this message :param bool save_to_sent_folder: whether or not to save it to sent folder :return: Success / Failure :rtype: bool def send(self, save_to_sent_folder=True): """ Sends this message :param bool save_to_sent_folder: whether or not to save it to ...
Creates a new message that is a reply to this message :param bool to_all: whether or not to replies to all the recipients instead to just the sender :return: new message :rtype: Message def reply(self, to_all=True): """ Creates a new message that is a reply to this message ...
Creates a new message that is a forward this message :return: new message :rtype: Message def forward(self): """ Creates a new message that is a forward this message :return: new message :rtype: Message """ if not self.object_id or self.__is_draft: ...
Marks this message as read in the cloud :return: Success / Failure :rtype: bool def mark_as_read(self): """ Marks this message as read in the cloud :return: Success / Failure :rtype: bool """ if self.object_id is None or self.__is_draft: raise Runti...
Move the message to a given folder :param folder: Folder object or Folder id or Well-known name to move this message to :type folder: str or mailbox.Folder :return: Success / Failure :rtype: bool def move(self, folder): """ Move the message to a given folder :...
Copy the message to a given folder :param folder: Folder object or Folder id or Well-known name to copy this message to :type folder: str or mailbox.Folder :returns: the copied message :rtype: Message def copy(self, folder): """ Copy the message to a given folder ...
Saves changes to a message. If the message is a new or saved draft it will call 'save_draft' otherwise this will save only properties of a message that are draft-independent such as: - is_read - category - flag :return: Success / Failure :rtype: bool ...
Save this message as a draft on the cloud :param target_folder: name of the drafts folder :return: Success / Failure :rtype: bool def save_draft(self, target_folder=OutlookWellKnowFolderNames.DRAFTS): """ Save this message as a draft on the cloud :param target_folder: name of ...
If this is a EventMessage it should return the related Event def get_event(self): """ If this is a EventMessage it should return the related Event""" if not self.is_event_message: return None # select a dummy field (eg. subject) to avoid pull unneccesary data query = self....
Builds the distribution files: wheels and source. def build(force): """ Builds the distribution files: wheels and source. """ dist_path = Path(DIST_PATH) if dist_path.exists() and list(dist_path.glob('*')): if force or click.confirm('{} is not empty - delete contents?'.format(dist_path)): ...
Uploads distribuition files to pypi or pypitest. def upload(ctx, release, rebuild): """ Uploads distribuition files to pypi or pypitest. """ dist_path = Path(DIST_PATH) if rebuild is False: if not dist_path.exists() or not list(dist_path.glob('*')): print("No distribution files found. P...
Checks the long description. def check(): """ Checks the long description. """ dist_path = Path(DIST_PATH) if not dist_path.exists() or not list(dist_path.glob('*')): print("No distribution files found. Please run 'build' command first") return subprocess.check_call(['twine', 'check', ...
Lists all releases published on pypi. def list_releases(): """ Lists all releases published on pypi. """ response = requests.get(PYPI_URL.format(package=PYPI_PACKAGE_NAME)) if response: data = response.json() releases_dict = data.get('releases', {}) if releases_dict: f...
Displays a table of the contributors and to what extent we have them to thank. def contribution_breakdown(): """ Displays a table of the contributors and to what extent we have them to thank.""" args = ['git', 'blame'] counts = {} line_format = '{0:30}\t{1:>10}\t{2:>10}%' files = subprocess.check_o...
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_secret :param list[str] scopes: a list of protocol user scopes to be converted by the protocol or raw scopes :param Protocol ...
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 :return: scopes with url prefix added :rtype: list ...
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): ...
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 str proxy_password: the proxy password def set_proxy(self, proxy_server, proxy_port, proxy_username, ...
Checks if the token file exists at the given position :return: if file exists or not :rtype: bool 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...
Initializes the oauth authorization flow, getting the authorization url that the user must approve. :param list[str] requested_scopes: list of scopes to request access for :param str redirect_uri: redirect url configured in registered app :param kwargs: allow to pass unused params in co...
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 :param bool store_token: whether or not to store the token, so u don't have to keep opening the auth link and ...
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 def get_session(self, token_path=None): """ Create a requests Session object :param Pa...
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 authorizati...
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 ...
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: extra params to send to the request api :return: Response of the reques...
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 to send to the request api :return: Response of the...
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_reques...
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...
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, da...
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=N...
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...
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...
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'): s...
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 ...
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...
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_chan...
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...
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] o...
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 di...
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 dra...
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', ...
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', ...
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 ...
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] """ ...
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 """ recip...
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_...
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 isi...
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 recipie...
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 resourc...
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 t...
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...
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 attri...
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: ...
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 de...
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']...
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_lis...
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: ...
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 quer...
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....
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 """ ...
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): ...
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): ...
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 :par...
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: ...
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...
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...
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...
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 appl...
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) ...
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 wind...
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 Ti...
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: ...
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 ...
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) ...
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 [] ...
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() retur...
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 = s...
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)) ...
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...
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)) res...
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) ...
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 = s...
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[Sit...
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) ...
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...
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...
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 ...
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 de...