Mercurial > hg > bitsyblog
comparison bitsyblog/bitsyblog.py @ 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 |
comparison
equal
deleted
inserted
replaced
| 87:67dd8e0aa6da | 88:a3a7ac9102dc |
|---|---|
| 48 'subject': '[ %(date)s ]:', # default subject | 48 'subject': '[ %(date)s ]:', # default subject |
| 49 'n_links': 5, # number of links for navigation | 49 'n_links': 5, # number of links for navigation |
| 50 'site_name': 'bitsyblog', # name of the site (needed?) | 50 'site_name': 'bitsyblog', # name of the site (needed?) |
| 51 'header': None, # text to insert as first child of body' | 51 'header': None, # text to insert as first child of body' |
| 52 'template_directories': '', # space separated template_directories | 52 'template_directories': '', # space separated template_directories |
| 53 'auto_reload': 'True', # reload the genshi templates | 53 'auto_reload': True, # reload the genshi templates |
| 54 'help_file': None, # help to display | 54 'help_file': None, # help to display |
| 55 'feed_items': 10, # number of RSS/atom items to display | 55 'feed_items': 10, # number of RSS/atom items to display |
| 56 'post_handlers': '' # post handlers | 56 'post_handlers': '' # post handlers |
| 57 } | 57 } |
| 58 | 58 |
| 59 cooked_bodies = {} | 59 cooked_bodies = {} |
| 60 | 60 |
| 61 def __init__(self, kw, handler_args): | 61 def __init__(self, kw, handler_args): |
| 62 for key in self.defaults: | 62 |
| 63 setattr(self, key, kw.get(key, self.defaults[key])) | 63 # set values from defaults and kw |
| 64 for key, value in self.defaults.items(): | |
| 65 kw_value = kw.get(key, value) | |
| 66 | |
| 67 # convert kw_value to the proper type | |
| 68 _type = type(value) | |
| 69 if isinstance(kw_value, basestring) and not issubclass(_type, basestring) and value is not None: | |
| 70 if _type == bool: | |
| 71 kw_value = kw_value.lower() == 'true' | |
| 72 else: | |
| 73 kw_value = _type(kw_value) | |
| 74 setattr(self, key, kw_value) | |
| 75 | |
| 64 self.n_links = int(self.n_links) # could be a string from the .ini | 76 self.n_links = int(self.n_links) # could be a string from the .ini |
| 65 self.response_functions = {'GET': self.get, | 77 self.response_functions = {'GET': self.get, |
| 66 'POST': self.post, | 78 'POST': self.post, |
| 67 'PUT': self.put | 79 'PUT': self.put |
| 68 } | 80 } |
| 74 self.blog = FileBlog(self.file_dir) | 86 self.blog = FileBlog(self.file_dir) |
| 75 self.cooker = self.restructuredText | 87 self.cooker = self.restructuredText |
| 76 self.feed_items = int(self.feed_items) | 88 self.feed_items = int(self.feed_items) |
| 77 | 89 |
| 78 # template renderer | 90 # template renderer |
| 79 self.auto_reload = self.auto_reload.lower()=='true' | |
| 80 self.template_directories = self.template_directories.split() # no spaces in directory names, for now | 91 self.template_directories = self.template_directories.split() # no spaces in directory names, for now |
| 81 | 92 |
| 82 for directory in self.template_directories: | 93 for directory in self.template_directories: |
| 83 assert os.path.isdir(directory), "Bitsyblog template directory %s does not exist!" % directory | 94 assert os.path.isdir(directory), "Bitsyblog template directory %s does not exist!" % directory |
| 84 | 95 |
