python-dependency-injector/examples/miniapps/mail_service/example.py

40 lines
1.0 KiB
Python
Raw Normal View History

2017-07-10 23:32:14 +03:00
"""Mail service and user registration example."""
class AbstractMailService(object):
"""Abstract mail service."""
def send(self, email, body):
"""Send email."""
raise NotImplementedError()
class MailService(AbstractMailService):
"""Mail service."""
def __init__(self, host, port, login, password):
"""Initializer."""
self._host = host
self._port = port
self._login = login
self._password = password
def send(self, email, body):
"""Send email."""
print('Connecting server {0}:{1} with {2}:{3}'.format(
self._host, self._port, self._login, self._password))
print('Sending "{0}" to "{1}"'.format(body, email))
class MailServiceStub(AbstractMailService):
"""Mail service stub."""
def send(self, email, body):
"""Send email."""
print('Emulating sending "{0}" to "{1}"'.format(body, email))
def add_user(email, password, mailer):
"""Register user."""
mailer.send(email, 'Your password is {0}'.format(password))