Created
July 23, 2013 12:21
-
-
Save amol-/6061958 to your computer and use it in GitHub Desktop.
TurboMail on TurboGears 2.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import absolute_import | |
from turbomail.control import interface | |
from paste.deploy.converters import asbool | |
import re | |
from tg import config | |
class FakeConfigObj(object): | |
def __init__(self, real_config): | |
self._config = real_config | |
self._nr_regex = re.compile('^(\d+)$') | |
def get(self, option, default): | |
value = self._config.get(option, default) | |
return self._convert(option, value) | |
def _convert(self, option, value): | |
if value is not None: | |
boolean_options = ( | |
'mail.smtp.tls', | |
'mail.tls', | |
'mail.smtp.debug', | |
'mail.debug' | |
) | |
should_be_bool = (option.endswith('.on') or (option in boolean_options)) | |
if should_be_bool: | |
value = asbool(value) | |
elif hasattr(value, 'isdigit') and value.isdigit(): | |
value = int(value) | |
return value | |
def update(self, new_value_dict): | |
self._config.update(new_value_dict) | |
def register_turbomail(base_config): | |
"""Call this inside app_cfg.py to enable TurboMail""" | |
base_config.register_hook('startup', lambda: interface.start(FakeConfigObj(config))) | |
base_config.register_hook('shutdown', lambda: interface.stop()) | |
__all__ = ['register_turbomail'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment