[Zope-dev] Problems with allow_class and class built-in __dict__
Manuel Markwort
mma at ratio.de
Fri Nov 5 11:07:20 EST 2004
hello,
today i ran into a problem with zope.
i've wrote some base-classes in c++, using Boost.Python (www.boost.org) to export them into a
python-module. the module (.pyd-file) works fine with my python-interpreter (v2.3.3). i can import
it, instanciate objects of my c++-classes and use their methods successfully.
my module is aimed to extend one of my zope-products. in the current level of development, the module
contains a first bunch of classes, which provide the basic functionality. so, i wanted to test my module
not only with the commandline-interpreter of python, but in zope, as well.
my setup runs zope v2.7.1 (win32, with python v2.3.3), which worked fine until today.
i've started to write a new zope-product, making my module useable in zope. in the
initializer-script i tried to allow my module and the classes in it on the usual way:
<-- start: __init__.py -->
from Products.PythonScripts.Utility import allow_module, allow_class
allow_module("Products.ABPcWeb")
allow_module("Products.ABPcWeb.ssl2du") <-- THE PYD FILE
allow_class(PySslSet) <-
allow_class(PySslEntry) | Classes in ssl2du.pyd
allow_class(PyAccessSsl) |
allow_class(PySslStatement) <-
__version__ = "0.01"
__product_name__ = "ABPcWeb"
def initialize(context):
pass
<-- end: __init__.py -->
the product is called 'ABPcWeb', and my .pyd 'ssl2du'. looks ok, i thought, but zope throws this
error on startup:
<-- start: zope-error -->
Loading ABPcWeb ...
------
2004-11-05T16:14:58 ERROR(200) Zope Could not import Products.ABPcWeb
Traceback (most recent call last):
File "C:\Program Files\Zope-2.7.1\lib\python\OFS\Application.py", line 660, in import_product
product=__import__(pname, global_dict, global_dict, silly)
File "C:\Zope-Instance\Products\ABPcWeb\__init__.py", line 8, in ?
allow_class(PySslSet)
File "C:\Program Files\Zope-2.7.1\lib\python\AccessControl\SecurityInfo.py", line 313, in allow_class
sec.apply(Class)
File "C:\Program Files\Zope-2.7.1\lib\python\AccessControl\SecurityInfo.py", line 165, in apply
dict['%s__roles__' % name] = access
TypeError: object does not support item assignment
Traceback (most recent call last):
File "C:\Program Files\Zope-2.7.1\lib\python\Zope\Startup\run.py", line 50, in ?
run()
File "C:\Program Files\Zope-2.7.1\lib\python\Zope\Startup\run.py", line 19, in run
start_zope(opts.configroot)
File "C:\Program Files\Zope-2.7.1\lib\python\Zope\Startup\__init__.py", line 51, in start_zope
starter.startZope()
File "C:\Program Files\Zope-2.7.1\lib\python\Zope\Startup\__init__.py", line 230, in startZope
Zope.startup()
File "C:\Program Files\Zope-2.7.1\lib\python\Zope\__init__.py", line 47, in startup
_startup()
File "C:\Program Files\Zope-2.7.1\lib\python\Zope\App\startup.py", line 45, in startup
OFS.Application.import_products()
File "C:\Program Files\Zope-2.7.1\lib\python\OFS\Application.py", line 637, in import_products
import_product(product_dir, product_name, raise_exc=debug_mode)
File "C:\Program Files\Zope-2.7.1\lib\python\OFS\Application.py", line 660, in import_product
product=__import__(pname, global_dict, global_dict, silly)
File "C:\Zope-Instance\Products\ABPcWeb\__init__.py", line 8, in ?
allow_class(PySslSet)
File "C:\Program Files\Zope-2.7.1\lib\python\AccessControl\SecurityInfo.py", line 313, in allow_class
sec.apply(Class)
File "C:\Program Files\Zope-2.7.1\lib\python\AccessControl\SecurityInfo.py", line 165, in apply
dict['%s__roles__' % name] = access
TypeError: object does not support item assignment
<-- end: zope-error -->
after searching the web for a possible solution of that problem, i realized that since python v2.2
the __dict__-attribute isnt a real dictionary, but a proxy-object. a direct access to __dict__ isnt
allowed anymore, so zope cant do its work.
to solve the problem, i've patched the following two files:
<Zope-Root>/lib/python/AccessControl/SecurityInfo.py
and
<Zope-Root>/lib/python/App/class_init.py
i've changed all direct-access commands invoking __dict__ to setattr()- and delattr()-methods.
for example:
--(SecurityInfo.py Line: 165)--
dict['%s__roles__' % name] = access
now is:
setattr(classobj, ('%s__roles__' % name), access)
after that changes, the allowing of my module + classes worked well.
now my question:
is there a workaround for that problem without changing the zope-source ? is that 'bug' fixed in
further versions ?
best regards,
Manuel Markwort
More information about the Zope-Dev
mailing list