.connect() port parameter as string or int (closes: #120).

This commit is contained in:
Federico Di Gregorio 2006-09-01 08:29:30 +00:00
parent f88b973bd1
commit ec865ae932
2 changed files with 23 additions and 5 deletions

View File

@ -1,5 +1,9 @@
2006-09-01 Federico Di Gregorio <fog@initd.org>
* psycopg/psycopgmodule.c: applied patch from jdahlin (#120)
to have .connect() accept either a string or int as the port
parameter.
* psycopg/adapter_binary.c: applied patch from jdahlin (#119)
to fix the segfault on empty binary buffers.

View File

@ -124,6 +124,7 @@ static PyObject *
psyco_connect(PyObject *self, PyObject *args, PyObject *keywds)
{
PyObject *conn, *factory = NULL;
PyObject *pyport = NULL;
int idsn=-1, iport=-1;
char *dsn=NULL, *database=NULL, *user=NULL, *password=NULL;
@ -134,12 +135,25 @@ psyco_connect(PyObject *self, PyObject *args, PyObject *keywds)
"user", "password", "sslmode",
"connection_factory", NULL};
if (!PyArg_ParseTupleAndKeywords(args, keywds, "|sssisssO", kwlist,
&dsn, &database, &host, &iport,
if (!PyArg_ParseTupleAndKeywords(args, keywds, "|sssOsssO", kwlist,
&dsn, &database, &host, &pyport,
&user, &password, &sslmode, &factory)) {
return NULL;
}
if (pyport && PyString_Check(pyport)) {
PyObject *pyint = PyInt_FromString(PyString_AsString(pyport), NULL, 10);
if (!pyint) return NULL;
iport = PyInt_AsLong(pyint);
}
else if (pyport && PyInt_Check(pyport)) {
iport = PyInt_AsLong(pyport);
}
else if (pyport != NULL) {
PyErr_SetString(PyExc_TypeError, "port must be a string or int");
return NULL;
}
if (iport > 0)
PyOS_snprintf(port, 16, "%d", iport);