This is the base class for all notification services.
| 63 | |
| 64 | |
| 65 | class NotifyBase(URLBase): |
| 66 | """This is the base class for all notification services.""" |
| 67 | |
| 68 | # An internal flag used to test the state of the plugin. If set to |
| 69 | # False, then the plugin is not used. Plugins can disable themselves |
| 70 | # due to enviroment issues (such as missing libraries, or platform |
| 71 | # dependencies that are not present). By default all plugins are |
| 72 | # enabled. |
| 73 | enabled = True |
| 74 | |
| 75 | @staticmethod |
| 76 | def runtime_deps(): |
| 77 | """Return a tuple of top-level Python package names that this plugin |
| 78 | imported as optional runtime dependencies. |
| 79 | |
| 80 | The plugin manager uses this to maintain a reference counter per |
| 81 | library. When every plugin that declared a given library is disabled, |
| 82 | its counter reaches zero and the manager evicts the library from |
| 83 | `sys.modules`, releasing the associated Python objects from memory. |
| 84 | |
| 85 | Names must be the importable top-level namespace - the same string you |
| 86 | would pass to `import` - not the pip install name: |
| 87 | |
| 88 | ('paho',) # paho-mqtt installs as 'paho' |
| 89 | ('slixmpp',) |
| 90 | ('cryptography',) |
| 91 | |
| 92 | Submodules are handled automatically; declaring the top-level name is |
| 93 | sufficient. |
| 94 | |
| 95 | Override this in any plugin that conditionally imports a heavy optional |
| 96 | library. Return an empty tuple (the default) when the plugin has no |
| 97 | optional dependencies that are worth evicting. |
| 98 | """ |
| 99 | return () |
| 100 | |
| 101 | @classmethod |
| 102 | def enable(self): |
| 103 | """Mark this plugin as enabled. |
| 104 | |
| 105 | This is the counterpart to :meth:`disable`. Calling this restores the |
| 106 | plugin to an active state so it will be used for notifications again. |
| 107 | Note that if the plugin's runtime dependencies were evicted from memory |
| 108 | by the plugin manager, re-enabling will restore the flag but the |
| 109 | plugin may not function until the process is restarted. |
| 110 | """ |
| 111 | self.enabled = True |
| 112 | |
| 113 | @classmethod |
| 114 | def disable(self): |
| 115 | """Mark this plugin as disabled. |
| 116 | |
| 117 | The plugin will not be used for notifications. The plugin manager |
| 118 | calls this when honouring `APPRISE_DENY_SERVICES` / |
| 119 | `APPRISE_ALLOW_SERVICES` and uses the result of |
| 120 | :method:`runtime_deps` to decrement its per-library reference counters, |
| 121 | potentially evicting unused libraries from `sys.modules`. |
| 122 | """ |
no outgoing calls
searching dependent graphs…