Newbie here. I am writing a Product called YSPanel. I installed on the root folder. I have a published method called: viewDomain, which simply displays the REQUEST dict for now. I can call it fine through: <http://10.0.10.28:8080/yspanel/viewDomain> Now I'd like the same method to be called to handle a URL like: <http://10.0.10.28:8080/yspanel/foobar/1/2/3/4> So I added this to my class: def __bobo_traverse__(self,REQUEST=None,NAME=None): if NAME == 'foobar': #gettattr_str = str(getattr(self, 'viewDomain')) #self_str = str(self) #err_str = "gettattr_str:%s \n self_str:%s"%(gettattr_str,self_str) #raise 'Ooops', err_str return getattr(self, 'viewDomain') else: # probably from unrestrictedTraverse return getattr(self, NAME) When try it I get: Zope has encountered a problem publishing your object. Cannot locate object at: http://10.0.10.28:8080/yspanel/foobar/1 Note when I uncomment my debugging lines above, I get what seems correct: gettattr_str: <bound method YSPanel.viewDomain of <YSPanel at /yspanel>> self_str: <YSPanel at yspanel> What am I missing here? What is the right way to handle variables passed via PATH_INFO? Thanks a lot. Mohamed~
Mohamed Lrhazi wrote: at first glance it seems like your python code is not indented properly ur return statement is not within the if block
Newbie here.
I am writing a Product called YSPanel. I installed on the root folder.
I have a published method called: viewDomain, which simply displays the REQUEST dict for now. I can call it fine through: <http://10.0.10.28:8080/yspanel/viewDomain>
Now I'd like the same method to be called to handle a URL like:
<http://10.0.10.28:8080/yspanel/foobar/1/2/3/4>
So I added this to my class:
def __bobo_traverse__(self,REQUEST=None,NAME=None): if NAME == 'foobar': #gettattr_str = str(getattr(self, 'viewDomain')) #self_str = str(self) #err_str = "gettattr_str:%s \n self_str:%s"%(gettattr_str,self_str) #raise 'Ooops', err_str return getattr(self, 'viewDomain') else: # probably from unrestrictedTraverse return getattr(self, NAME)
When try it I get:
Zope has encountered a problem publishing your object. Cannot locate object at: http://10.0.10.28:8080/yspanel/foobar/1
Note when I uncomment my debugging lines above, I get what seems correct:
gettattr_str: <bound method YSPanel.viewDomain of <YSPanel at /yspanel>> self_str: <YSPanel at yspanel>
What am I missing here?
What is the right way to handle variables passed via PATH_INFO?
Thanks a lot. Mohamed~
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
--On Thursday, May 27, 2004 12:13 PM -0500 sathya <sathya@zeomega.com> wrote:
at first glance it seems like your python code is not indented properly ur return statement is not within the if block
The copy/paste into my mail client screwed it up a bit. but it is correct: Here it is better indented: def __bobo_traverse__(self,REQUEST=None,NAME=None): if NAME == 'foobar': #gettattr_str = str(getattr(self, 'viewDomain')) #self_str = str(self) #err_str = "gettattr_str:%s \n self_str:%s"%(gettattr_str,self_str) #raise 'Ooops', err_str return getattr(self, 'viewDomain') else: # probably from unrestrictedTraverse return getattr(self, NAME) One more thing, this works as expected: <http://10.0.10.28:8080/yspanel/foobar> Meaning that is does call my viewDomain method which displays the REQUEST dict. But this fails: <http://10.0.10.28:8080/yspanel/foobar/1/2> Error: Zope has encountered a problem publishing your object. Cannot locate object at: http://10.0.10.28:8080/yspanel/foobar/1
Mohamed Lrhazi wrote:
One more thing, this works as expected:
<http://10.0.10.28:8080/yspanel/foobar>
Meaning that is does call my viewDomain method which displays the REQUEST dict.
But this fails:
<http://10.0.10.28:8080/yspanel/foobar/1/2>
Error:
Zope has encountered a problem publishing your object. Cannot locate object at: http://10.0.10.28:8080/yspanel/foobar/1
OK, this is saying that it can get to 'foobar' OK, but the next traversal step from foobar to '1' is failing. It cant find '1' in the context of 'foobar'. My initial thought is that maybe there is no context wrapper for viewDomain when you return it. I can't remeber if it is added automaticcally or not. You could try: return getattr(self, 'viewDomain').__of__(self) and see if that works. Having said that, taking another look at your code, I think it works as expected. The first call to __bobo_traverse__ gets 'foobar', but how does foobar get '1'? Does an object called '1' exist anywhere? -Matt -- Matt Hamilton matth@netsight.co.uk Netsight Internet Solutions, Ltd. Business Vision on the Internet http://www.netsight.co.uk +44 (0)117 9090901 Web Design | Zope/Plone Development & Consulting | Co-location | Hosting
--On Thursday, May 27, 2004 9:15 PM +0100 Matt Hamilton <matth@netsight.co.uk> wrote:
My initial thought is that maybe there is no context wrapper for viewDomain when you return it. I can't remember if it is added automaticcally or not. You could try:
return getattr(self, 'viewDomain').__of__(self)
and see if that works.
I will try that....
Having said that, taking another look at your code, I think it works as expected. The first call to __bobo_traverse__ gets 'foobar', but how does foobar get '1'? Does an object called '1' exist anywhere?
I said I was a newbie, didn't I? :) In <http://10.0.10.28:8080/yspanel/foobar/1/2/3/4> There is no object "foobar" nor "1" nor "2" .... yspanel is an instance of My product though. and I am trying to figure out how to use __bobo_traverse__ to call a method to handle the above request, where everything, from foobar and on, is parameters or commands... Thanks a lot. Mohamed~
Matt Hamilton wrote:
OK, this is saying that it can get to 'foobar' OK, but the next traversal step from foobar to '1' is failing. It cant find '1' in the context of 'foobar'.
Indeed. Writing traversal hooks is "hard". Look at my PahtHandler product as one way to handle this. I never checked how Script objects do this, but it's probably some variation on the same... cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
participants (4)
-
Chris Withers -
Matt Hamilton -
Mohamed Lrhazi -
sathya