Solved

masking cherrypy keyword parameters

Posted on 2013-06-18
2
376 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
Comment Utility
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
Comment Utility
tested the solution, works perfectly.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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.
Read about why website design really matters in today's demanding market.
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…

772 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

10 Experts available now in Live!

Get 1:1 Help Now