Package turbomail :: Package adapters :: Module tm_pylons
[hide private]
[frames] | no frames]

Source Code for Module turbomail.adapters.tm_pylons

 1  # encoding: utf-8 
 2   
 3  """Pylons (and thus TurboGears 2) helper functions.""" 
 4   
 5   
 6  import atexit 
 7  import re 
 8   
 9  from paste.deploy.converters import asbool 
10  from pylons import config 
11   
12  from turbomail.control import interface 
13   
14   
15  __all__ = ['start_extension', 'shutdown_extension'] 
16   
17   
18   
19 -class FakeConfigObj(object):
20 """TODO: Docstring incomplete.""" 21
22 - def __init__(self, real_config):
23 self._config = real_config 24 self._nr_regex = re.compile('^(\d+)$')
25
26 - def get(self, option, default):
27 value = self._config.get(option, default) 28 return self._convert(option, value)
29
30 - def _convert(self, option, value):
31 if value is not None: 32 boolean_options = ( 33 'mail.smtp.tls', 34 'mail.tls', 35 'mail.smtp.debug', 36 'mail.debug' 37 ) 38 39 should_be_bool = (option.endswith('.on') or (option in boolean_options)) 40 41 if should_be_bool: 42 value = asbool(value) 43 44 elif hasattr(value, 'isdigit') and value.isdigit(): 45 value = int(value) 46 47 return value
48
49 - def update(self, new_value_dict):
50 self._config.update(new_value_dict)
51 52
53 -def start_extension():
54 # There is no guarantee that atexit calls shutdown but Pylons does not 55 # provide other mechanisms! 56 atexit.register(shutdown_extension) 57 58 # interface.start will exit immediately if TurboMail is not enabled. 59 interface.start(FakeConfigObj(config))
60 61
62 -def shutdown_extension():
63 interface.stop()
64