From: W. Trevor King Date: Thu, 22 Jul 2010 11:52:33 +0000 (-0400) Subject: Use CherryPy decoding tool to decode GET/POST arguments X-Git-Tag: v0.1~12 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f4c2fcd7817fe581ed457eee27a9990bc4eeb46c;p=cookbook.git Use CherryPy decoding tool to decode GET/POST arguments --- diff --git a/bin/cook.py b/bin/cook.py index 4a872be..5f006b4 100755 --- a/bin/cook.py +++ b/bin/cook.py @@ -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, diff --git a/cookbook/server.py b/cookbook/server.py index fb5a61d..b5992fc 100644 --- a/cookbook/server.py +++ b/cookbook/server.py @@ -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('')