Solved

masking cherrypy keyword parameters

Posted on 2013-06-18
2
380 Views
Last Modified: 2013-06-19
Hello,
I am writing a cherrypy script, which accepts POST requests, with one of the keys in the request being "dir". The cherrypy skeleton is like this:

class Root(object)
    def index(self, dir = '/my/default/directory'):
        ...
        return ....
    index.exposed = true

The request originates from a form action javascript with an jQuery AJAX post like this:
  $.post(wsgi_url, { dir: t }...

This would seem to shadow the python built-in "dir" word. To maintain consistency with other projects, I prefer not to change form action javascript to use a different keyword. Is there a way to set up the def so that the request value for keyword 'dir' can be applied to a different variable name?

As the origin of the request is a form with the POST method, I can not use positional parameters.

Thanks,

-- Robert
0
Comment
Question by:Robert_Lawson_Brown
2 Comments
 
LVL 50

Accepted Solution

by:
Steve Bink earned 500 total points
ID: 39260057
What about a dictionary wildcard?

def index(self, **kwarg):
  if not 'dir' in kwarg.keys():
    # handle lack of argument here

Open in new window

0
 

Author Closing Comment

by:Robert_Lawson_Brown
ID: 39260223
tested the solution, works perfectly.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
When should I use a controller? 3 34
Add image to into animation on website template 1 27
tutorial for ebay api 3 35
CSS: Making responsive table look nicer 7 27
Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question