Solved

masking cherrypy keyword parameters

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
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 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…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…

867 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now