?
Solved

masking cherrypy keyword parameters

Posted on 2013-06-18
2
Medium Priority
?
392 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 51

Accepted Solution

by:
Steve Bink earned 2000 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

770 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