Skip to content

Commit d9c5a1e

Browse files
committed
Ignore keys set to Py_None. Expose RD_KAFKA_PARTITON_UA as partition default
1 parent b13d7f5 commit d9c5a1e

File tree

1 file changed

+29
-28
lines changed

1 file changed

+29
-28
lines changed

confluent_kafka/src/confluent_kafka.c

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,12 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype,
17011701
goto inner_err;
17021702
}
17031703

1704+
/* Treat key=Py_None as if it were never set */
1705+
if (vo == Py_None) {
1706+
PyDict_DelItem(confdict, ko);
1707+
Py_DECREF(ks);
1708+
continue;
1709+
}
17041710
k = cfl_PyUnistr_AsUTF8(ks, &ks8);
17051711
if (!strcmp(k, "error_cb")) {
17061712
if (!PyCallable_Check(vo)) {
@@ -1713,10 +1719,10 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype,
17131719
Py_DECREF(h->error_cb);
17141720
h->error_cb = NULL;
17151721
}
1716-
if (vo != Py_None) {
1717-
h->error_cb = vo;
1718-
Py_INCREF(h->error_cb);
1719-
}
1722+
1723+
h->error_cb = vo;
1724+
Py_INCREF(h->error_cb);
1725+
17201726
Py_XDECREF(ks8);
17211727
Py_DECREF(ks);
17221728
continue;
@@ -1731,10 +1737,10 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype,
17311737
Py_DECREF(h->throttle_cb);
17321738
h->throttle_cb = NULL;
17331739
}
1734-
if (vo != Py_None) {
1735-
h->throttle_cb = vo;
1736-
Py_INCREF(h->throttle_cb);
1737-
}
1740+
1741+
h->throttle_cb = vo;
1742+
Py_INCREF(h->throttle_cb);
1743+
17381744
Py_XDECREF(ks8);
17391745
Py_DECREF(ks);
17401746
continue;
@@ -1750,10 +1756,10 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype,
17501756
Py_DECREF(h->stats_cb);
17511757
h->stats_cb = NULL;
17521758
}
1753-
if (vo != Py_None) {
1754-
h->stats_cb = vo;
1755-
Py_INCREF(h->stats_cb);
1756-
}
1759+
1760+
h->stats_cb = vo;
1761+
Py_INCREF(h->stats_cb);
1762+
17571763
Py_XDECREF(ks8);
17581764
Py_DECREF(ks);
17591765
continue;
@@ -1763,10 +1769,9 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype,
17631769
h->logger = NULL;
17641770
}
17651771

1766-
if (vo != Py_None) {
1767-
h->logger = vo;
1768-
Py_INCREF(h->logger);
1769-
}
1772+
h->logger = vo;
1773+
Py_INCREF(h->logger);
1774+
17701775
Py_XDECREF(ks8);
17711776
Py_DECREF(ks);
17721777
continue;
@@ -1789,18 +1794,14 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype,
17891794
/*
17901795
* Pass configuration property through to librdkafka.
17911796
*/
1792-
if (vo == Py_None) {
1793-
v = NULL;
1794-
} else {
1795-
if (!(vs = cfl_PyObject_Unistr(vo))) {
1796-
PyErr_SetString(PyExc_TypeError,
1797-
"expected configuration "
1798-
"property value as type "
1799-
"unicode string");
1800-
goto inner_err;
1801-
}
1802-
v = cfl_PyUnistr_AsUTF8(vs, &vs8);
1797+
if (!(vs = cfl_PyObject_Unistr(vo))) {
1798+
PyErr_SetString(PyExc_TypeError,
1799+
"expected configuration "
1800+
"property value as type "
1801+
"unicode string");
1802+
goto inner_err;
18031803
}
1804+
v = cfl_PyUnistr_AsUTF8(vs, &vs8);
18041805

18051806
if (rd_kafka_conf_set(conf, k, v, errstr, sizeof(errstr)) !=
18061807
RD_KAFKA_CONF_OK) {
@@ -2361,7 +2362,7 @@ static PyObject *_init_cimpl (void) {
23612362
PyModule_AddIntConstant(m, "OFFSET_END", RD_KAFKA_OFFSET_END);
23622363
PyModule_AddIntConstant(m, "OFFSET_STORED", RD_KAFKA_OFFSET_STORED);
23632364
PyModule_AddIntConstant(m, "OFFSET_INVALID", RD_KAFKA_OFFSET_INVALID);
2364-
2365+
PyModule_AddIntConstant(m, "PARTITION_UA", RD_KAFKA_PARTITION_UA);
23652366
return m;
23662367
}
23672368

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy