Commit dc6b4f7a authored by Alessandro Decina's avatar Alessandro Decina

gst.Structure: raise TypeError when assigning None to a key

parent b1f499ec
......@@ -110,8 +110,10 @@ _wrap_gst_structure_set_value(PyObject *self, PyObject *args, PyObject *kwargs)
"invalid type name");
return NULL;
}
} else if (py_value == Py_None) {
PyErr_SetString(PyExc_TypeError, "value can't be None");
return NULL;
} else {
/* Let PyGTK guess a GType for the object. */
type = pyg_type_from_object((PyObject *) py_value->ob_type);
}
......
......@@ -154,6 +154,11 @@ pygst_value_init_for_pyobject (GValue * value, PyObject * obj)
{
GType t;
if (obj == Py_None) {
PyErr_SetString (PyExc_TypeError, "value can't be None");
return FALSE;
}
if (!(t = pyg_type_from_object ((PyObject *) obj->ob_type))) {
if (PyObject_IsInstance (obj, gstvalue_class)) {
PyErr_Clear ();
......
......@@ -180,6 +180,17 @@ class CapsTest(TestCase):
gst.Caps ("some/mime, _double = (double) 1.0; other/mime, _int = { 1, 2 }"),
gst.Caps ("some/mime, _double = (double) 1.0"))
def testNoneValue(self):
caps = gst.Caps("foo")
def invalid_assignment():
caps[0]["bar"] = None
self.assertRaises(TypeError, invalid_assignment)
def invalid_set_value():
caps[0].set_value("bar", None)
self.assertRaises(TypeError, invalid_set_value)
if __name__ == "__main__":
unittest.main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment