Skip to content

Commit

Permalink
Refactor acquire_of.
Browse files Browse the repository at this point in the history
Instead of two functiond doing nearly the same, create a now one with
the Wrapper class to create as a parameter.
Since only a single argument is needed use METH_O instead of VARARGS.
Now the argument parsing inside the function can be omited, because
python does this for us.
  • Loading branch information
stephan-hof committed Feb 22, 2017
1 parent ecdb4f4 commit f7f11ac
Showing 1 changed file with 28 additions and 38 deletions.
66 changes: 28 additions & 38 deletions src/Acquisition/_Acquisition.c
Expand Up @@ -1582,52 +1582,42 @@ static PyExtensionClass XaqWrappertype = {
};

static PyObject *
acquire_of(PyObject *self, PyObject *args)
acquire_of(PyObject *self, PyObject *inst, PyExtensionClass *target)
{
PyObject *inst;

UNLESS(PyArg_ParseTuple(args, "O", &inst)) return NULL;

UNLESS(PyExtensionInstance_Check(inst))
{
PyErr_SetString(PyExc_TypeError,
"attempt to wrap extension method using an object that\n"
"is not an extension class instance.");
return NULL;
if (!PyExtensionInstance_Check(inst)) {
PyErr_SetString(PyExc_TypeError,
"attempt to wrap extension method using an object that"
" is not an extension class instance.");
return NULL;
}

return newWrapper(self, inst, (PyTypeObject *)&Wrappertype);
}
return newWrapper(self, inst, target);

}
static PyObject *
xaq_of(PyObject *self, PyObject *args)
aq__of__(PyObject *self, PyObject *inst)
{
PyObject *inst;

UNLESS(PyArg_ParseTuple(args, "O", &inst)) return NULL;

UNLESS(PyExtensionInstance_Check(inst))
{
PyErr_SetString(PyExc_TypeError,
"attempt to wrap extension method using an object that\n"
"is not an extension class instance.");
return NULL;
}
return acquire_of(self, inst, &Wrappertype);
}

return newWrapper(self, inst, (PyTypeObject *)&XaqWrappertype);
static PyObject *
xaq__of__(PyObject *self, PyObject *inst)
{
return acquire_of(self, inst, &XaqWrappertype);
}

static struct PyMethodDef Acquirer_methods[] = {
{"__of__",(PyCFunction)acquire_of, METH_VARARGS,
"__of__(context) -- return the object in a context"},
{NULL, NULL} /* sentinel */
{"__of__",(PyCFunction)aq__of__, METH_O,
"__of__(context) -- return the object in a context"},

{NULL, NULL}
};

static struct PyMethodDef Xaq_methods[] = {
{"__of__",(PyCFunction)xaq_of, METH_VARARGS,""},

{NULL, NULL} /* sentinel */
static struct PyMethodDef ExplicitAcquirer_methods[] = {
{"__of__",(PyCFunction)xaq__of__, METH_O,
"__of__(context) -- return the object in a context"},

{NULL, NULL}
};

static PyObject *
Expand Down Expand Up @@ -2087,13 +2077,13 @@ module_init(void)

PURE_MIXIN_CLASS(Acquirer,
"Base class for objects that implicitly"
" acquire attributes from containers\n"
, Acquirer_methods);
" acquire attributes from containers\n",
Acquirer_methods);

PURE_MIXIN_CLASS(ExplicitAcquirer,
"Base class for objects that explicitly"
" acquire attributes from containers\n"
, Xaq_methods);
" acquire attributes from containers\n",
ExplicitAcquirer_methods);

UNLESS(ExtensionClassImported) return NULL;

Expand Down

0 comments on commit f7f11ac

Please sign in to comment.