changeset 16:657e8df14187

use a better way of setting True/False values
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 16 Jul 2011 10:38:46 -0700
parents 1ee374416987
children d15f85eb2ab9
files uploader/dispatcher.py
diffstat 1 files changed, 14 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/uploader/dispatcher.py
+++ b/uploader/dispatcher.py
@@ -5,29 +5,38 @@ request dispatcher
 import os
 from handlers import Get, Post, SubpathGet, SubpathPost
 from webob import Request, exc
 
 class Dispatcher(object):
 
     ### class level variables
     defaults = { 'directory': None,
-                 'auth': 'False',
+                 'auth': False,
                  'query_string': None,
-                 'subpath': 'False',
+                 'subpath': False,
+                 'display_contents': False,
                  'app': None}
 
     def __init__(self, **kw):
+
+        # set defaults
         for key in self.defaults:
             setattr(self, key, kw.get(key, self.defaults[key]))
         assert os.path.exists(self.directory), "The base directory %s does not exist; uploader needs it!" % self.directory
         if self.app:
-            assert hasattr(self.app, '__call__')
-        self.auth = self.auth.lower() == 'true'
-        self.subpath = self.subpath.lower() == 'true'
+            assert hasattr(self.app, '__call__'), "app must be a callable WSGI app"
+
+        # set True/False values
+        for i in ('auth', 'subpath', 'display_contents'):
+            attr = getattr(self, i)
+            if isinstance(attr, basestring):
+                setattr(self, i, attr.lower() == 'true')
+
+        # choose handler based on subpath
         if self.subpath:
             self.handlers = [ SubpathGet, SubpathPost ]
         else:
             self.handlers = [ Get, Post ]
 
     ### methods dealing with HTTP
     def __call__(self, environ, start_response):
         request = Request(environ)