Resolving a url from a path in a virtual host environment
Hi guys, I'm having some trouble tying to get an object from a given path. I'm using virtual hosts, so according to Dieter's great documentation[1], REQUEST.resolve_url should do it. However no matter how creative I get making up urls, I always get a "Different namespace." ValueError. Looking at the source of resolve_url[2] I can see that it tries to ensure being at the same namespace (?) seeing if REQUEST.script is at the beginning of the passed url. So the actual problem is that this attribute always returns "http://127.0.0.1:8080" in my (2.9.4-final) Zope instance, quite independently from my requested url. So: should I be using some other method instead? (if so, I guess my reference is wrong or outdated). Which one? Do I need any special configuration to make REQUEST.script returns my virtual environment? Any additional suggestion? In case the real url after apache's rewrite is relevant, PATH_INFO and PATH_TRANSLATED are showing something like: '/VirtualHostBase/http/www.mydomain.com:80/sites/mysite/VirtualHostRoot/foo/bar.py' TIA, Pablo [1] : Quoting http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html#c37ac15c11b4: "Unless your site uses /virtual hosts/ (or the virtual hosting tools for a different purpose) restrictedTraverse is almost the inverse of absolute_url. [...] The true inverse of absolute_url is the method resolve_url of the request object." [2] http://svn.zope.org/Zope/trunk/lib/python/ZPublisher/HTTPRequest.py?rev=6875...
----- Original Message ----- From: "Pablo Ziliani" <pablo@decode.com.ar> To: "Zope" <zope@zope.org> Sent: Thursday, October 19, 2006 8:54 PM Subject: [Zope] Resolving a url from a path in a virtual host environment
Hi guys,
I'm having some trouble tying to get an object from a given path. I'm using virtual hosts, so according to Dieter's great documentation[1], REQUEST.resolve_url should do it. However no matter how creative I get making up urls, I always get a "Different namespace." ValueError. Looking at the source of resolve_url[2] I can see that it tries to ensure being at the same namespace (?) seeing if REQUEST.script is at the beginning of the passed url. So the actual problem is that this attribute always returns "http://127.0.0.1:8080" in my (2.9.4-final) Zope instance, quite independently from my requested url.
So: should I be using some other method instead? (if so, I guess my reference is wrong or outdated). Which one? Do I need any special configuration to make REQUEST.script returns my virtual environment? Any additional suggestion?
In case the real url after apache's rewrite is relevant, PATH_INFO and PATH_TRANSLATED are showing something like: '/VirtualHostBase/http/www.mydomain.com:80/sites/mysite/VirtualHostRoot/foo/bar.py'
To have a quick look at the urls that are easily available within the REQUEST namespace create a dtml method in the 'end' folder that contains: <dtml-var standard_html_header> <dtml-var REQUEST> <dtml-var standard_html_footer> Then point your browser at this method (eg. http://www.mywebsite.com/folderA/folderB/tstmethod) and see what comes up. Once you have located a variable that gives you what you need, you can easily access it via something like: REQUEST['URL0'] or REQUEST['BASE3']. If the path (url) you need is not located within the REQUEST namespace then you may need to work-around the problem... one possibility is to create property field on the 'top' level folder that contains the base url you need. You can than access this property field to build the required url. hth Jonathan
Jonathan wrote:
----- Original Message ----- From: "Pablo Ziliani" <pablo@decode.com.ar>
I'm having some trouble tying to get an object from a given path. I'm using virtual hosts, so according to Dieter's great documentation[1], REQUEST.resolve_url should do it. However no matter how creative I get making up urls, I always get a "Different namespace." ValueError. Looking at the source of resolve_url[2] I can see that it tries to ensure being at the same namespace (?) seeing if REQUEST.script is at the beginning of the passed url. So the actual problem is that this attribute always returns "http://127.0.0.1:8080" in my (2.9.4-final) Zope instance, quite independently from my requested url.
So: should I be using some other method instead? (if so, I guess my reference is wrong or outdated). Which one? Do I need any special configuration to make REQUEST.script returns my virtual environment? Any additional suggestion?
In case the real url after apache's rewrite is relevant, PATH_INFO and PATH_TRANSLATED are showing something like: '/VirtualHostBase/http/www.mydomain.com:80/sites/mysite/VirtualHostRoot/foo/bar.py'
To have a quick look at the urls that are easily available within the REQUEST namespace create a dtml method in the 'end' folder that contains:
<dtml-var standard_html_header> <dtml-var REQUEST> <dtml-var standard_html_footer>
Then point your browser at this method (eg. http://www.mywebsite.com/folderA/folderB/tstmethod) and see what comes up.
Thanks Jonathan for replying, I already have something like that on my server and part of the info I gave in my previous post was actually taken from it. Unfortunately however, I don't think this debug information can leave me any closer to my goal of fetching an object from an arbitrary path.
Once you have located a variable that gives you what you need, you can easily access it via something like: REQUEST['URL0'] or REQUEST['BASE3']. If the path (url) you need is not located within the REQUEST namespace then you may need to work-around the problem... one possibility is to create property field on the 'top' level folder that contains the base url you need. You can than access this property field to build the required url. Again, thanks for your effort, however is not my script who should access any of these fields (it would actually be BASE0) but the method resolve_url of the REQUEST object which is out of my scope. BTW, I did implemented a workaround to this some time before (which I can't find now...), but my point was knowing if I was right using this resolve_url (even though this was not working) or there was something else available out of the box.
Regards, Pablo
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Pablo Ziliani wrote:
Jonathan wrote:
----- Original Message ----- From: "Pablo Ziliani" <pablo@decode.com.ar>
I'm having some trouble tying to get an object from a given path. I'm using virtual hosts, so according to Dieter's great documentation[1], REQUEST.resolve_url should do it. However no matter how creative I get making up urls, I always get a "Different namespace." ValueError. Looking at the source of resolve_url[2] I can see that it tries to ensure being at the same namespace (?) seeing if REQUEST.script is at the beginning of the passed url. So the actual problem is that this attribute always returns "http://127.0.0.1:8080" in my (2.9.4-final) Zope instance, quite independently from my requested url.
So: should I be using some other method instead? (if so, I guess my reference is wrong or outdated). Which one? Do I need any special configuration to make REQUEST.script returns my virtual environment? Any additional suggestion?
In case the real url after apache's rewrite is relevant, PATH_INFO and PATH_TRANSLATED are showing something like: '/VirtualHostBase/http/www.mydomain.com:80/sites/mysite/VirtualHostRoot/foo/bar.py'
To have a quick look at the urls that are easily available within the REQUEST namespace create a dtml method in the 'end' folder that contains:
<dtml-var standard_html_header> <dtml-var REQUEST> <dtml-var standard_html_footer>
Then point your browser at this method (eg. http://www.mywebsite.com/folderA/folderB/tstmethod) and see what comes up.
Thanks Jonathan for replying, I already have something like that on my server and part of the info I gave in my previous post was actually taken from it. Unfortunately however, I don't think this debug information can leave me any closer to my goal of fetching an object from an arbitrary path.
Once you have located a variable that gives you what you need, you can easily access it via something like: REQUEST['URL0'] or REQUEST['BASE3']. If the path (url) you need is not located within the REQUEST namespace then you may need to work-around the problem... one possibility is to create property field on the 'top' level folder that contains the base url you need. You can than access this property field to build the required url. Again, thanks for your effort, however is not my script who should access any of these fields (it would actually be BASE0) but the method resolve_url of the REQUEST object which is out of my scope. BTW, I did implemented a workaround to this some time before (which I can't find now...), but my point was knowing if I was right using this resolve_url (even though this was not working) or there was something else available out of the box.
You probably wanted to use the context object's 'restrictedTraverse' method, e.g.: target = context.restrictedTraverse('/path/to/target') I can't think of a single case in the past five years where I wanted to be using 'resolve_url' (or 'BASE0', for that matter). Tres. - -- =================================================================== Tres Seaver +1 202-558-7113 tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFOMqS+gerLs4ltQ4RAqTQAJ4iFUfN1SCGYWg6bUwg/DbcHXQNHACdG7qP eBzetlP6zy6SYlXERzrmYhk= =YzTq -----END PGP SIGNATURE-----
Pablo Ziliani wrote at 2006-10-19 21:54 -0300:
I'm having some trouble tying to get an object from a given path. I'm using virtual hosts, so according to Dieter's great documentation[1], REQUEST.resolve_url should do it.
Whatever I may have said, if you really have a (Zope) path (and not an URL), then you should use a method working with paths: "[un]restrictedTraverse". -- Dieter
participants (4)
-
Dieter Maurer -
Jonathan -
Pablo Ziliani -
Tres Seaver