[Zope] thread safety

Toby Dickenson tdickenson@geminidataloggers.com
Mon, 21 May 2001 11:58:18 +0100


On Mon, 21 May 2001 08:40:09 +0200 (MET DST), Jerome Alet
<alet@unice.fr> wrote:

>On Wed, 16 May 2001, Toby Dickenson wrote:
>
>> On Wed, 16 May 2001 16:44:37 +0200 (MET DST), Jerome Alet
>> <alet@unice.fr> wrote:
>>=20
>> >So my question is: is this code thread safe, wrt to other Zope =
threads
>> >accessing the os module methods while they are redirected to mine ? I
>> >don't want other Zope threads to access my own methods, just the =
current
>> >one.=20
>>=20
>> The cheeky solution involves using the standard library module rexec.
>> It was designed for replacing modules in a security sandbox (for
>> example, replacing the standard 'open' function with one that limits
>> access to a specific directory) but it will do exactly what you want
>> too.
>>=20
>> The python documentation for this module is a little thin, but there
>> is deeper documentation on www.python.org.
>
>I really don't understand how to do that, does someone have working
>examples ?
>
>thanks in advance !

import rexec
import os

def customised_listdir(f):
    # customise this
    return ['perl','python','c++']

def make_glob():
    r_env =3D rexec.RExec()
    module =3D r_env.add_module('os')
    for name,value in os.__dict__.items():
        setattr(module,name,value)
    module.listdir =3D customised_listdir
    r_env.s_exec('import glob')
    return r_env.r_eval('glob.glob')

glob =3D make_glob()

def test():
    print glob('/p*')

if __name__=3D=3D'__main__':
    test()


Toby Dickenson
tdickenson@geminidataloggers.com