Raise exception when no servers are given.

This commit is contained in:
lericson 2009-11-18 20:23:16 +01:00
parent 7fea129abd
commit 43729b93a8
2 changed files with 10 additions and 1 deletions

View File

@ -58,7 +58,7 @@ static void PylibMC_ClientType_dealloc(PylibMC_Client *self) {
static int PylibMC_Client_init(PylibMC_Client *self, PyObject *args, static int PylibMC_Client_init(PylibMC_Client *self, PyObject *args,
PyObject *kwds) { PyObject *kwds) {
PyObject *srvs, *srvs_it, *c_srv; PyObject *srvs, *srvs_it, *c_srv;
unsigned char set_stype = 0, bin = 0; unsigned char set_stype = 0, bin = 0, got_server = 0;
static char *kws[] = { "servers", "binary", NULL }; static char *kws[] = { "servers", "binary", NULL };
@ -76,6 +76,7 @@ static int PylibMC_Client_init(PylibMC_Client *self, PyObject *args,
unsigned short int port; unsigned short int port;
memcached_return rc; memcached_return rc;
got_server |= 1;
port = 0; port = 0;
if (PyString_Check(c_srv)) { if (PyString_Check(c_srv)) {
memcached_server_st *list; memcached_server_st *list;
@ -137,6 +138,11 @@ it_error:
goto error; goto error;
} }
if (!got_server) {
PyErr_SetString(PylibMCExc_MemcachedError, "empty server list");
goto error;
}
Py_DECREF(srvs_it); Py_DECREF(srvs_it);
return 0; return 0;
error: error:

View File

@ -171,6 +171,9 @@ True
'world' 'world'
>>> c.delete("hello") >>> c.delete("hello")
True True
Empty server lists are bad for your health.
>>> c = _pylibmc.client([])
""" """
# Used to test pickling. # Used to test pickling.