-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathnoop_pluggable.py
49 lines (36 loc) · 1.73 KB
/
noop_pluggable.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
A dummy custom router and authenticator for testing and demonstration purposes.
"""
from logging import Logger
from types import SimpleNamespace
from typing import Any, AsyncGenerator
from aiosmtpd.smtp import AuthResult
from mailrise.router import AppriseNotification, EmailMessage, Router
# The typing and inheritance information is not strictly necessary, but it comes
# in handy when developing your code.
class FullyTypedNoopRouter(Router): # pylint: disable=too-few-public-methods
"""A dummy custom router with full typing information."""
async def email_to_apprise(
self, logger: Logger, email: EmailMessage, auth_data: Any, **kwargs) \
-> AsyncGenerator[AppriseNotification, None]:
yield AppriseNotification(
config='urls: ["json://localhost"]',
title='Hello, World!',
body='Lorem ipsum dolor sit amet')
class EasyNoopRouter: # pylint: disable=too-few-public-methods
"""A dummy custom router with the minimum required code."""
async def email_to_apprise(self, _logger, _email, _auth_data, **_kwargs):
"""Our replacement for email_to_apprise()."""
# An ordinary dictionary will not work; we need dot notation access.
yield SimpleNamespace(
config='urls: ["json://localhost"]',
title='Hello, World!',
body='Lorem ipsum dolor sit amet')
# Technically, an authenticator has to satisfy the
# aiosmtpd.smtp.AuthenticatorType type, but there's no way in Python to
# communicate that to mypy.
def noop_authenticator(_server, _session, _envelope, _mechanism, _auth_data):
"""A dummy custom authenticator."""
return AuthResult(success=False)
router = FullyTypedNoopRouter()
authenticator = noop_authenticator