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	Tue Jul 12 09:18:29 2011 -0700
+++ b/uploader/dispatcher.py	Sat Jul 16 10:38:46 2011 -0700
@@ -10,19 +10,28 @@
 
     ### 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: