Returns the instance of a instantiated plugin based on the provided Server URL. If the url fails to be parsed, then None is returned. The specified url can be either a string (the URL itself) or a dictionary containing all of the components needed to istantiate the
(
url: Union[str, dict],
asset: Optional[AppriseAsset] = None,
tag: Optional[Union[str, list[str]]] = None,
suppress_exceptions: bool = True,
)
| 114 | |
| 115 | @staticmethod |
| 116 | def instantiate( |
| 117 | url: Union[str, dict], |
| 118 | asset: Optional[AppriseAsset] = None, |
| 119 | tag: Optional[Union[str, list[str]]] = None, |
| 120 | suppress_exceptions: bool = True, |
| 121 | ) -> Optional[NotifyBase]: |
| 122 | """Returns the instance of a instantiated plugin based on the provided |
| 123 | Server URL. If the url fails to be parsed, then None is returned. |
| 124 | |
| 125 | The specified url can be either a string (the URL itself) or a |
| 126 | dictionary containing all of the components needed to istantiate |
| 127 | the notification service. If identifying a dictionary, at the bare |
| 128 | minimum, one must specify the schema. |
| 129 | |
| 130 | An example of a url dictionary object might look like: |
| 131 | { |
| 132 | schema: 'mailto', |
| 133 | host: 'google.com', |
| 134 | user: 'myuser', |
| 135 | password: 'mypassword', |
| 136 | } |
| 137 | |
| 138 | Alternatively the string is much easier to specify: |
| 139 | mailto://user:mypassword@google.com |
| 140 | |
| 141 | The dictionary works well for people who are calling details() to |
| 142 | extract the components they need to build the URL manually. |
| 143 | """ |
| 144 | |
| 145 | # Initialize our result set |
| 146 | results = None |
| 147 | |
| 148 | # Prepare our Asset Object |
| 149 | asset = asset if isinstance(asset, AppriseAsset) else AppriseAsset() |
| 150 | |
| 151 | if isinstance(url, str): |
| 152 | # Acquire our url tokens |
| 153 | results = plugins.url_to_dict( |
| 154 | url, secure_logging=asset.secure_logging |
| 155 | ) |
| 156 | |
| 157 | if results is None: |
| 158 | # Failed to parse the server URL; detailed logging handled |
| 159 | # inside url_to_dict - nothing to report here. |
| 160 | return None |
| 161 | |
| 162 | elif isinstance(url, dict): |
| 163 | # We already have our result set |
| 164 | results = url |
| 165 | |
| 166 | if results.get("schema") not in N_MGR: |
| 167 | # schema is a mandatory dictionary item as it is the only way |
| 168 | # we can index into our loaded plugins |
| 169 | logger.error('Dictionary does not include a "schema" entry.') |
| 170 | logger.trace( |
| 171 | "Invalid dictionary unpacked as:{}{}".format( |
| 172 | os.linesep, |
| 173 | os.linesep.join( |