Hi, I wanted to improve the speed of my sites translating the DTML method accessrule into a python script. But when the DTML method works, the equivalent (?) python script doesn't (always show the default Zope page). Any clue ? Thanks in advance --Gilles ========My DTML method======== <dtml-let domaine="_.string.split(_.string.lower(_.string.split(HTTP_HOST, ':')[0]), '.')[-3:]"> <dtml-if "_['domaine']==['www', 'site1', 'com']"> <dtml-call "REQUEST.path.append('site1')"> <dtml-elif "_['domaine']==['www', 'site2', 'com']"> <dtml-call "REQUEST.path.append('site2')"> </dtml-if> </dtml-let> ========End DTML method======== ========My Python script ======== machine = _.string.lower(context.REQUEST.HTTP_HOST) servermap = { 'www.site1.com': 'site1', 'www.site2.com': 'site2' } if servermap.has_key(machine): context.REQUEST.append(servermap[machine]) return
Hi. :) I recently upgraded to 2.4.0 but it doesn't work well with Blark, which I currently need very badly. Unfortunately, I cannot find the old install of 2.3.x anywhere. To my dismay, it also does not seem to be on the zope.org site! :) Please, is there anyone out there whom might know of it's existence at another URL? Pray, do drop me the link sometime today. :) Thank you, Sire Nathaniel Harari :)
On Tue, Oct 02, 2001 at 10:35:48AM -0400, Nat Harari wrote:
I recently upgraded to 2.4.0 but it doesn't work well with Blark, which I currently need very badly.
Unfortunately, I cannot find the old install of 2.3.x anywhere. To my dismay, it also does not seem to be on the zope.org site! :)
Please, is there anyone out there whom might know of it's existence at another URL? Pray, do drop me the link sometime today. :)
See http://www.zope.org/Products/Zope which is linked from the Downloads page, left blue bar. -- Martijn Pieters | Software Engineer mailto:mj@zope.com | Zope Corporation http://www.zope.com/ | Creators of Zope http://www.zope.org/ ---------------------------------------------
http://www.zope.org/Products/Zope/2.3.3 Andreas ----- Original Message ----- From: "Nat Harari" <nat@interactivehq.org> To: <zope@zope.org> Sent: Tuesday, October 02, 2001 10:35 Subject: [Zope] Zope 2.3.x? Where?
Hi. :)
I recently upgraded to 2.4.0 but it doesn't work well with Blark, which I currently need very badly.
Unfortunately, I cannot find the old install of 2.3.x anywhere. To my dismay, it also does not seem to be on the zope.org site! :)
Please, is there anyone out there whom might know of it's existence at another URL? Pray, do drop me the link sometime today. :)
Thank you,
Sire Nathaniel Harari :)
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Thanks. Got it. :) I didn't know that the hotfixes was the place to get it. :) Next question: Swishdot. Any word? What's up with it? Another question: Templates for WebDAV. Where do I get them? What's ZPT and how does it relate to it? I've been reading the lists a bit but I'm still confused. I need to customize a CMF portal real quick (nothing major...but it has to be done soon). Can I do it in Dreamweaver? Any FAQ for a newbie to understand would be most helpful, barring direct instructions. :) Thank you, Sire Nat. :)
Nat Harari wrote:
Next question: Swishdot. Any word? What's up with it?
:-S Buying a house and a load of consulting sucks a lot of time. It is on my mind, if only someone could fund the development then I could do it during work hours... Chris
Any version you want and relevant hotfixes http://www.zope.org/Products/Zope/ ----- Original Message ----- From: "Nat Harari" <nat@interactivehq.org> To: <zope@zope.org> Sent: Tuesday, October 02, 2001 4:35 PM Subject: [Zope] Zope 2.3.x? Where?
Hi. :)
I recently upgraded to 2.4.0 but it doesn't work well with Blark, which I currently need very badly.
Unfortunately, I cannot find the old install of 2.3.x anywhere. To my dismay, it also does not seem to be on the zope.org site! :)
Please, is there anyone out there whom might know of it's existence at another URL? Pray, do drop me the link sometime today. :)
Thank you,
Sire Nathaniel Harari :)
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Hi Gilles! Yes, your Python Script is _not_ equivalent. :-) Try this (untested): ------------------------------------------ from string import lower request = context.REQUEST machine = lower(request.HTTP_HOST) servermap = { 'www.site1.com': 'site1', 'www.site2.com': 'site2' } if servermap.has_key(machine): request['TraversalRequestNameStack'].append(servermap[machine]) ------------------------------------------ Explanation: (sorry if this looks insultingly simple to you)
machine = _.string.lower(context.REQUEST.HTTP_HOST) better be:
from string import lower machine = lower(context.REQUEST.HTTP_HOST) ------------------------------------------ from python scripts you don't access libraries through the current DTML namespace (check the "Bindinds" tab if you need to use the current DTML namespace), they're already there and available. You just import the library, or - as in this case - one or two functions "from" the library. If you had a line like "import string" you refer to the "lower" function as "string.lower", if you import a function directly, it's accessable direcly through its name (as in the above code). btw, with a little string-splitting (very easy) you could also check for *.site1.com (not only "www")...
context.REQUEST.append(servermap[machine])
mmmh, never tried that. I guess this won't work. My access rule shows something like: ------------------------------------------ container.REQUEST['TraversalRequestNameStack'].append(servermap[machine]) ------------------------------------------ this will append "site1" (resp. "site2"...) to the stack of object names that will be "climbed" through when an object is accessed (remember: your access rule is a special object that gets called _before_ Zope traverses any further). This results in an object call one level further down in your object hierarchy. (Yes, you could bring the request even further down by adding more object names...) if you use "context.REQUEST" a couple of times, ------------------------------------------ request = context.REQUEST ------------------------------------------ as a first line (uh, second, first you import your (string) function(s)) might be handy, as seen in the "default" Python Script that you see when you add a new Python Script. After this line you can refer to the "context.REQUEST" object with shorter code, e.g. your (currently) first line would become ------------------------------------------ machine = lower(request.HTTP_HOST) ------------------------------------------ and your last line would become ------------------------------------------ request['TraversalRequestNameStack'].append(servermap[machine]) ------------------------------------------ hope this helps, Danny On Wednesday 03 October 2001 03:11, Gilles Lenfant wrote:
Hi,
I wanted to improve the speed of my sites translating the DTML method accessrule into a python script. But when the DTML method works, the equivalent (?) python script doesn't (always show the default Zope page).
Any clue ?
Thanks in advance
--Gilles
========My DTML method======== <dtml-let domaine="_.string.split(_.string.lower(_.string.split(HTTP_HOST, ':')[0]), '.')[-3:]"> <dtml-if "_['domaine']==['www', 'site1', 'com']"> <dtml-call "REQUEST.path.append('site1')"> <dtml-elif "_['domaine']==['www', 'site2', 'com']"> <dtml-call "REQUEST.path.append('site2')"> </dtml-if> </dtml-let> ========End DTML method======== ========My Python script ======== machine = _.string.lower(context.REQUEST.HTTP_HOST) servermap = { 'www.site1.com': 'site1', 'www.site2.com': 'site2' } if servermap.has_key(machine): context.REQUEST.append(servermap[machine]) return
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Danny, I made the changes you suggested with no success. Those test scripts gave me the same results after binding the namespace to "_", I got: == script 1 == from string import lower return lower('SPAM') ========= == script 2 == return _.string.lower('SPAM') ========= In addition, it seems that "importing" in an accessrule slows down the server. Cheers, --Gilles
Hi Gilles, if your current script looks exactly like this: ---------------------------------------------------------------- from string import lower request = container.REQUEST machine = lower(request.HTTP_HOST) servermap = { 'www.site1.com': 'site1', 'www.site2.com': 'site2' } if servermap.has_key(machine): request['TraversalRequestNameStack'].append(servermap[machine]) ---------------------------------------------------------------- and fails, then something odd is going on. I don't see any mistake. Hold on... If you're running Zope on a port other than 80, machine = lower(split(request.HTTP_HOST, ':')[0]) should do the trick (to get rid of the :port) I recognized you had used that in your DTML. Did you "re"-set the access rule? btw, I haven't measured the impact of an "import", but have you tried _not_ to bind the namespace at all (unnecessary in this case)? Is it still slower? hth, Danny On Wednesday 03 October 2001 09:43, Gilles Lenfant wrote:
Danny,
I made the changes you suggested with no success.
Those test scripts gave me the same results after binding the namespace to "_", I got:
== script 1 == from string import lower return lower('SPAM') =========
== script 2 == return _.string.lower('SPAM') =========
In addition, it seems that "importing" in an accessrule slows down the server.
Cheers,
--Gilles
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Many thanks Danny, My Zope server is behind an Apache server that makes rewrite to www.site1.com:8080 This was my (stupid) mistake. Should have been obvious ! It works now with : machine = _.string.lower(_.string.split(context.REQUEST.HTTP_HOST, ':')[0]) # and so on... The complete accessrule script is : =============== machine = _.string.lower(_.string.split(context.REQUEST.HTTP_HOST, ':')[0]) servermap = { 'www.site1.com': 'folder_site1', 'www.site2.com': 'folder_site2' } if servermap.has_key(machine): context.REQUEST['TraversalRequestNameStack'].append(servermap[machine]) return ============== With the namespace bound to '_' Cheers --Gilles ----- Original Message ----- From: "Danny William Adair" <danny@adair.net> To: "Gilles Lenfant" <glenfant@bigfoot.com>; <zope@zope.org> Sent: Wednesday, October 03, 2001 12:07 AM Subject: Re: [Zope] An accessrule in python script
Hi Gilles,
if your current script looks exactly like this: ---------------------------------------------------------------- from string import lower request = container.REQUEST machine = lower(request.HTTP_HOST) servermap = { 'www.site1.com': 'site1', 'www.site2.com': 'site2' } if servermap.has_key(machine): request['TraversalRequestNameStack'].append(servermap[machine]) ----------------------------------------------------------------
and fails, then something odd is going on. I don't see any mistake.
Hold on...
If you're running Zope on a port other than 80, machine = lower(split(request.HTTP_HOST, ':')[0]) should do the trick (to get rid of the :port) I recognized you had used that in your DTML.
Did you "re"-set the access rule?
participants (6)
-
Andreas Jung -
Chris Withers -
Danny William Adair -
Gilles Lenfant -
Martijn Pieters -
Nat Harari