Zope is (again) carefully protecting you from yourself, which it does extremely well. Try not to kick the PC too hard, you'll dent it. ;-) The original problem was (with time.time()) that the Python 'time' module does not have any module security info declarations associated with it inside of Zope. You can make these declarations... there is documentation in the developer's guide about how to make use of "modulesecurityinfo" objects to expose arbitrary module-level functions to Python Scripts. Please see http://www.zope.org/Documentation/ZDG/Security.dtml for he gory details. In this case, you need to add a security declaration somewhere for the time module's time function within a Product file. For instance, you can create a Product directory named "time_secured" (inside lib/python/Products), put a file in there named __init__.py, and add the following contents to it (untested): import time def time(): return time.time() from AccessControl import ModuleSecurityInfo modulesecurity = ModuleSecurityInfo() modulesecurity.declarePublic('time') modulesecurity.apply(globals()) Then from within PythonScripts, you can do: import time_secured t = time_secured.time() For the (gory) explanation of why this is necessary in this particular case, read the Developer's Guide with an eye towards the fact that the "time" module is a module implemented in C. - C ----- Original Message ----- From: "Bruce Eckel" <Bruce@EckelObjects.com> To: "password horpz" <zope@zope.org> Sent: Tuesday, May 15, 2001 1:15 PM Subject: Re: [Zope] Weird (?) Python Script problem
Never mind. I just figured out the DateTime() thing. (replace time.time() below with DateTime()).
Although it seems a strange way to report an error.
*********** REPLY SEPARATOR ***********
On 5/15/01 at 10:00 AM Bruce Eckel wrote:
The following script follows all the rules, I think. It saves fine, and I usually get an exception when I save a script if there's something wrong with it. But when I try to run it, it pops up the "Please type your user name and password" dialog box, and it will not accept my "root" zope admin password.
## Script (Python) "SeminarID" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=name ##title= ## import string, time
order_id = string.join(string.split(string.strip(name)), '') # Remove spaces idstring = ''
for c in order_id: if c in string.letters: # Take only characters idstring = idstring + c order_id = idstring[0:20] # Take only the first 20 characters order_id = "%s%x" % (order_id, time.time()) # Combine with current time in hex for unique ID return order_id
Most current information can be found at: http://www.mindview.net/Etc/notes.html =================== Bruce Eckel http://www.BruceEckel.com Contains free electronic books: "Thinking in Java 2e" & "Thinking in C++ 2e" Please subscribe to my free newsletter -- just send any email to: join-eckel-oo-programming@earth.lyris.net My schedule can be found at: http://www.mindview.net/Calendar ===================
_______________________________________________ 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 )
Most current information can be found at: http://www.mindview.net/Etc/notes.html =================== Bruce Eckel http://www.BruceEckel.com Contains free electronic books: "Thinking in Java 2e" & "Thinking in C++ 2e" Please subscribe to my free newsletter -- just send any email to: join-eckel-oo-programming@earth.lyris.net My schedule can be found at: http://www.mindview.net/Calendar ===================
_______________________________________________ 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 )