I creates some Script(P7ython) in Zope: import time.strftime, time.strptime # ... BDate=strftime("%d.%m.%Y",strptime(Person['Birthday'],"%Y-%m-%d")) # ... all looks ok But when script is executing, i have error message: ___ Site Error An error was encountered while publishing this resource. ImportError Sorry, a site error occurred. Traceback (innermost last): ...... File /usr/www/Zope/lib/python/Shared/DC/Scripts/Bindings.py, line 342, in _bindAndExec (Object: View) File /usr/www/Zope/lib/python/Products/PythonScripts/PythonScript.py, line 326, in _exec (Object: View) (Info: ({'script': <PythonScript instance at 89f2620>, 'context': <Folder instance at 89f2a80>, 'container': <Folder instance at 89f2a80>, 'traverse_subpath': []}, (), {}, None)) File Script (Python), line 1, in View (Object: guard) File /usr/www/Zope/lib/python/AccessControl/ZopeGuards.py, line 188, in guarded_import ImportError: import of "time.strftime" is unauthorized ___ Why it's unauthorised? I run it from manager interface - my role in Zope is Manager How can i resolve this problem? -- Vitaly Markitantov mailto: vm@cit.sh icq: 117438950 phone: 332-23-90
On Mon, Apr 15, 2002 at 04:08:02PM +0300, Vitaly Markitantov wrote:
I creates some Script(P7ython) in Zope:
import time.strftime, time.strptime # ...
BDate=strftime("%d.%m.%Y",strptime(Person['Birthday'],"%Y-%m-%d")) # ...
all looks ok
But when script is executing, i have error message:
___ Site Error
An error was encountered while publishing this resource.
ImportError Sorry, a site error occurred.
Traceback (innermost last): ...... File /usr/www/Zope/lib/python/Shared/DC/Scripts/Bindings.py, line 342, in _bindAndExec (Object: View) File /usr/www/Zope/lib/python/Products/PythonScripts/PythonScript.py, line 326, in _exec (Object: View) (Info: ({'script': <PythonScript instance at 89f2620>, 'context': <Folder instance at 89f2a80>, 'container': <Folder instance at 89f2a80>, 'traverse_subpath': []}, (), {}, None)) File Script (Python), line 1, in View (Object: guard) File /usr/www/Zope/lib/python/AccessControl/ZopeGuards.py, line 188, in guarded_import ImportError: import of "time.strftime" is unauthorized ___
Why it's unauthorised? I run it from manager interface - my role in Zope is Manager How can i resolve this problem?
In addition, i've done this via External Method import time def date2date(mDate): return time.strftime("%d.%m.%Y",time.strptime(mDate,"%Y/%m/%d")) it work's, but why this not works for Scrypt(Python)? It seems like, i cannot import python libraries in Scrypt(Python). -- Vitaly Markitantov mailto: vm@cit.sh icq: 117438950 phone: 332-23-90
import time.strftime, time.strptime
That particular module is not restricted for Python Scripts. Why? Very complicated. If you want to use modules that are forbidden for Python Scripts, let an External Method do the crude job and try to keep as much code as possible in the script. Example: ## External Method /Extensions/careful_strftime.py ## import time.strftime, time.strptime def careful_strftime(self, *args): return strftime(args) ## Zope object careful_strftime ## Id: carefule_strftime Module: careful_strftime Function: careful_strftime ## Python Script ## BDate = context.careful_strftime("%d.%m.%Y", xxx) You must obviously do the same to strptime(). It is a good idea to keep a py file in Extensions filled with little hacks like this. Alternativly, look into the XXXPythonScript product on zope.org On Monday 15 April 2002 15:08, Vitaly Markitantov wrote:
I creates some Script(P7ython) in Zope:
import time.strftime, time.strptime # ...
BDate=strftime("%d.%m.%Y",strptime(Person['Birthday'],"%Y-%m-%d")) # ...
all looks ok
But when script is executing, i have error message:
___ Site Error
An error was encountered while publishing this resource.
ImportError Sorry, a site error occurred.
Traceback (innermost last): ...... File /usr/www/Zope/lib/python/Shared/DC/Scripts/Bindings.py, line 342, in _bindAndExec (Object: View) File /usr/www/Zope/lib/python/Products/PythonScripts/PythonScript.py, line 326, in _exec (Object: View) (Info: ({'script': <PythonScript instance at 89f2620>, 'context': <Folder instance at 89f2a80>, 'container': <Folder instance at 89f2a80>, 'traverse_subpath': []}, (), {}, None)) File Script (Python), line 1, in View (Object: guard) File /usr/www/Zope/lib/python/AccessControl/ZopeGuards.py, line 188, in guarded_import ImportError: import of "time.strftime" is unauthorized ___
Why it's unauthorised? I run it from manager interface - my role in Zope is Manager How can i resolve this problem?
On Mon, 15 Apr 2002, Vitaly Markitantov wrote:
I creates some Script(P7ython) in Zope:
import time.strftime, time.strptime # ...
Why it's unauthorised? I run it from manager interface - my role in Zope is Manager How can i resolve this problem?
Scripts run a very restricted form of Python with only limited imports. If you need access to all of Python, you must write an External Method not a Script.
participants (4)
-
Dennis Allison -
Dieter Maurer -
Peter Bengtsson -
Vitaly Markitantov