Use CherryPy decoding tool to decode GET/POST arguments
authorW. Trevor King <wking@drexel.edu>
Thu, 22 Jul 2010 11:52:33 +0000 (07:52 -0400)
committerW. Trevor King <wking@drexel.edu>
Thu, 22 Jul 2010 11:52:33 +0000 (07:52 -0400)
bin/cook.py
cookbook/server.py

index 4a872bee0e1e75c817bc1ceaf978f20f0afeef82..5f006b4e3bcfd763f9b5d8d409f34ef40623ce91 100755 (executable)
@@ -88,6 +88,7 @@ if __name__ == '__main__':
             cherrypy.config.update({ # http://www.cherrypy.org/wiki/ConfigAPI
                     'server.socket_host': options.address,
                     'server.socket_port': int(options.port),
+                    'tools.decode.on': True,
                     'tools.encode.on': True,
                     'tools.encode.encoding': 'utf8',
                     'tools.staticdir.root': static_dir,
@@ -101,6 +102,7 @@ if __name__ == '__main__':
                     'server.environment': 'production',
                     'server.socket_host': options.address,
                     'server.socket_port': int(options.port),
+                    'decoding_filter.on': True,
                     'encoding_filter.on': True,
                     'encodinf_filter.encoding': 'utf8',
                     'static_filter.on': True,
index fb5a61de8a45db901cb61388937198bff27998e8..b5992fcfc15dedf1b5296836d596579f6880c26e 100644 (file)
@@ -63,8 +63,6 @@ class Server (object):
         if name == None:
             recipe = random.choice(self.cookbook)
         else:
-            if isinstance(name, types.StringType):
-                name = unicode(name, 'utf-8')
             recipe = self.cookbook.index[name]
         template = self.env.get_template('recipe.html')
         return template.render(cookbook=self.cookbook, recipe=recipe)
@@ -72,8 +70,6 @@ class Server (object):
     @cherrypy.expose
     def add_tag(self, name, tag):
         """Add a tag to a single recipe."""
-        if isinstance(name, types.StringType):
-            name = unicode(name, 'utf-8')
         recipe = self.cookbook.index[name]
         if recipe.tags == None:
             recipe.tags = []
@@ -88,8 +84,6 @@ class Server (object):
     @cherrypy.expose
     def remove_tag(self, name, tag):
         """Remove a tag from a single recipe."""
-        if isinstance(name, types.StringType):
-            name = unicode(name, 'utf-8')
         recipe = self.cookbook.index[name]
         if recipe.tags == None:
             return
@@ -103,7 +97,7 @@ class Server (object):
 
     def _clean_tag(self, tag):
         """Sanitize tag."""
-        if not isinstance(tag, types.StringType):
+        if not isinstance(tag, types.StringTypes):
             if len(tag) == 2 and '' in tag:
                 # User used either dropdown or textbox
                 tag.remove('')