diff options
Diffstat (limited to 'src/mailman/plugins/testing/example')
| -rw-r--r-- | src/mailman/plugins/testing/example/__init__.py | 0 | ||||
| -rw-r--r-- | src/mailman/plugins/testing/example/hooks.py | 21 | ||||
| -rw-r--r-- | src/mailman/plugins/testing/example/rest.py | 79 | ||||
| -rw-r--r-- | src/mailman/plugins/testing/example/rules/__init__.py | 0 | ||||
| -rw-r--r-- | src/mailman/plugins/testing/example/rules/rules.py | 14 |
5 files changed, 114 insertions, 0 deletions
diff --git a/src/mailman/plugins/testing/example/__init__.py b/src/mailman/plugins/testing/example/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/src/mailman/plugins/testing/example/__init__.py diff --git a/src/mailman/plugins/testing/example/hooks.py b/src/mailman/plugins/testing/example/hooks.py new file mode 100644 index 000000000..55c09c4a5 --- /dev/null +++ b/src/mailman/plugins/testing/example/hooks.py @@ -0,0 +1,21 @@ +import os + +from mailman.interfaces.plugin import IPlugin +from public import public +from zope.interface import implementer + + +@public +@implementer(IPlugin) +class ExamplePlugin: + def pre_hook(self): + if os.environ.get('DEBUG_HOOKS'): + print("I'm in my pre-hook") + + def post_hook(self): + if os.environ.get('DEBUG_HOOKS'): + print("I'm in my post-hook") + + @property + def resource(self): + return None diff --git a/src/mailman/plugins/testing/example/rest.py b/src/mailman/plugins/testing/example/rest.py new file mode 100644 index 000000000..1d83ce2cd --- /dev/null +++ b/src/mailman/plugins/testing/example/rest.py @@ -0,0 +1,79 @@ +from mailman.config import config +from mailman.interfaces.plugin import IPlugin +from mailman.rest.helpers import bad_request, child, etag, no_content, okay +from mailman.rest.validator import Validator +from public import public +from zope.interface import implementer + + +@public +class Yes: + def on_get(self, request, response): + okay(response, etag(dict(yes=True))) + + +@public +class No: + def on_get(self, request, response): + bad_request(response, etag(dict(no=False))) + + +@public +class NumberEcho: + def __init__(self): + self._plugin = config.plugins['example'] + + def on_get(self, request, response): + okay(response, etag(dict(number=self._plugin.number))) + + def on_post(self, request, response): + try: + resource = Validator(number=int)(request) + self._plugin.number = resource['number'] + except ValueError as error: + bad_request(response, str(error)) + else: + no_content(response) + + def on_delete(self, request, response): + self._plugin.number = 0 + no_content(response) + + +@public +class RESTExample: + def on_get(self, request, response): + resource = { + 'my-name': 'example-plugin', + 'my-child-resources': 'yes, no, echo', + } + okay(response, etag(resource)) + + @child() + def yes(self, context, segments): + return Yes(), [] + + @child() + def no(self, context, segments): + return No(), [] + + @child() + def echo(self, context, segments): + return NumberEcho(), [] + + +@public +@implementer(IPlugin) +class ExamplePlugin: + def __init__(self): + self.number = 0 + + def pre_hook(self): + pass + + def post_hook(self): + pass + + @property + def resource(self): + return RESTExample() diff --git a/src/mailman/plugins/testing/example/rules/__init__.py b/src/mailman/plugins/testing/example/rules/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/src/mailman/plugins/testing/example/rules/__init__.py diff --git a/src/mailman/plugins/testing/example/rules/rules.py b/src/mailman/plugins/testing/example/rules/rules.py new file mode 100644 index 000000000..7e9ba6ce7 --- /dev/null +++ b/src/mailman/plugins/testing/example/rules/rules.py @@ -0,0 +1,14 @@ +from mailman.interfaces.rules import IRule +from public import public +from zope.interface import implementer + + +@public +@implementer(IRule) +class ExampleRule: + name = 'example-rule' + description = 'An example rule.' + record = True + + def check(self, mlist, msg, msgdata): + return 'example' in msgdata |
