[Zope-Checkins] CVS: Zope/lib/python/Acquisition -
_Acquisition.c:1.1.4.2 tests.py:1.1.4.2
Jim Fulton
cvs-admin at zope.org
Thu Nov 27 10:34:23 EST 2003
Update of /cvs-repository/Zope/lib/python/Acquisition
In directory cvs.zope.org:/tmp/cvs-serv7869/lib/python/Acquisition
Modified Files:
Tag: Zope-2_8-devel-branch
_Acquisition.c tests.py
Log Message:
Got tests to pass except test that was previously (and still) failing
on head.
=== Zope/lib/python/Acquisition/_Acquisition.c 1.1.4.1 => 1.1.4.2 ===
--- Zope/lib/python/Acquisition/_Acquisition.c:1.1.4.1 Tue Nov 25 15:17:21 2003
+++ Zope/lib/python/Acquisition/_Acquisition.c Thu Nov 27 10:33:41 2003
@@ -407,12 +407,12 @@
else return r;
}
else PyErr_Clear();
- else if (*name=='_' && name[1]=='_' && strcmp(name+2,"reduce__")==0)
- {
- PyErr_SetString(PyExc_TypeError,
- "Can't pickle objects in acquisition wrappers.");
- return NULL;
- }
+ else if (*name=='_' && name[1]=='_' &&
+ (strcmp(name+2,"reduce__")==0 ||
+ strcmp(name+2,"reduce_ex__")==0 ||
+ strcmp(name+2,"getstate__")==0
+ ))
+ return PyObject_GenericGetAttr(((PyObject*)self), oname);
/* If we are doing a containment search, then replace self with aq_inner */
if (containment)
@@ -1105,6 +1105,15 @@
return PyInt_FromLong(0);
}
+PyObject *
+Wrappers_are_not_picklable(PyObject *Wrapper, PyObject *args)
+{
+ PyErr_SetString(PyExc_TypeError,
+ "Can't pickle objects in acquisition wrappers.");
+ return NULL;
+}
+
+
static struct PyMethodDef Wrapper_methods[] = {
{"__init__", (PyCFunction)Wrapper__init__, 0,
"Initialize an Acquirer Wrapper"},
@@ -1116,6 +1125,12 @@
"Get an attribute, acquiring it if necessary"},
{"aq_inContextOf", (PyCFunction)Wrapper_inContextOf, METH_VARARGS,
"Test whether the object is currently in the context of the argument"},
+ {"__getstate__", (PyCFunction)Wrappers_are_not_picklable, METH_VARARGS,
+ "Wrappers are not picklable"},
+ {"__reduce__", (PyCFunction)Wrappers_are_not_picklable, METH_VARARGS,
+ "Wrappers are not picklable"},
+ {"__reduce_ex__", (PyCFunction)Wrappers_are_not_picklable, METH_VARARGS,
+ "Wrappers are not picklable"},
{NULL, NULL} /* sentinel */
};
@@ -1145,7 +1160,7 @@
0L,0L,
"Wrapper object for implicit acquisition", /* Documentation string */
METHOD_CHAIN(Wrapper_methods),
- EXTENSIONCLASS_BINDABLE_FLAG,
+ (void*)(EXTENSIONCLASS_BINDABLE_FLAG),
};
static PyExtensionClass XaqWrappertype = {
@@ -1174,7 +1189,7 @@
0L,0L,
"Wrapper object for explicit acquisition", /* Documentation string */
METHOD_CHAIN(Wrapper_methods),
- EXTENSIONCLASS_BINDABLE_FLAG,
+ (void*)(EXTENSIONCLASS_BINDABLE_FLAG),
};
static PyObject *
=== Zope/lib/python/Acquisition/tests.py 1.1.4.1 => 1.1.4.2 ===
--- Zope/lib/python/Acquisition/tests.py:1.1.4.1 Tue Nov 25 15:17:21 2003
+++ Zope/lib/python/Acquisition/tests.py Thu Nov 27 10:33:41 2003
@@ -1376,6 +1376,100 @@
"""
+def test_cant_pickle_acquisition_wrappers_classic():
+ """
+ >>> import pickle
+
+ >>> class X:
+ ... def __getstate__(self):
+ ... return 1
+
+ We shouldn't be able to pickle wrappers:
+
+ >>> from Acquisition import ImplicitAcquisitionWrapper
+ >>> w = ImplicitAcquisitionWrapper(X(), X())
+ >>> pickle.dumps(w)
+ Traceback (most recent call last):
+ ...
+ TypeError: Can't pickle objects in acquisition wrappers.
+
+ But that's not enough. We need to defeat persistence as well. :)
+ This is tricky. We want to generate the error in __getstate__, not
+ in the attr access, as attribute errors are too-often hidden:
+
+ >>> getstate = w.__getstate__
+ >>> getstate()
+ Traceback (most recent call last):
+ ...
+ TypeError: Can't pickle objects in acquisition wrappers.
+
+ We shouldn't be able to pickle wrappers:
+
+ >>> from Acquisition import ExplicitAcquisitionWrapper
+ >>> w = ExplicitAcquisitionWrapper(X(), X())
+ >>> pickle.dumps(w)
+ Traceback (most recent call last):
+ ...
+ TypeError: Can't pickle objects in acquisition wrappers.
+
+ But that's not enough. We need to defeat persistence as well. :)
+ This is tricky. We want to generate the error in __getstate__, not
+ in the attr access, as attribute errors are too-often hidden:
+
+ >>> getstate = w.__getstate__
+ >>> getstate()
+ Traceback (most recent call last):
+ ...
+ TypeError: Can't pickle objects in acquisition wrappers.
+ """
+
+def test_cant_pickle_acquisition_wrappers_newstyle():
+ """
+ >>> import pickle
+
+ >>> class X(object):
+ ... def __getstate__(self):
+ ... return 1
+
+ We shouldn't be able to pickle wrappers:
+
+ >>> from Acquisition import ImplicitAcquisitionWrapper
+ >>> w = ImplicitAcquisitionWrapper(X(), X())
+ >>> pickle.dumps(w)
+ Traceback (most recent call last):
+ ...
+ TypeError: Can't pickle objects in acquisition wrappers.
+
+ But that's not enough. We need to defeat persistence as well. :)
+ This is tricky. We want to generate the error in __getstate__, not
+ in the attr access, as attribute errors are too-often hidden:
+
+ >>> getstate = w.__getstate__
+ >>> getstate()
+ Traceback (most recent call last):
+ ...
+ TypeError: Can't pickle objects in acquisition wrappers.
+
+ We shouldn't be able to pickle wrappers:
+
+ >>> from Acquisition import ExplicitAcquisitionWrapper
+ >>> w = ExplicitAcquisitionWrapper(X(), X())
+ >>> pickle.dumps(w)
+ Traceback (most recent call last):
+ ...
+ TypeError: Can't pickle objects in acquisition wrappers.
+
+ But that's not enough. We need to defeat persistence as well. :)
+ This is tricky. We want to generate the error in __getstate__, not
+ in the attr access, as attribute errors are too-often hidden:
+
+ >>> getstate = w.__getstate__
+ >>> getstate()
+ Traceback (most recent call last):
+ ...
+ TypeError: Can't pickle objects in acquisition wrappers.
+ """
+
def show(x):
print showaq(x).strip()
More information about the Zope-Checkins
mailing list