[Zope] ImportError: import unauthorized
Peter Bengtsson
mail@peterbe.com
Mon, 15 Apr 2002 18:36:16 +0200
> 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?