[Zope] Python -> ZopePython cheat sheet?

Ausum Studio ausum_studio@hotmail.com
Mon, 4 Nov 2002 21:48:57 -0500


> Is there some way I can make dir() and type() available to scripts for
> development purposes and make sys importable once again?

As Chris said, you need an external method (due to security concerns). Just
like this:

1. Create the following script:

# helpers.py

def dir_this(ob):
    return dir(ob)

def type_this(ob):
    return type(ob)

2. Save the preceeding script 'helpers.py' in the 'Extensions' folder of
your Zope instance.

3. In the root of the Zope Management Interface (ZMI) add an External Method
with the id of the first of the two methods you need. (You may use a
different id as well):
     id: dir_this
     title: any title
     module name: helpers     (without the extension)
     function: dir_this

4. Repeat the same thing for 'type_this'

5. Now you're ready to use dir() and type() within your code:
       PythonScript:      context.dir_this(object)
                                 context.type_this(object)
       DTML:     <dtml-var "dir_this(object)">
                        <dtml-var "type_this(object)">

6. Last but not least, make sure only managers have access to these methods,
at its 'Security' tabs.



Ausum