Skip to content

Instantly share code, notes, and snippets.

@amol-
Created July 23, 2013 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amol-/6061958 to your computer and use it in GitHub Desktop.
Save amol-/6061958 to your computer and use it in GitHub Desktop.
TurboMail on TurboGears 2.3
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