From 4bddcadfb85e0190c7d8940963709921b61080be Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Tue, 26 Nov 2019 20:11:06 -0500 Subject: [PATCH] AppriseAsset refactored; added body_format default (#181) --- apprise/Apprise.py | 4 ++++ apprise/AppriseAsset.py | 33 +++++++++++++++++++++------------ test/test_api.py | 8 ++++++-- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/apprise/Apprise.py b/apprise/Apprise.py index 31bd2888..bb950466 100644 --- a/apprise/Apprise.py +++ b/apprise/Apprise.py @@ -323,6 +323,10 @@ class Apprise(object): # bad attachments return False + # Allow Asset default value + body_format = self.asset.body_format \ + if body_format is None else body_format + # Iterate over our loaded plugins for server in self.find(tag): if status is None: diff --git a/apprise/AppriseAsset.py b/apprise/AppriseAsset.py index 61bd75f3..9ad834fb 100644 --- a/apprise/AppriseAsset.py +++ b/apprise/AppriseAsset.py @@ -86,23 +86,32 @@ class AppriseAsset(object): 'apprise-{TYPE}-{XY}{EXTENSION}', )) - def __init__(self, theme='default', image_path_mask=None, - image_url_mask=None, default_extension=None): + # This value can also be set on calls to Apprise.notify(). This allows + # you to let Apprise upfront the type of data being passed in. This + # must be of type NotifyFormat. Possible values could be: + # - NotifyFormat.TEXT + # - NotifyFormat.MARKDOWN + # - NotifyFormat.HTML + # - None + # + # If no format is specified (hence None), then no special pre-formating + # actions will take place during a notificaton. This has been and always + # will be the default. + body_format = None + + def __init__(self, **kwargs): """ Asset Initialization """ - if theme: - self.theme = theme + # Assign default arguments if specified + for key, value in kwargs.items(): + if not hasattr(AppriseAsset, key): + raise AttributeError( + 'AppriseAsset init(): ' + 'An invalid key {} was specified.'.format(key)) - if image_path_mask is not None: - self.image_path_mask = image_path_mask - - if image_url_mask is not None: - self.image_url_mask = image_url_mask - - if default_extension is not None: - self.default_extension = default_extension + setattr(self, key, value) def color(self, notify_type, color_type=None): """ diff --git a/test/test_api.py b/test/test_api.py index 2e30db9d..c3c723c5 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -666,9 +666,13 @@ def test_apprise_asset(tmpdir): API: AppriseAsset() object """ - a = AppriseAsset(theme=None) + a = AppriseAsset(theme='light') # Default theme - assert a.theme == 'default' + assert a.theme == 'light' + + # Invalid kw handling + with pytest.raises(AttributeError): + AppriseAsset(invalid_kw='value') a = AppriseAsset( theme='dark',