Solved

masking cherrypy keyword parameters

Posted on 2013-06-18
2
381 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Accurate Analytics (Not Google) 2 59
show form submit button based on jquery sum 5 44
Forms that calculate points for wordpress 10 50
Why "Mobile First"? 5 17
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

840 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