'winerror' : 1 }))
except NameError: pass
+import pickle, random
+
for args in exceptionList:
expected = args[-1]
try:
( repr(e), checkArgName,
repr(expected[checkArgName]),
repr(getattr(e, checkArgName)) ))
+
+ # test for pickling support
+ new = pickle.loads(pickle.dumps(e, random.randint(0, 2)))
+ for checkArgName in expected.keys():
+ if repr(getattr(e, checkArgName)) != repr(expected[checkArgName]):
+ raise TestFailed('Checking unpickled exception arguments, '
+ 'exception '
+ '"%s", attribute "%s" expected %s got %s.' %
+ ( repr(e), checkArgName,
+ repr(expected[checkArgName]),
+ repr(getattr(e, checkArgName)) ))
{
if (self->args && self->dict)
return PyTuple_Pack(3, self->ob_type, self->args, self->dict);
- else if (self->args)
+ else
return PyTuple_Pack(2, self->ob_type, self->args);
- else {
- PyObject *res, *tup = PyTuple_New(0);
- if (!tup) return NULL;
- res = PyTuple_Pack(2, self->ob_type, tup);
- Py_DECREF(tup);
- return res;
- }
}
{
PyObject *args = self->args;
PyObject *res = NULL, *tmp;
+
/* self->args is only the first two real arguments if there was a
* file name given to EnvironmentError. */
if (PyTuple_GET_SIZE(args) == 2 && self->filename) {
Py_INCREF(self->filename);
PyTuple_SET_ITEM(args, 2, self->filename);
- } else {
+ } else
Py_INCREF(args);
- }
- res = PyTuple_Pack(3, self->ob_type, args, self->dict);
+
+ if (self->dict)
+ res = PyTuple_Pack(3, self->ob_type, args, self->dict);
+ else
+ res = PyTuple_Pack(2, self->ob_type, args);
Py_DECREF(args);
return res;
}