void *cbdata,
GError **err)
{
- PyObject *result;
+ PyObject *arglist, *result, *py_pkg;
CbData *data = cbdata;
- CR_UNUSED(pkg);
+ if (data->py_pkg)
+ py_pkg = data->py_pkg;
+ else
+ py_pkg = Object_FromPackage(pkg, 1);
- if (data->py_pkg) {
- // Decref ref count on processed package
- Py_DECREF(data->py_pkg);
- data->py_pkg = NULL;
- }
-
- result = PyObject_CallObject(data->py_pkgcb, NULL);
+ arglist = Py_BuildValue("(O)", py_pkg);
+ result = PyObject_CallObject(data->py_pkgcb, arglist);
+ Py_DECREF(arglist);
+ Py_DECREF(py_pkg);
+ data->py_pkg = NULL;
if (result == NULL) {
// Exception raised
return NULL;
}
- if (!PyCallable_Check(py_newpkgcb)) {
- PyErr_SetString(PyExc_TypeError, "newpkgcb must be callable");
+ if (!PyCallable_Check(py_newpkgcb) && py_newpkgcb != Py_None) {
+ PyErr_SetString(PyExc_TypeError, "newpkgcb must be callable or None");
return NULL;
}
return NULL;
}
+ if (py_newpkgcb == Py_None && py_pkgcb == Py_None) {
+ PyErr_SetString(PyExc_TypeError, "both pkgcb and newpkgcb cannot be None");
+ return NULL;
+ }
+
Py_XINCREF(py_newpkgcb);
Py_XINCREF(py_pkgcb);
Py_XINCREF(py_warningcb);
+ cr_XmlParserNewPkgCb ptr_c_newpkgcb = NULL;
cr_XmlParserPkgCb ptr_c_pkgcb = NULL;
cr_XmlParserWarningCb ptr_c_warningcb = NULL;
+ if (py_newpkgcb != Py_None)
+ ptr_c_newpkgcb = c_newpkgcb;
if (py_pkgcb != Py_None)
ptr_c_pkgcb = c_pkgcb;
if (py_warningcb != Py_None)
cbdata.py_pkg = NULL;
cr_xml_parse_primary(filename,
- c_newpkgcb,
+ ptr_c_newpkgcb,
&cbdata,
ptr_c_pkgcb,
&cbdata,
return NULL;
}
- if (!PyCallable_Check(py_newpkgcb)) {
- PyErr_SetString(PyExc_TypeError, "newpkgcb must be callable");
+ if (!PyCallable_Check(py_newpkgcb) && py_newpkgcb != Py_None) {
+ PyErr_SetString(PyExc_TypeError, "newpkgcb must be callable or None");
return NULL;
}
return NULL;
}
+ if (py_newpkgcb == Py_None && py_pkgcb == Py_None) {
+ PyErr_SetString(PyExc_TypeError, "both pkgcb and newpkgcb cannot be None");
+ return NULL;
+ }
+
Py_XINCREF(py_newpkgcb);
Py_XINCREF(py_pkgcb);
Py_XINCREF(py_warningcb);
+ cr_XmlParserNewPkgCb ptr_c_newpkgcb = NULL;
cr_XmlParserPkgCb ptr_c_pkgcb = NULL;
cr_XmlParserWarningCb ptr_c_warningcb = NULL;
+ if (py_newpkgcb != Py_None)
+ ptr_c_newpkgcb = c_newpkgcb;
if (py_pkgcb != Py_None)
ptr_c_pkgcb = c_pkgcb;
if (py_warningcb != Py_None)
cbdata.py_pkg = NULL;
cr_xml_parse_filelists(filename,
- c_newpkgcb,
+ ptr_c_newpkgcb,
&cbdata,
ptr_c_pkgcb,
&cbdata,
return NULL;
}
- if (!PyCallable_Check(py_newpkgcb)) {
- PyErr_SetString(PyExc_TypeError, "newpkgcb must be callable");
+ if (!PyCallable_Check(py_newpkgcb) && py_newpkgcb != Py_None) {
+ PyErr_SetString(PyExc_TypeError, "newpkgcb must be callable or None");
return NULL;
}
return NULL;
}
+ if (py_newpkgcb == Py_None && py_pkgcb == Py_None) {
+ PyErr_SetString(PyExc_TypeError, "both pkgcb and newpkgcb cannot be None");
+ return NULL;
+ }
+
Py_XINCREF(py_newpkgcb);
Py_XINCREF(py_pkgcb);
Py_XINCREF(py_warningcb);
+ cr_XmlParserNewPkgCb ptr_c_newpkgcb = NULL;
cr_XmlParserPkgCb ptr_c_pkgcb = NULL;
cr_XmlParserWarningCb ptr_c_warningcb = NULL;
+ if (py_newpkgcb != Py_None)
+ ptr_c_newpkgcb = c_newpkgcb;
if (py_pkgcb != Py_None)
ptr_c_pkgcb = c_pkgcb;
if (py_warningcb != Py_None)
cbdata.py_pkg = NULL;
cr_xml_parse_other(filename,
- c_newpkgcb,
+ ptr_c_newpkgcb,
&cbdata,
ptr_c_pkgcb,
&cbdata,
userdata["pkgs"].append(pkg)
return pkg
- def pkgcb():
+ def pkgcb(pkg):
userdata["pkgcb_calls"] += 1
def warningcb(warn_type, msg):
userdata["pkgs"].append(pkg)
return pkg
- def pkgcb():
+ def pkgcb(pkg):
userdata["pkgcb_calls"] += 1
def warningcb(warn_type, msg):
self.assertEqual(userdata["pkgcb_calls"], 2)
self.assertEqual(userdata["warnings"], [])
+ def test_xml_parser_primary_repo02_only_pkgcb(self):
+
+ pkgs = []
+
+ def pkgcb(pkg):
+ pkgs.append(pkg)
+
+ cr.xml_parse_primary(REPO_02_PRIXML, None, pkgcb, None, 1)
+
+ self.assertEqual([pkg.name for pkg in pkgs],
+ ['fake_bash', 'super_kernel'])
+
+ def test_xml_parser_primary_repo02_no_cbs(self):
+ self.assertRaises(TypeError,
+ cr.xml_parse_primary,
+ REPO_02_PRIXML, None, None, None, 1)
+
def test_xml_parser_primary_warnings(self):
userdata = {
def test_xml_parser_primary_pkgcb_abort(self):
def newpkgcb(pkgId, name, arch):
return cr.Package()
- def pkgcb():
+ def pkgcb(pkg):
raise Error("Foo error")
self.assertRaises(cr.CreaterepoCError,
cr.xml_parse_primary,
userdata["pkgs"].append(pkg)
return pkg
- def pkgcb():
+ def pkgcb(pkg):
userdata["pkgcb_calls"] += 1
def warningcb(warn_type, msg):
userdata["pkgs"].append(pkg)
return pkg
- def pkgcb():
+ def pkgcb(pkg):
userdata["pkgcb_calls"] += 1
def warningcb(warn_type, msg):
self.assertEqual(userdata["pkgcb_calls"], 2)
self.assertEqual(userdata["warnings"], [])
+ def test_xml_parser_filelists_repo02_only_pkgcb(self):
+
+ pkgs = []
+
+ def pkgcb(pkg):
+ pkgs.append(pkg)
+
+ cr.xml_parse_filelists(REPO_02_FILXML, None, pkgcb, None)
+
+ self.assertEqual([pkg.name for pkg in pkgs],
+ ['fake_bash', 'super_kernel'])
+
+ def test_xml_parser_filelists_repo02_no_cbs(self):
+ self.assertRaises(TypeError,
+ cr.xml_parse_filelists,
+ REPO_02_FILXML, None, None, None)
+
def test_xml_parser_filelists_warnings(self):
userdata = {
def test_xml_parser_filelists_pkgcb_abort(self):
def newpkgcb(pkgId, name, arch):
return cr.Package()
- def pkgcb():
+ def pkgcb(pkg):
raise Error("Foo error")
self.assertRaises(cr.CreaterepoCError,
cr.xml_parse_filelists,
userdata["pkgs"].append(pkg)
return pkg
- def pkgcb():
+ def pkgcb(pkg):
userdata["pkgcb_calls"] += 1
def warningcb(warn_type, msg):
userdata["pkgs"].append(pkg)
return pkg
- def pkgcb():
+ def pkgcb(pkg):
userdata["pkgcb_calls"] += 1
def warningcb(warn_type, msg):
self.assertEqual(userdata["pkgcb_calls"], 2)
self.assertEqual(userdata["warnings"], [])
+ def test_xml_parser_other_repo02_only_pkgcb(self):
+
+ pkgs = []
+
+ def pkgcb(pkg):
+ pkgs.append(pkg)
+
+ cr.xml_parse_other(REPO_02_OTHXML, None, pkgcb, None)
+
+ self.assertEqual([pkg.name for pkg in pkgs],
+ ['fake_bash', 'super_kernel'])
+
+ def test_xml_parser_other_repo02_no_cbs(self):
+ self.assertRaises(TypeError,
+ cr.xml_parse_other,
+ REPO_02_OTHXML, None, None, None)
+
def test_xml_parser_other_warnings(self):
userdata = {
def test_xml_parser_other_pkgcb_abort(self):
def newpkgcb(pkgId, name, arch):
return cr.Package()
- def pkgcb():
+ def pkgcb(pkg):
raise Error("Foo error")
self.assertRaises(cr.CreaterepoCError,
cr.xml_parse_other,