434 static PyObject* pshoutobj_set_metadata(ShoutObject* self, PyObject* args) {
435 shout_metadata_t* metadata;
436 PyObject* dict;
437 PyObject* key;
438 PyObject* val;
439 const char* skey;
440 const char* sval;
441 Py_ssize_t i = 0;
442 int rc;
443
444 if (!(metadata = shout_metadata_new())) {
445 PyErr_NoMemory();
when treating unknown struct shout_metadata_t * from shout.c:445 as non-NULL
taking False path
446 return NULL;
447 }
448
449 if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &dict))
450 return NULL;
when PyArg_ParseTuple() succeeds
taking False path
451
452 while (PyDict_Next(dict, &i, &key, &val)) {
453 if (!PyString_Check(key)) {
when considering range: -0x80000000 <= value <= -1
taking True path
454 PyErr_SetString(PyExc_TypeError, "Dictionary key must be string");
when treating unknown struct PyObject * * from shout.c:453 as non-NULL
when treating unknown struct _typeobject * from shout.c:454 as non-NULL
when considering range: 1 <= value <= 0x8000000
taking False path
455 shout_metadata_free(metadata);
456 return NULL;
457 }
458 if (!PyString_Check(val)) {
459 PyErr_SetString(PyExc_TypeError, "Dictionary value must be string");
when treating unknown struct PyObject * * from shout.c:453 as non-NULL
when treating unknown struct _typeobject * from shout.c:459 as non-NULL
when considering range: 1 <= value <= 0x8000000
taking False path
460 shout_metadata_free(metadata);
461 return NULL;
462 }
463
464 skey = PyString_AsString(key);
465 sval = PyString_AsString(val);
when PyString_AsString() succeeds
466
when PyString_AsString() succeeds
467 if ((rc = shout_metadata_add(metadata, skey, sval)) != SHOUTERR_SUCCESS) {
468 if (rc == SHOUTERR_MALLOC)
when considering range: -0x80000000 <= value <= -1
taking True path
469 PyErr_NoMemory();
when considering range: -0x80000000 <= value <= -6
taking False path
470 else if (rc == SHOUTERR_INSANE)
471 PyErr_SetString(PyExc_TypeError, "Dictionary key must not be empty");
taking False path
472 shout_metadata_free(metadata);
473 return NULL;
474 }
475 }
476
477 rc = shout_set_metadata(self->conn, metadata);
478 shout_metadata_free(metadata);
479
480 if (rc != SHOUTERR_SUCCESS) {
481 PyErr_SetString(ShoutError, "Metadata not supported in this connection");
482 return NULL;
483 }
484
485 return Py_BuildValue("i", 1);
486 }
487