[Zope] cPickle.PicklingError in Connection.py when saving reference
to a class method
Grégoire Weber
gregoire.weber@switzerland.org
Tue, 13 Feb 2001 16:35:35 +0100
Hi people,
I tried to save a method reference to the ZODB (see below at #####).
The nop method acts as default method to be called in do_something()
if an other module using the class does not register itself a method.
Zope 2.3.0 (and also 2.2.4) prints the error shown below which I do
not understand. I'am using Zope under NT4SP6us.
The same error occures in register_method().
Do I do something wrong?
Or is there a bug in Zope?
Or is this kind of thing not possible with the ZODB?
Thanks in advance, Greg
P.S.: As it seems my approach is correct (from the python view), as the
code snipped at the end of the e-mail shows. But if there is somebody
on the list who knows a better solution, please let me know!
#------------------------- code fragment -------------------------
import Globals
from Globals import Persistent, Acquisition
import AccessControl
import OFS
class Calendar(OFS.SimpleItem.SimpleItem):
""" a calendar object """
def nop(self, beg, end):
return ''
def __init__(self, parentFolder, id):
self.method = self.nop ##### <-- if I clear this line the error
##### disappears
self.id=str(id)
self.title=''
parentFolder._setObject(id, self)
return parentFolder._getOb(id) # as in OSF/Folder.py
def register_method(self, method):
self.method = method
def do_something():
...
value = self.method(start_date, end_date)
...
#------------------------- zope error message -------------------------
Zope Error
Zope has encountered an error while publishing this resource.
Error Type: cPickle.PicklingError
Error Value: Cannot pickle objects.
Troubleshooting Suggestions
The URL may be incorrect.
The parameters passed to this resource may be incorrect.
A resource that this resource relies on may be encountering
an error.
For more detailed information about the error, please refer to
the HTML source for this page.
If the error persists please contact the site maintainer. Thank
you for your patience.
Traceback (innermost last):
File D:\prog\zope\lib\python\ZPublisher\Publish.py, line 222, in
publish_module
File D:\prog\zope\lib\python\ZPublisher\Publish.py, line 187, in publish
File D:\prog\zope\lib\python\Zope\__init__.py, line 221, in
zpublisher_exception_hook
File D:\prog\zope\lib\python\ZPublisher\Publish.py, line 175, in publish
File D:\prog\zope\lib\python\Zope\__init__.py, line 235, in commit
File D:\prog\zope\lib\python\ZODB\Transaction.py, line 252, in commit
File D:\prog\zope\lib\python\ZODB\Connection.py, line 358, in commit
(Info: (('Products.HOOP.Calendar', 'Calendar'),
'\000\000\000\000\000\000\024=', ''))
cPickle.PicklingError: (see above)
#------------------------- python shell example -------------------------
>>> class gaga:
... def nop(self): pass
... def __init__(self):
... self.m = self.nop
... def get(self):
... return self.m
...
>>> g= gaga()
>>> g
<__main__.gaga instance at 7e8a80>
>>> g.get()
<method gaga.nop of gaga instance at 7e8a80>
_______________________________________________________
Grégoire Weber
Rigistr. 31
CH-8006 Zürich
Switzerland
phone: +41-(0)1-361 66 11
mobile: +41-(0)79-44 11 457
mailto:gregoire.weber@switzerland.org
Gregi's Handy-Handhabung: http://www.topics.ch/greg/ghh