Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Multiple level arguments, how would I do it.
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Beau  
View profile  
 More options Mar 25 2012, 11:51 pm
From: Beau <beautr...@gmail.com>
Date: Sun, 25 Mar 2012 20:51:20 -0700 (PDT)
Local: Sun, Mar 25 2012 11:51 pm
Subject: Multiple level arguments, how would I do it.
Hello,

I've been playing around with web.py and mimerender to create a little
webservice that will query other devices and respond via html/json/
xml.

What I want to do is have the url in the format of.

/identifier/function/arg1

or

/function/identifier/arg1

i've noticed get can return the url(?) via name. So this works great
for single arguments, but how would I extend this to multiple ones?.
Splitting on / seems like it would be a bad idea, and there is
probably a better way I'm overlooking.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Cameron Wengert  
View profile  
 More options Mar 26 2012, 2:24 pm
From: Cameron Wengert <phanto...@gmail.com>
Date: Mon, 26 Mar 2012 12:24:18 -0600
Local: Mon, Mar 26 2012 2:24 pm
Subject: Re: [webpy] Multiple level arguments, how would I do it.

You should just be able to handle this with a regex in the url definitions.

urls = ('/(.*?)/(.*?)/(.*?)', 'handler')

class handler:

    def GET(self, identifier, function, arg):

I wouldn't be surprised if there is a better way to do this though...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Beau  
View profile  
 More options Apr 3 2012, 8:49 pm
From: Beau <beautr...@gmail.com>
Date: Tue, 3 Apr 2012 17:49:40 -0700 (PDT)
Local: Tues, Apr 3 2012 8:49 pm
Subject: Re: Multiple level arguments, how would I do it.
That is exactly the solution :). Thanks.

On Mar 27, 2:24 am, Cameron Wengert <phanto...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
罗晟  
View profile  
 More options Apr 9 2012, 12:02 am
From: 罗晟 <sheng.peisi....@gmail.com>
Date: Sun, 8 Apr 2012 21:02:34 -0700 (PDT)
Local: Mon, Apr 9 2012 12:02 am
Subject: Re: [webpy] Multiple level arguments, how would I do it.

Inspired me! Thanks.

But what about when the second and third parameters are not necessary?
Which means following urls need to be matched:
* /function
* /function/identifier
* /function/identifier/arg1

This puzzled me for quite a long time...

在 2012年3月27日星期二UTC+8上午2时24分18秒,PhantomXC写道:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
NSC  
View profile  
 More options Apr 9 2012, 11:51 am
From: NSC <Shannon.Cr...@cloudsidekick.com>
Date: Mon, 9 Apr 2012 08:51:20 -0700 (PDT)
Local: Mon, Apr 9 2012 11:51 am
Subject: Re: Multiple level arguments, how would I do it.
I'm doing something similar, as I convert an asp.net application.

my url mapping:
    urls = (
        '/', 'index',
        '/uiMethods/(.*)', 'uiMethods'
    )

This way, anything that hits /uiMethods/foo is a web method call, and
I can still do normal mappings for static pages, templates, etc.

I then use the following handler for GET and POST, which in turn call
the function by *name*

class uiMethods:
    def GET(self, method):
        try:
            methodToCall = getattr(self, method)
            result = methodToCall()
            return result
        except Exception as ex:
            raise ex

    def POST(self, method):
        try:
            methodToCall = getattr(self, method)
            result = methodToCall()
            return result
        except Exception as ex:
            raise ex

    def hello(self):
        print "hello"

So, localhost:8080/uiMethods/hello will now map to your function, and
you can add new functions all day long without messing around with
more url mappings.

On Mar 25, 11:51 pm, Beau <beautr...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Cameron Wengert  
View profile  
 More options Apr 9 2012, 11:36 pm
From: Cameron Wengert <phanto...@gmail.com>
Date: Mon, 9 Apr 2012 21:36:45 -0600
Local: Mon, Apr 9 2012 11:36 pm
Subject: Re: [webpy] Multiple level arguments, how would I do it.

You could handle most of that with a regex as well. (I'm 99.7% positive
this is wrong as I suck with regex)

  urls = '/(.*?)(?:/(.*?))(?:/(.*?))?', 'handler',

  def GET(self, function, identifier=None, arg=None):


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »