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

This commit is contained in:
Alessandro Decina 2010-08-06 23:18:02 +02:00
parent b1f499ec7e
commit dc6b4f7a0a
3 changed files with 19 additions and 1 deletions

View file

@ -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);
}

View file

@ -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 ();

View file

@ -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()