changeset 88:a3a7ac9102dc

better choosing of types
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 17 Nov 2011 15:18:13 -0800
parents 67dd8e0aa6da
children 7f7f7313b4c4
files bitsyblog/bitsyblog.py
diffstat 1 files changed, 15 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/bitsyblog/bitsyblog.py	Thu Nov 17 15:03:19 2011 -0800
+++ b/bitsyblog/bitsyblog.py	Thu Nov 17 15:18:13 2011 -0800
@@ -50,7 +50,7 @@
                  'site_name': 'bitsyblog', # name of the site (needed?)
                  'header': None, # text to insert as first child of body'
                  'template_directories': '', # space separated template_directories
-                 'auto_reload': 'True', # reload the genshi templates
+                 'auto_reload': True, # reload the genshi templates
                  'help_file': None, # help to display
                  'feed_items': 10, # number of RSS/atom items to display
                  'post_handlers': '' # post handlers
@@ -59,8 +59,20 @@
     cooked_bodies = {}
 
     def __init__(self, kw, handler_args):
-        for key in self.defaults:
-            setattr(self, key, kw.get(key, self.defaults[key]))
+
+        # set values from defaults and kw
+        for key, value in self.defaults.items():
+            kw_value = kw.get(key, value)
+
+            # convert kw_value to the proper type
+            _type = type(value)
+            if isinstance(kw_value, basestring) and not issubclass(_type, basestring) and value is not None:
+                if _type == bool:
+                    kw_value = kw_value.lower() == 'true'
+                else:
+                    kw_value = _type(kw_value)
+            setattr(self, key, kw_value)
+
         self.n_links = int(self.n_links) # could be a string from the .ini
         self.response_functions = {'GET': self.get,
                                    'POST': self.post,
@@ -76,7 +88,6 @@
         self.feed_items = int(self.feed_items)
 
         # template renderer
-        self.auto_reload = self.auto_reload.lower()=='true'
         self.template_directories = self.template_directories.split() # no spaces in directory names, for now
 
         for directory in self.template_directories: