[Zope] how to use allow_module() and allow_class() ?

Doyon, Jean-Francois Jean-Francois.Doyon@CCRS.NRCan.gc.ca
Tue, 26 Mar 2002 15:49:06 -0500


Hello,

I am tryting to enable the use of a module in my Python scripts, but am
having trouble.

I have done as suggested in the PythonScripts/README.txt and created =
myself
a product with an __init__.py that has:

# Global module assertions for Python scripts
from Products.PythonScripts.Utility import allow_module, allow_class

allow_module('urllib')
allow_module('Projection')

BUT when I try to run a simple script such as:

	from Projection import Projection, DEGREES

	o =3D
Projection(['proj=3Dlcc','lat_0=3D49n','lon_0=3D95w','lat_1=3D49n','lat_=
2=3D77n','ellp
s=3DGRS80'],DEGREES)
	point =3D o.Forward(latlong[0],latlong[1])

	return point

I get an unauthorized access error! Forward is a function of the
ProjectionPtr class, which is subclassed (is that the word?) by the
Projection class.  See the code below, it's short.

Anyways all this is part of the Projection module ... so what's the =
problem?

Do I have to somehow use the allow_class() call ?

Here's the module:

# This file was created automatically by SWIG.
import Projectionc
class ProjectionPtr :
    def __init__(self,this):
        self.this =3D this
        self.thisown =3D 0
    def __del__(self,Projectionc=3DProjectionc):
        if self.thisown =3D=3D 1 :
            Projectionc.delete_Projection(self)
    def Forward(self, *_args, **_kwargs):
        val =3D apply(Projectionc.Projection_Forward,(self,) + _args, =
_kwargs)
        return val
    def Inverse(self, *_args, **_kwargs):
        val =3D apply(Projectionc.Projection_Inverse,(self,) + _args, =
_kwargs)
        return val
    def __setattr__(self,name,value):
        if name =3D=3D "units" :
            Projectionc.Projection_units_set(self,value)
            return
        if name =3D=3D "proj" :
            Projectionc.Projection_proj_set(self,value)
            return
        self.__dict__[name] =3D value
    def __getattr__(self,name):
        if name =3D=3D "units" :
            return Projectionc.Projection_units_get(self)
        if name =3D=3D "proj" :
            return Projectionc.Projection_proj_get(self)
        raise AttributeError,name
    def __repr__(self):
        return "<C Projection instance at %s>" % (self.this,)
class Projection(ProjectionPtr):
    def __init__(self,*_args,**_kwargs):
        self.this =3D apply(Projectionc.new_Projection,_args,_kwargs)
        self.thisown =3D 1

(There's more , but it's irrelevant)

Projectionc. is a .so dynamically linked library.

Thanks!

Jean-Fran=E7ois Doyon
Internet Service Development and Systems Support
GeoAccess Division
Canadian Center for Remote Sensing
Natural Resources Canada
http://atlas.gc.ca
Phone: (613) 992-4902
Fax: (613) 947-2410